UBSan's alignment check does not detect unaligned loads and stores from
extern struct declarations. Example:
struct S { int i; }; extern struct S g_S; // &g_S may not be aligned properly. int main() { return g_S.i; // No alignment check for &g_S.i is emitted. }
The frontend skips the alignment check for &g_S.i because the check is
constant-folded to 'NOT NULL' by the IR builder.
If we drop the alignment information from extern struct declarations,
the IR builder would no longer be able to constant-fold the checks away.
That would make the alignment check more useful.
Note: it would still not be able to catch the following case --
extern int i; // &i is not aligned properly.
PR: https://bugs.llvm.org/show_bug.cgi?id=32630
Testing: check-clang, check-ubsan.
If we don't explicitly set the alignment, is it 1? Or is it picking up the alignment from the type somehow?