authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-20 04:03:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-20 04:03:36-04:00
logd9dd50d74c282aefcb89ca922523916b88a6236f
tree56a6f6658059327ad975afbf20f6ace272a98805
parent8e19bdfc797cb419bddb4334e7d81abd382c11d9

fix not propagating parseh aliases through pub use decls


7 files changed, 41 insertions(+), 4 deletions(-)

src/analyze.cpp+12-2
...@@ -2922,13 +2922,17 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *...@@ -2922,13 +2922,17 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
2922 continue;2922 continue;
2923 }2923 }
29242924
2925 auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld->name, target_tld);2925 // Note: target_tld->name is not necessarily equal to entry->key because
2926 // of aliases that parseh uses.
2927 Buf *target_tld_name = entry->key;
2928
2929 auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld_name, target_tld);
2926 if (existing_entry) {2930 if (existing_entry) {
2927 Tld *existing_decl = existing_entry->value;2931 Tld *existing_decl = existing_entry->value;
2928 if (existing_decl != target_tld) {2932 if (existing_decl != target_tld) {
2929 ErrorMsg *msg = add_node_error(g, dst_use_node,2933 ErrorMsg *msg = add_node_error(g, dst_use_node,
2930 buf_sprintf("import of '%s' overrides existing definition",2934 buf_sprintf("import of '%s' overrides existing definition",
2931 buf_ptr(target_tld->name)));2935 buf_ptr(target_tld_name)));
2932 add_error_note(g, msg, existing_decl->source_node, buf_sprintf("previous definition here"));2936 add_error_note(g, msg, existing_decl->source_node, buf_sprintf("previous definition here"));
2933 add_error_note(g, msg, target_tld->source_node, buf_sprintf("imported definition here"));2937 add_error_note(g, msg, target_tld->source_node, buf_sprintf("imported definition here"));
2934 }2938 }
...@@ -2956,6 +2960,12 @@ void resolve_use_decl(CodeGen *g, AstNode *node) {...@@ -2956,6 +2960,12 @@ void resolve_use_decl(CodeGen *g, AstNode *node) {
2956void preview_use_decl(CodeGen *g, AstNode *node) {2960void preview_use_decl(CodeGen *g, AstNode *node) {
2957 assert(node->type == NodeTypeUse);2961 assert(node->type == NodeTypeUse);
29582962
2963 if (node->data.use.resolution == TldResolutionOk ||
2964 node->data.use.resolution == TldResolutionInvalid)
2965 {
2966 return;
2967 }
2968
2959 node->data.use.resolution = TldResolutionResolving;2969 node->data.use.resolution = TldResolutionResolving;
2960 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,2970 IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
2961 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);2971 node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
std/build.zig+2-2
...@@ -979,7 +979,7 @@ pub const LibExeObjStep = struct {...@@ -979,7 +979,7 @@ pub const LibExeObjStep = struct {
979979
980 for (builder.include_paths.toSliceConst()) |include_path| {980 for (builder.include_paths.toSliceConst()) |include_path| {
981 %%zig_args.append("-isystem");981 %%zig_args.append("-isystem");
982 %%zig_args.append(include_path);982 %%zig_args.append(builder.pathFromRoot(include_path));
983 }983 }
984984
985 for (builder.rpaths.toSliceConst()) |rpath| {985 for (builder.rpaths.toSliceConst()) |rpath| {
...@@ -1086,7 +1086,7 @@ pub const TestStep = struct {...@@ -1086,7 +1086,7 @@ pub const TestStep = struct {
10861086
1087 for (builder.include_paths.toSliceConst()) |include_path| {1087 for (builder.include_paths.toSliceConst()) |include_path| {
1088 %%zig_args.append("-isystem");1088 %%zig_args.append("-isystem");
1089 %%zig_args.append(include_path);1089 %%zig_args.append(builder.pathFromRoot(include_path));
1090 }1090 }
10911091
1092 for (builder.rpaths.toSliceConst()) |rpath| {1092 for (builder.rpaths.toSliceConst()) |rpath| {
test/build_examples.zig+1
...@@ -9,4 +9,5 @@ pub fn addCases(cases: &tests.BuildExamplesContext) {...@@ -9,4 +9,5 @@ pub fn addCases(cases: &tests.BuildExamplesContext) {
9 cases.addBuildFile("example/mix_o_files/build.zig");9 cases.addBuildFile("example/mix_o_files/build.zig");
10 cases.addBuildFile("test/standalone/issue_339/build.zig");10 cases.addBuildFile("test/standalone/issue_339/build.zig");
11 cases.addBuildFile("test/standalone/pkg_import/build.zig");11 cases.addBuildFile("test/standalone/pkg_import/build.zig");
12 cases.addBuildFile("test/standalone/use_alias/build.zig");
12}13}
test/standalone/use_alias/build.zig created+11
...@@ -0,0 +1,11 @@
1const Builder = @import("std").build.Builder;
2
3pub fn build(b: &Builder) {
4 b.addCIncludePath(".");
5
6 const main = b.addTest("main.zig");
7 main.setBuildMode(b.standardReleaseOptions());
8
9 const test_step = b.step("test", "Test it");
10 test_step.dependOn(&main.step);
11}
test/standalone/use_alias/c.zig created+1
...@@ -0,0 +1 @@
1pub use @cImport(@cInclude("foo.h"));
test/standalone/use_alias/foo.h created+4
...@@ -0,0 +1,4 @@
1struct Foo {
2 int a;
3 int b;
4};
test/standalone/use_alias/main.zig created+10
...@@ -0,0 +1,10 @@
1const c = @import("c.zig");
2const assert = @import("std").debug.assert;
3
4test "symbol exists" {
5 var foo = c.Foo {
6 .a = 1,
7 .b = 1,
8 };
9 assert(foo.a + foo.b == 2);
10}