summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-04-18 15:49:25 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-04-18 15:49:25 +0000
commit0c502d2a6264fec85b06689b3a96bc797f05650c (patch)
treeaffb71eaa54a346bc94cc7835794516d15917fff
parent6c7a9eec42033931a9ed09b92561c39c0abbd59e (diff)
downloadbcm5719-llvm-0c502d2a6264fec85b06689b3a96bc797f05650c.tar.gz
bcm5719-llvm-0c502d2a6264fec85b06689b3a96bc797f05650c.zip
Fix PR9741. The implicit declarations created for range-based for loops weren't being added to the DeclContext (nor were they being marked as implicit). Also, the declarations were being emitted in the wrong order when building the CFG.
llvm-svn: 129700
-rw-r--r--clang/lib/Analysis/CFG.cpp4
-rw-r--r--clang/lib/Sema/SemaStmt.cpp2
-rw-r--r--clang/test/Analysis/PR9741.cpp8
3 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index bfe2247fba1..eaab487d959 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -2629,8 +2629,8 @@ CFGBlock* CFGBuilder::VisitCXXForRangeStmt(CXXForRangeStmt* S) {
// Add the initialization statements.
Block = createBlock();
- addStmt(S->getRangeStmt());
- return addStmt(S->getBeginEndStmt());
+ addStmt(S->getBeginEndStmt());
+ return addStmt(S->getRangeStmt());
}
CFGBlock *CFGBuilder::VisitExprWithCleanups(ExprWithCleanups *E,
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 407618219fb..e6609c08e21 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -1029,6 +1029,7 @@ static VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc,
TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc);
VarDecl *Decl = VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type,
TInfo, SC_Auto, SC_None);
+ Decl->setImplicit();
return Decl;
}
@@ -1052,6 +1053,7 @@ static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init,
SemaRef.AddInitializerToDecl(Decl, Init, /*DirectInit=*/false,
/*TypeMayContainAuto=*/false);
SemaRef.FinalizeDeclaration(Decl);
+ SemaRef.CurContext->addHiddenDecl(Decl);
return false;
}
diff --git a/clang/test/Analysis/PR9741.cpp b/clang/test/Analysis/PR9741.cpp
new file mode 100644
index 00000000000..e20e56c9406
--- /dev/null
+++ b/clang/test/Analysis/PR9741.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -cc1 -std=c++0x -Wuninitialized -verify %s
+
+void f() {
+ int a[] = { 1, 2, 3 };
+ unsigned int u = 0;
+ for (auto x : a)
+ ;
+}
OpenPOWER on IntegriCloud