compile error test for casting integer to c pointer

when the int has more bits than pointers

See #1059
master
Andrew Kelley 2019-02-12 10:25:21 -05:00
parent 6f05e8d1be
commit 270933b1e9
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 17 additions and 1 deletions

View File

@ -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;
}

View File

@ -1,6 +1,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 {};