PR19252: Fix crash if alignas is used with an auto-typed variable. Don't check

the type of the variable until it's known.

llvm-svn: 204887
This commit is contained in:
Richard Smith 2014-03-27 01:22:48 +00:00
parent ffa4b7993f
commit dc4ccaaf66
4 changed files with 6 additions and 7 deletions

View File

@ -5344,9 +5344,6 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
// Handle attributes prior to checking for duplicates in MergeVarDecl
ProcessDeclAttributes(S, NewVD, D);
if (NewVD->hasAttrs())
CheckAlignasUnderalignment(NewVD);
if (getLangOpts().CUDA) {
// CUDA B.2.5: "__shared__ and __constant__ variables have implied static
// storage [duration]."
@ -5734,6 +5731,9 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
if (T->isUndeducedType())
return;
if (NewVD->hasAttrs())
CheckAlignasUnderalignment(NewVD);
if (T->isObjCObjectType()) {
Diag(NewVD->getLocation(), diag::err_statically_allocated_object)
<< FixItHint::CreateInsertion(NewVD->getLocation(), "*");
@ -5851,7 +5851,6 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
if (NewVD->isConstexpr() && !T->isDependentType() &&
RequireLiteralType(NewVD->getLocation(), T,
diag::err_constexpr_var_non_literal)) {
// Can't perform this check until the type is deduced.
NewVD->setInvalidDecl();
return;
}

View File

@ -3593,9 +3593,6 @@ void Sema::BuildVariableInstantiation(
InstantiateAttrs(TemplateArgs, OldVar, NewVar, LateAttrs, StartingScope);
if (NewVar->hasAttrs())
CheckAlignasUnderalignment(NewVar);
LookupResult Previous(
*this, NewVar->getDeclName(), NewVar->getLocation(),
NewVar->isLocalExternDecl() ? Sema::LookupRedeclarationWithLinkage

View File

@ -9,6 +9,7 @@ alignas(1) alignas(4) int n6 alignas(2); // ok
alignas(1) int n7 alignas(2), // expected-error {{less than minimum alignment}}
n8 alignas(4); // ok
alignas(8) int n9 alignas(2); // ok, overaligned
alignas(1) extern int n10; // expected-error {{less than minimum alignment}}
enum alignas(1) E1 {}; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'E1'}}
enum alignas(1) E2 : char {}; // ok

View File

@ -48,3 +48,5 @@ static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expe
[[__carries_dependency__]] // expected-warning{{unknown attribute '__carries_dependency__' ignored}}
void func(void);
alignas(4) auto PR19252 = 0;