[RFC] Sort out and correct pragma align/pack stack effect


Recently we are trying to implement AIX pragma align/pack stack effect, but noticed current implementation model in Clang has some limitations.

That results from mixing #pragma pack and #pragma align by using only an unsigned number to represent both so that they could override each other.

Some examples we have been aware of are:

  1. The current diagnostic for pragma pack does not produce a valid diagnostic when align pragma is involved. For example,

$ cat test_diag.c

#pragma align = natural

$ clang test_diag.c -S

test_diag.c:1:9: warning: unterminated ‘#pragma pack (push, …)’ at end of file [-Wpragma-pack]

#pragma align = natural


test_diag.c:1:9: note: did you intend to use ‘#pragma pack (pop)’ instead of ‘#pragma pack()’?

1 warning generated.

The diagnostic is misleading by indicating some *'#pragma pack* is unterminated. This is caused by not differentiating between align pragma and pack pragma in clang’s current align and pack stack model.

2**.**There exists platforms like AIX that cannot have pragma align/pack stack effect simply represented by an alignment value. The stack effect between align and pack pragmas on AIX is different.

(1)They don’t override but create combinations with each other sometimes.
#pragma align(natural)
#pragma pack(2)

In current Clang’s implementation we get pack(2) in effect here without knowing align mode information above it;

However, XL on AIX would need to align objects to natural alignment first and then reduced by pack(2).