This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Don't permit dependent alignments on non-dependent typedef-names
ClosedPublic

Authored by majnemer on Mar 29 2015, 7:13 PM.

Details

Summary

A dependent alignment attribute (like attribute((aligned(...))) or
__declspec(align(...))) on a non-dependent typedef or using declaration
poses a considerable challenge: the type is _not_ dependent, the size
_may_ be dependent if the type is used as an array type, the alignment
_is_ dependent.

It is reasonable for a compiler to be able to query the size and
alignment of a complete type. Let's help that become an invariant.

This fixes PR22042.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 22859.Mar 29 2015, 7:13 PM
majnemer retitled this revision from to [Sema] Don't permit dependent alignments on non-dependent typedef-names.
majnemer updated this object.
majnemer added a reviewer: rsmith.
majnemer added a subscriber: Unknown Object (MLST).
rsmith added inline comments.Apr 6 2015, 4:30 PM
lib/Sema/SemaDeclAttr.cpp
2866

The 'type dependent' check here is redundant.

2869

I don't think you should check instantiation-dependence here. I think you should reject this, for instance:

template<int N> struct X {
  typedef __attribute__((aligned(N))) int X[sizeof(N)];
};
majnemer updated this revision to Diff 23304.Apr 6 2015, 6:36 PM
  • Address review comments
rsmith accepted this revision.Apr 6 2015, 6:56 PM
rsmith edited edge metadata.

LGTM. Can you also update the documentation to list this divergence from GCC behavior, with a brief explanation of why we think it's unreasonable to support?

This revision is now accepted and ready to land.Apr 6 2015, 6:56 PM
This revision was automatically updated to reflect the committed changes.