From 0ec213d4c9a6141c881c4df3ae9dd667a18f95da Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 27 Mar 2014 01:22:48 +0000 Subject: [PATCH] PR19252: Fix crash if alignas is used with an auto-typed variable. Don't check the type of the variable until it's known. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204887 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 7 +++---- lib/Sema/SemaTemplateInstantiateDecl.cpp | 3 --- test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp | 1 + test/SemaCXX/attr-cxx0x.cpp | 2 ++ 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e4511c925f..bfbd870eef 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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; } diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 0982f44257..8766c887f8 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -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 diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp index 10be98d16e..3c250f9d25 100644 --- a/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp +++ b/test/CXX/dcl.dcl/dcl.attr/dcl.align/p5.cpp @@ -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 diff --git a/test/SemaCXX/attr-cxx0x.cpp b/test/SemaCXX/attr-cxx0x.cpp index 02d9dc9129..6ba89a62d7 100644 --- a/test/SemaCXX/attr-cxx0x.cpp +++ b/test/SemaCXX/attr-cxx0x.cpp @@ -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; -- 2.40.0