commit 270933b1e997c91a9c2d28b6896d625c0ae1b163 (tree)
parent 6f05e8d1be083a429673e717e8b3c736c7ddb8d2
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 12 Feb 2019 10:25:21 -0500
compile error test for casting integer to c pointer
when the int has more bits than pointers
See #1059
Diffstat:
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -10882,7 +10882,9 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
ira->codegen->builtin_types.entry_usize->data.integral.bit_count)
{
ir_add_error(ira, source_instr,
- buf_sprintf("integer type too big for implicit @intToPtr to type '%s'", buf_ptr(&dest_type->name)));
+ buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
+ buf_ptr(&integer->value.type->name),
+ buf_ptr(&dest_type->name)));
return ira->codegen->invalid_instruction;
}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -2,6 +2,20 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addTest(
+ "implicit casting too big integers to C pointers",
+ \\export fn a() void {
+ \\ var ptr: [*c]u8 = (1 << 64) + 1;
+ \\}
+ \\export fn b() void {
+ \\ var x: @IntType(false, 65) = 0x1234;
+ \\ var ptr: [*c]u8 = x;
+ \\}
+ ,
+ ".tmp_source.zig:2:33: error: integer value 71615590737044764481 cannot be implicitly casted to type 'usize'",
+ ".tmp_source.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
+ );
+
+ cases.addTest(
"C pointer pointing to non C ABI compatible type",
\\const Foo = struct {};
\\export fn entry() [*c]Foo {