aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-25 19:31:30 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-25 19:31:30 -0500
commit3ca861c7dd048a8bc15b6776a3b56fdc790750f7 (patch)
tree2db2fe9f4803b242b582f80959a6cc2928fd29e0
parent0f54728cf0e282ca6578bb8a55df3409541c1a7f (diff)
downloadzig-3ca861c7dd048a8bc15b6776a3b56fdc790750f7.tar.gz
zig-3ca861c7dd048a8bc15b6776a3b56fdc790750f7.zip
add a compile error note when C import fails and not linking libc
closes #558
-rw-r--r--src/ir.cpp4
-rw-r--r--test/compile_errors.zig11
2 files changed, 15 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 929f195586..d6e40384f8 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -18705,6 +18705,10 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
if (errors.length > 0) {
ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
+ if (ira->codegen->libc_link_lib == nullptr) {
+ add_error_note(ira->codegen, parent_err_msg, node,
+ buf_sprintf("libc headers not available; compilation does not link against libc"));
+ }
for (size_t i = 0; i < errors.length; i += 1) {
ErrorMsg *err_msg = errors.at(i);
err_msg_add_note(parent_err_msg, err_msg);
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 48eb7cd85d..37b39706b5 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -2,6 +2,17 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addTest(
+ "libc headers note",
+ \\const c = @cImport(@cInclude("stdio.h"));
+ \\export fn entry() void {
+ \\ c.printf("hello, world!\n");
+ \\}
+ ,
+ ".tmp_source.zig:1:11: error: C import failed",
+ ".tmp_source.zig:1:11: note: libc headers not available; compilation does not link against libc",
+ );
+
+ cases.addTest(
"comptime vector overflow shows the index",
\\comptime {
\\ var a: @Vector(4, u8) = []u8{ 1, 2, 255, 4 };