Skip to content

Commit

Permalink
Merge pull request #130 from goblint/alignas_support
Browse files Browse the repository at this point in the history
Respect C11 `_Alignas(...)` for computing alignments
  • Loading branch information
michael-schwarz authored Feb 12, 2023
2 parents c03ade1 + d75db7a commit 2ec2b95
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/frontc/cparser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,8 @@ decl_spec_list_common: /* ISO 6.7 */
/* ISO 6.7.4 */
| INLINE decl_spec_list_opt { SpecInline :: $2, $1 }
| NORETURN decl_spec_list_opt { SpecNoreturn :: $2, $1 }
| ALIGNAS LPAREN expression RPAREN decl_spec_list_opt { $5, $1 }
| ALIGNAS LPAREN type_name RPAREN decl_spec_list_opt { $5, $1 }
| ALIGNAS LPAREN expression RPAREN decl_spec_list_opt { SpecAttr ("aligned", [fst $3]) :: $5, $1 }
| ALIGNAS LPAREN type_name RPAREN decl_spec_list_opt { let b, d = $3 in SpecAttr ("aligned", [ TYPE_ALIGNOF (b, d) ]) :: $5, $1 }

| cvspec decl_spec_list_opt { (fst $1) :: $2, snd $1 }
/* specifier pattern variable (must be last in spec list) */
Expand Down
26 changes: 26 additions & 0 deletions test/small1/alignas_proper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdalign.h>

struct testalign {
int f1;
} __attribute__((__aligned__(16)));

struct testalign2 {
_Alignas(16) int f1;
};

struct testalign3 {
_Alignas(long double) int f1;
};


int main() {
struct testalign a;
char static_assertion_failure_1[(__alignof__ (a) == 16) ? 1 : -1];

struct testalign2 b;
char static_assertion_failure_2[(__alignof__ (b) == 16) ? 1 : -1];

struct testalign3 c;
char static_assertion_failure_3[(__alignof__ (c) == __alignof__ (long double)) ? 1 : -1];
return 0;
}
1 change: 1 addition & 0 deletions test/testcil.pl
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ sub addToGroup {
addTestFail("testc11/clang-c11-generic-1-2", "No compatible associations or default in generic");
addTest("testc11/clang-c11-generic-2");
addTest("testc11/alignas");
addTest("testc11/alignas_proper");

# ---------------- c-torture -------------
## if we have the c-torture tests add them
Expand Down

0 comments on commit 2ec2b95

Please sign in to comment.