[cfe-commits] r41263 - in /cfe/trunk: Parse/ParseStmt.cpp test/Parser/control-scope.c

Chris Lattner sabre at nondot.org
Tue Aug 21 22:16:29 PDT 2007


Author: lattner
Date: Wed Aug 22 00:16:28 2007
New Revision: 41263

URL: http://llvm.org/viewvc/llvm-project?rev=41263&view=rev
Log:
Fix a nasty C99 scope issue that Neil pointed out (for ifs)
This fixes test/Parser/control-scope.c

Added:
    cfe/trunk/test/Parser/control-scope.c
Modified:
    cfe/trunk/Parse/ParseStmt.cpp

Modified: cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseStmt.cpp?rev=41263&r1=41262&r2=41263&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/Parse/ParseStmt.cpp Wed Aug 22 00:16:28 2007
@@ -433,6 +433,10 @@
     return true;
   }
   
+  // In C99, the body of the if statement is a scope, even if there is no
+  // compound stmt.
+  if (getLang().C99) EnterScope(0);
+  
   // Read the if condition.
   StmtResult CondStmt = ParseStatement();
 
@@ -440,13 +444,23 @@
   if (CondStmt.isInvalid)
     CondStmt = Actions.ParseNullStmt(Tok.getLocation());
   
+  // Pop the 'if' scope if needed.
+  if (getLang().C99) ExitScope();
   
   // If it has an else, parse it.
   SourceLocation ElseLoc;
   StmtResult ElseStmt(false);
   if (Tok.getKind() == tok::kw_else) {
     ElseLoc = ConsumeToken();
+    
+    // In C99, the body of the if statement is a scope, even if there is no
+    // compound stmt.
+    if (getLang().C99) EnterScope(0);
+    
     ElseStmt = ParseStatement();
+
+    // Pop the 'else' scope if needed.
+    if (getLang().C99) ExitScope();
     
     if (ElseStmt.isInvalid)
       ElseStmt = Actions.ParseNullStmt(ElseLoc);

Added: cfe/trunk/test/Parser/control-scope.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/control-scope.c?rev=41263&view=auto

==============================================================================
--- cfe/trunk/test/Parser/control-scope.c (added)
+++ cfe/trunk/test/Parser/control-scope.c Wed Aug 22 00:16:28 2007
@@ -0,0 +1,8 @@
+// RUN: not clang %s -std=c90
+// RUN: clang %s -std=c99
+
+int f (int z) { 
+  if (z + sizeof (enum {a})) 
+    return 1 + sizeof (enum {a}); 
+  return 0; 
+}





More information about the cfe-commits mailing list