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
1870518705
1870618706 if (errors.length > 0) {
1870718707 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 }
1870818712 for (size_t i = 0; i < errors.length; i += 1) {
1870918713 ErrorMsg *err_msg = errors.at(i);
1871018714 err_msg_add_note(parent_err_msg, err_msg);
test/compile_errors.zig+11
......@@ -1,6 +1,17 @@
11const tests = @import("tests.zig");
22
33pub 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
415 cases.addTest(
516 "comptime vector overflow shows the index",
617 \\comptime {