| author | |
| committer | |
| log | cc7060d0d934135d797bd2bc24288ecab095051a |
| tree | f7a94569505fe31bd71bb0b61ff4c20bbcdbf3f8 |
| parent | 973a93d43b8b44d2ee8bfde09e78f8295470f337 |
| signature |
See #10593 files changed, 15 insertions(+), 6 deletions(-)
src/ir.cpp+5| ... | ... | @@ -5057,6 +5057,11 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 5057 | 5057 | |
| 5058 | 5058 | IrInstruction *align_value; |
| 5059 | 5059 | if (align_expr != nullptr) { |
| 5060 | if (ptr_len == PtrLenC) { | |
| 5061 | exec_add_error_node(irb->codegen, irb->exec, node, | |
| 5062 | buf_sprintf("[*c] pointers may not have align attribute")); | |
| 5063 | return irb->codegen->invalid_instruction; | |
| 5064 | } | |
| 5060 | 5065 | align_value = ir_gen_node(irb, align_expr, scope); |
| 5061 | 5066 | if (align_value == irb->codegen->invalid_instruction) |
| 5062 | 5067 | return align_value; |
test/compile_errors.zig+8-4| ... | ... | @@ -118,13 +118,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | 120 | cases.addTest( |
| 121 | "C pointer pointing to non C ABI compatible type", | |
| 121 | "C pointer pointing to non C ABI compatible type or has align attr", | |
| 122 | 122 | \\const Foo = struct {}; |
| 123 | \\export fn entry() [*c]Foo { | |
| 124 | \\ return undefined; | |
| 123 | \\export fn a() void { | |
| 124 | \\ const T = [*c]Foo; | |
| 125 | \\} | |
| 126 | \\export fn b() void { | |
| 127 | \\ const T = [*c]align(4) u8; | |
| 125 | 128 | \\} |
| 126 | 129 | , |
| 127 | ".tmp_source.zig:2:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | |
| 130 | ".tmp_source.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", | |
| 131 | ".tmp_source.zig:6:15: error: [*c] pointers may not have align attribute", | |
| 128 | 132 | ); |
| 129 | 133 | |
| 130 | 134 | cases.addTest( |
test/stage1/behavior/type_info.zig+2-2| ... | ... | @@ -67,12 +67,12 @@ test "type info: C pointer type info" { |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | fn testCPtr() void { |
| 70 | const ptr_info = @typeInfo([*c]align(4) const i8); | |
| 70 | const ptr_info = @typeInfo([*c]const i8); | |
| 71 | 71 | expect(TypeId(ptr_info) == TypeId.Pointer); |
| 72 | 72 | expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C); |
| 73 | 73 | expect(ptr_info.Pointer.is_const); |
| 74 | 74 | expect(!ptr_info.Pointer.is_volatile); |
| 75 | expect(ptr_info.Pointer.alignment == 4); | |
| 75 | expect(ptr_info.Pointer.alignment == 1); | |
| 76 | 76 | expect(ptr_info.Pointer.child == i8); |
| 77 | 77 | } |
| 78 | 78 |