[cfe-commits] r129700 - in /cfe/trunk: lib/Analysis/CFG.cpp lib/Sema/SemaStmt.cpp test/Analysis/PR9741.cpp
    Richard Smith 
    richard-llvm at metafoo.co.uk
       
    Mon Apr 18 08:49:25 PDT 2011
    
    
  
Author: rsmith
Date: Mon Apr 18 10:49:25 2011
New Revision: 129700
URL: http://llvm.org/viewvc/llvm-project?rev=129700&view=rev
Log:
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.
Added:
    cfe/trunk/test/Analysis/PR9741.cpp
Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=129700&r1=129699&r2=129700&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Apr 18 10:49:25 2011
@@ -2629,8 +2629,8 @@
 
   // 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,
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=129700&r1=129699&r2=129700&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Apr 18 10:49:25 2011
@@ -1029,6 +1029,7 @@
   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 @@
   SemaRef.AddInitializerToDecl(Decl, Init, /*DirectInit=*/false,
                                /*TypeMayContainAuto=*/false);
   SemaRef.FinalizeDeclaration(Decl);
+  SemaRef.CurContext->addHiddenDecl(Decl);
   return false;
 }
 
Added: cfe/trunk/test/Analysis/PR9741.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/PR9741.cpp?rev=129700&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/PR9741.cpp (added)
+++ cfe/trunk/test/Analysis/PR9741.cpp Mon Apr 18 10:49:25 2011
@@ -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)
+    ;
+}
    
    
More information about the cfe-commits
mailing list