authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-14 20:04:13-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-14 20:04:13-05:00
logd5bbd748711abc82272199869cf70faf1ea30f52
treea3a15180a22228a4c38ccdcd79815349746aeaa4
parentcc7060d0d934135d797bd2bc24288ecab095051a
signaturelock-open Commit is signed but in an unrecognized format.

allow C pointers to have alignment

clang/gcc support pointer alignment attribute: https://clang.llvm.org/docs/AttributeReference.html#align-value

3 files changed, 2 insertions(+), 11 deletions(-)

src/ir.cpp-5
...@@ -5057,11 +5057,6 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -5057,11 +5057,6 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
50575057
5058 IrInstruction *align_value;5058 IrInstruction *align_value;
5059 if (align_expr != nullptr) {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 }
5065 align_value = ir_gen_node(irb, align_expr, scope);5060 align_value = ir_gen_node(irb, align_expr, scope);
5066 if (align_value == irb->codegen->invalid_instruction)5061 if (align_value == irb->codegen->invalid_instruction)
5067 return align_value;5062 return align_value;
test/compile_errors.zig-4
...@@ -123,12 +123,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -123,12 +123,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
123 \\export fn a() void {123 \\export fn a() void {
124 \\ const T = [*c]Foo;124 \\ const T = [*c]Foo;
125 \\}125 \\}
126 \\export fn b() void {
127 \\ const T = [*c]align(4) u8;
128 \\}
129 ,126 ,
130 ".tmp_source.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",127 ".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",
132 );128 );
133129
134 cases.addTest(130 cases.addTest(
test/stage1/behavior/type_info.zig+2-2
...@@ -67,12 +67,12 @@ test "type info: C pointer type info" {...@@ -67,12 +67,12 @@ test "type info: C pointer type info" {
67}67}
6868
69fn testCPtr() void {69fn testCPtr() void {
70 const ptr_info = @typeInfo([*c]const i8);70 const ptr_info = @typeInfo([*c]align(4) const i8);
71 expect(TypeId(ptr_info) == TypeId.Pointer);71 expect(TypeId(ptr_info) == TypeId.Pointer);
72 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);72 expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);
73 expect(ptr_info.Pointer.is_const);73 expect(ptr_info.Pointer.is_const);
74 expect(!ptr_info.Pointer.is_volatile);74 expect(!ptr_info.Pointer.is_volatile);
75 expect(ptr_info.Pointer.alignment == 1);75 expect(ptr_info.Pointer.alignment == 4);
76 expect(ptr_info.Pointer.child == i8);76 expect(ptr_info.Pointer.child == i8);
77}77}
7878