mirror of
https://github.com/ziglang/zig.git
synced 2024-12-17 08:40:19 +00:00
allow C pointers to have alignment
clang/gcc support pointer alignment attribute: https://clang.llvm.org/docs/AttributeReference.html#align-value
This commit is contained in:
parent
cc7060d0d9
commit
d5bbd74871
@ -5057,11 +5057,6 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
|
||||
|
||||
IrInstruction *align_value;
|
||||
if (align_expr != nullptr) {
|
||||
if (ptr_len == PtrLenC) {
|
||||
exec_add_error_node(irb->codegen, irb->exec, node,
|
||||
buf_sprintf("[*c] pointers may not have align attribute"));
|
||||
return irb->codegen->invalid_instruction;
|
||||
}
|
||||
align_value = ir_gen_node(irb, align_expr, scope);
|
||||
if (align_value == irb->codegen->invalid_instruction)
|
||||
return align_value;
|
||||
|
@ -123,12 +123,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
\\export fn a() void {
|
||||
\\ const T = [*c]Foo;
|
||||
\\}
|
||||
\\export fn b() void {
|
||||
\\ const T = [*c]align(4) u8;
|
||||
\\}
|
||||
,
|
||||
".tmp_source.zig:3:15: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
|
||||
".tmp_source.zig:6:15: error: [*c] pointers may not have align attribute",
|
||||
);
|
||||
|
||||
cases.addTest(
|
||||
|
@ -67,12 +67,12 @@ test "type info: C pointer type info" {
|
||||
}
|
||||
|
||||
fn testCPtr() void {
|
||||
const ptr_info = @typeInfo([*c]const i8);
|
||||
const ptr_info = @typeInfo([*c]align(4) const i8);
|
||||
expect(TypeId(ptr_info) == TypeId.Pointer);
|
||||
expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C);
|
||||
expect(ptr_info.Pointer.is_const);
|
||||
expect(!ptr_info.Pointer.is_volatile);
|
||||
expect(ptr_info.Pointer.alignment == 1);
|
||||
expect(ptr_info.Pointer.alignment == 4);
|
||||
expect(ptr_info.Pointer.child == i8);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user