authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-25 19:31:30-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-25 19:31:30-05:00
log3ca861c7dd048a8bc15b6776a3b56fdc790750f7
tree2db2fe9f4803b242b582f80959a6cc2928fd29e0
parent0f54728cf0e282ca6578bb8a55df3409541c1a7f
signaturelock-open Commit is signed but in an unrecognized format.

add a compile error note when C import fails and not linking libc

closes #558

2 files changed, 15 insertions(+), 0 deletions(-)

src/ir.cpp+4
...@@ -18705,6 +18705,10 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -18705,6 +18705,10 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
1870518705
18706 if (errors.length > 0) {18706 if (errors.length > 0) {
18707 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));18707 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
18708 if (ira->codegen->libc_link_lib == nullptr) {
18709 add_error_note(ira->codegen, parent_err_msg, node,
18710 buf_sprintf("libc headers not available; compilation does not link against libc"));
18711 }
18708 for (size_t i = 0; i < errors.length; i += 1) {18712 for (size_t i = 0; i < errors.length; i += 1) {
18709 ErrorMsg *err_msg = errors.at(i);18713 ErrorMsg *err_msg = errors.at(i);
18710 err_msg_add_note(parent_err_msg, err_msg);18714 err_msg_add_note(parent_err_msg, err_msg);
test/compile_errors.zig+11
...@@ -1,6 +1,17 @@...@@ -1,6 +1,17 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.addTest(
5 "libc headers note",
6 \\const c = @cImport(@cInclude("stdio.h"));
7 \\export fn entry() void {
8 \\ c.printf("hello, world!\n");
9 \\}
10 ,
11 ".tmp_source.zig:1:11: error: C import failed",
12 ".tmp_source.zig:1:11: note: libc headers not available; compilation does not link against libc",
13 );
14
4 cases.addTest(15 cases.addTest(
5 "comptime vector overflow shows the index",16 "comptime vector overflow shows the index",
6 \\comptime {17 \\comptime {