-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR][Codegen] Initial support for packed structures (#473)
This PR adds a support for packed structures. Basically, now both `pragma pack(...)` and `__attribute__((aligned(...)))` should work. The only problem is that `getAlignment` is not a total one - I fix only a couple of issues I faced with - for struct types and arrays.
- Loading branch information
Showing
5 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
#pragma pack(1) | ||
|
||
typedef struct { | ||
int a0; | ||
char a1; | ||
} A; | ||
|
||
typedef struct { | ||
int b0; | ||
char b1; | ||
A a[6]; | ||
} B; | ||
|
||
typedef struct { | ||
int c0; | ||
char c1; | ||
} __attribute__((aligned(2))) C; | ||
|
||
|
||
// CHECK: !ty_22A22 = !cir.struct<struct "A" packed {!s32i, !s8i}> | ||
// CHECK: !ty_22C22 = !cir.struct<struct "C" packed {!s32i, !s8i}> | ||
// CHECK: !ty_22B22 = !cir.struct<struct "B" packed {!s32i, !s8i, !cir.array<!ty_22A22 x 6>}> | ||
|
||
// CHECK: cir.func {{.*@foo()}} | ||
// CHECK: %0 = cir.alloca !ty_22A22, cir.ptr <!ty_22A22>, ["a"] {alignment = 1 : i64} | ||
// CHECK: %1 = cir.alloca !ty_22B22, cir.ptr <!ty_22B22>, ["b"] {alignment = 1 : i64} | ||
// CHECK: %2 = cir.alloca !ty_22C22, cir.ptr <!ty_22C22>, ["c"] {alignment = 2 : i64} | ||
void foo() { | ||
A a; | ||
B b; | ||
C c; | ||
} | ||
|
||
|