| author | |
| committer | |
| log | 285e2f62ba0648d6d8e7ff64d1ee7d2900481e2f |
| tree | ca99c7ae5e4e29bb12a750b92a8d292b3e09a556 |
| parent | 0abe6d668eb52aefa59c75a8d8f782f2372f8600 |
| signature |
See #10594 files changed, 16 insertions(+), 2 deletions(-)
src/analyze.cpp+1-1| ... | @@ -1469,7 +1469,7 @@ static bool type_allowed_in_packed_struct(ZigType *type_entry) { | ... | @@ -1469,7 +1469,7 @@ static bool type_allowed_in_packed_struct(ZigType *type_entry) { |
| 1469 | zig_unreachable(); | 1469 | zig_unreachable(); |
| 1470 | } | 1470 | } |
| 1471 | 1471 | ||
| 1472 | static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { | 1472 | bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { |
| 1473 | switch (type_entry->id) { | 1473 | switch (type_entry->id) { |
| 1474 | case ZigTypeIdInvalid: | 1474 | case ZigTypeIdInvalid: |
| 1475 | zig_unreachable(); | 1475 | zig_unreachable(); |
src/analyze.hpp+1-1| ... | @@ -44,7 +44,7 @@ void find_libc_include_path(CodeGen *g); | ... | @@ -44,7 +44,7 @@ void find_libc_include_path(CodeGen *g); |
| 44 | void find_libc_lib_path(CodeGen *g); | 44 | void find_libc_lib_path(CodeGen *g); |
| 45 | 45 | ||
| 46 | bool type_has_bits(ZigType *type_entry); | 46 | bool type_has_bits(ZigType *type_entry); |
| 47 | 47 | bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry); | |
| 48 | 48 | ||
| 49 | ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code); | 49 | ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code); |
| 50 | 50 |
src/ir.cpp+4| ... | @@ -21145,6 +21145,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct | ... | @@ -21145,6 +21145,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 21145 | } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) { | 21145 | } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) { |
| 21146 | ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque")); | 21146 | ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque")); |
| 21147 | return ira->codegen->invalid_instruction; | 21147 | return ira->codegen->invalid_instruction; |
| 21148 | } else if (instruction->ptr_len == PtrLenC && !type_allowed_in_extern(ira->codegen, child_type)) { | ||
| 21149 | ir_add_error(ira, &instruction->base, | ||
| 21150 | buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'", buf_ptr(&child_type->name))); | ||
| 21151 | return ira->codegen->invalid_instruction; | ||
| 21148 | } | 21152 | } |
| 21149 | 21153 | ||
| 21150 | uint32_t align_bytes; | 21154 | uint32_t align_bytes; |
test/compile_errors.zig+10| ... | @@ -1,6 +1,16 @@ | ... | @@ -1,6 +1,16 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4 | cases.addTest( | ||
| 5 | "C pointer pointing to non C ABI compatible type", | ||
| 6 | \\const Foo = struct {}; | ||
| 7 | \\export fn entry() [*c]Foo { | ||
| 8 | \\ return undefined; | ||
| 9 | \\} | ||
| 10 | , | ||
| 11 | ".tmp_source.zig:2:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | ||
| 12 | ); | ||
| 13 | |||
| 4 | cases.addTest( | 14 | cases.addTest( |
| 5 | "@truncate undefined value", | 15 | "@truncate undefined value", |
| 6 | \\export fn entry() void { | 16 | \\export fn entry() void { |