From b0c0554bd62689f48a1c42fc46c78c531cdb3cbf Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 21 May 2008 05:06:46 +0000 Subject: [PATCH] PR2347: Fix crash iterating over VLAs; this started triggering because we now iterate over the whole AST when we destroy it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51363 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/StmtIterator.cpp | 9 ++++----- test/Sema/vla.c | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/AST/StmtIterator.cpp b/lib/AST/StmtIterator.cpp index 14083e30a9..61b8e0f9c5 100644 --- a/lib/AST/StmtIterator.cpp +++ b/lib/AST/StmtIterator.cpp @@ -36,16 +36,16 @@ void StmtIteratorBase::NextVA() { p = FindVA(p->getElementType().getTypePtr()); setVAPtr(p); - if (!p && decl) { + if (!p && inDecl()) { if (VarDecl* VD = dyn_cast(decl)) if (VD->Init) return; NextDecl(); - } - else { + } else if (inSizeOfTypeVA()) { + assert(!decl); RawVAPtr = 0; - } + } } void StmtIteratorBase::NextDecl(bool ImmediateAdvance) { @@ -101,7 +101,6 @@ StmtIteratorBase::StmtIteratorBase(VariableArrayType* t) RawVAPtr |= reinterpret_cast(t); } - Stmt*& StmtIteratorBase::GetDeclExpr() const { if (VariableArrayType* VAPtr = getVAPtr()) { assert (VAPtr->SizeExpr); diff --git a/test/Sema/vla.c b/test/Sema/vla.c index c1e0e20e63..fcb533adbc 100644 --- a/test/Sema/vla.c +++ b/test/Sema/vla.c @@ -5,3 +5,11 @@ int test1() { static int y = sizeof(x); // expected-error {{not constant}} } +// PR2347 +void f (unsigned int m) +{ + extern int e[2][m]; + + e[0][0] = 0; +} + -- 2.50.1