Commit 4ff1b27
committed
Enforce minimal safe alignment on global variables
Currently, global variables are aligned according to their C types, e.g.
`char c[4];` has alignment 1.
However, the CompCert C semantics make it possible to cast `c` to `int *`
and dereference this pointer, which requires 4-alignment of `c` to be safe
on all platforms.
This commit makes sure that the alignment of a global variable is at
least the minimal safe alignment for its size, as defined in
`Memdata.min_safe_alignment`. This ensures that any memory access (at
offset 0) that fits within the bounds of the variable is aligned.
Without `_Alignas` modifiers, the alignment of a C type is always <=
the minimal safe alignment of the size of the type. However,
`_Alignas` modifiers can increase the C alignment beyond the minimal
safe alignment. We use the greater of the two alignments.1 parent e1ffc63 commit 4ff1b27
1 file changed
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1270 | 1270 | | |
1271 | 1271 | | |
1272 | 1272 | | |
1273 | | - | |
| 1273 | + | |
| 1274 | + | |
1274 | 1275 | | |
1275 | 1276 | | |
1276 | 1277 | | |
| |||
0 commit comments