Skip to content

Commit 2ec2b95

Browse files
Merge pull request #130 from goblint/alignas_support
Respect C11 `_Alignas(...)` for computing alignments
2 parents c03ade1 + d75db7a commit 2ec2b95

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/frontc/cparser.mly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,8 @@ decl_spec_list_common: /* ISO 6.7 */
10521052
/* ISO 6.7.4 */
10531053
| INLINE decl_spec_list_opt { SpecInline :: $2, $1 }
10541054
| NORETURN decl_spec_list_opt { SpecNoreturn :: $2, $1 }
1055-
| ALIGNAS LPAREN expression RPAREN decl_spec_list_opt { $5, $1 }
1056-
| ALIGNAS LPAREN type_name RPAREN decl_spec_list_opt { $5, $1 }
1055+
| ALIGNAS LPAREN expression RPAREN decl_spec_list_opt { SpecAttr ("aligned", [fst $3]) :: $5, $1 }
1056+
| ALIGNAS LPAREN type_name RPAREN decl_spec_list_opt { let b, d = $3 in SpecAttr ("aligned", [ TYPE_ALIGNOF (b, d) ]) :: $5, $1 }
10571057

10581058
| cvspec decl_spec_list_opt { (fst $1) :: $2, snd $1 }
10591059
/* specifier pattern variable (must be last in spec list) */

test/small1/alignas_proper.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdalign.h>
2+
3+
struct testalign {
4+
int f1;
5+
} __attribute__((__aligned__(16)));
6+
7+
struct testalign2 {
8+
_Alignas(16) int f1;
9+
};
10+
11+
struct testalign3 {
12+
_Alignas(long double) int f1;
13+
};
14+
15+
16+
int main() {
17+
struct testalign a;
18+
char static_assertion_failure_1[(__alignof__ (a) == 16) ? 1 : -1];
19+
20+
struct testalign2 b;
21+
char static_assertion_failure_2[(__alignof__ (b) == 16) ? 1 : -1];
22+
23+
struct testalign3 c;
24+
char static_assertion_failure_3[(__alignof__ (c) == __alignof__ (long double)) ? 1 : -1];
25+
return 0;
26+
}

test/testcil.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ sub addToGroup {
747747
addTestFail("testc11/clang-c11-generic-1-2", "No compatible associations or default in generic");
748748
addTest("testc11/clang-c11-generic-2");
749749
addTest("testc11/alignas");
750+
addTest("testc11/alignas_proper");
750751

751752
# ---------------- c-torture -------------
752753
## if we have the c-torture tests add them

0 commit comments

Comments
 (0)