]> granicus.if.org Git - clang/commitdiff
Fix test/Parser/if-scope-*.c. Patch by Neil Booth!
authorChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 23:08:06 +0000 (23:08 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 26 Aug 2007 23:08:06 +0000 (23:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41471 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseStmt.cpp
test/Parser/if-scope-c90.c [new file with mode: 0644]
test/Parser/if-scope-c99.c [new file with mode: 0644]

index 832eef213ec5bd1b81363054481477c0f40f2a2b..01cdbbcb4676c9c92a82844400202699f07d2aec 100644 (file)
@@ -427,10 +427,17 @@ Parser::StmtResult Parser::ParseIfStatement() {
     return true;
   }
   
+  // C99 6.8.4p3 - In C99, the if statement is a block.  This is not
+  // the case for C90.
+  if (getLang().C99)
+    EnterScope(Scope::DeclScope);
+
   // Parse the condition.
   ExprResult CondExp = ParseSimpleParenExpression();
   if (CondExp.isInvalid) {
     SkipUntil(tok::semi);
+    if (getLang().C99)
+      ExitScope();
     return true;
   }
   
@@ -472,6 +479,9 @@ Parser::StmtResult Parser::ParseIfStatement() {
       ElseStmt = Actions.ParseNullStmt(ElseLoc);
   }
   
+  if (getLang().C99)
+    ExitScope();
+
   return Actions.ParseIfStmt(IfLoc, CondExp.Val, CondStmt.Val,
                              ElseLoc, ElseStmt.Val);
 }
@@ -488,9 +498,13 @@ Parser::StmtResult Parser::ParseSwitchStatement() {
     SkipUntil(tok::semi);
     return true;
   }
-  
-  // Start the switch scope.
-  EnterScope(Scope::BreakScope|Scope::DeclScope);
+
+  // C99 6.8.4p3 - In C99, the switch statement is a block.  This is
+  // not the case for C90.  Start the switch scope.
+  if (getLang().C99)
+    EnterScope(Scope::BreakScope|Scope::DeclScope);
+  else
+    EnterScope(Scope::BreakScope);
 
   // Parse the condition.
   ExprResult Cond = ParseSimpleParenExpression();
@@ -538,8 +552,12 @@ Parser::StmtResult Parser::ParseWhileStatement() {
     return true;
   }
   
-  // Start the loop scope.
-  EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
+  // C99 6.8.5p5 - In C99, the while statement is a block.  This is not
+  // the case for C90.  Start the loop scope.
+  if (getLang().C99)
+    EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
+  else
+    EnterScope(Scope::BreakScope | Scope::ContinueScope);
 
   // Parse the condition.
   ExprResult Cond = ParseSimpleParenExpression();
@@ -571,8 +589,12 @@ Parser::StmtResult Parser::ParseDoStatement() {
   assert(Tok.getKind() == tok::kw_do && "Not a do stmt!");
   SourceLocation DoLoc = ConsumeToken();  // eat the 'do'.
   
-  // Start the loop scope.
-  EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
+  // C99 6.8.5p5 - In C99, the do statement is a block.  This is not
+  // the case for C90.  Start the loop scope.
+  if (getLang().C99)
+    EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
+  else
+    EnterScope(Scope::BreakScope | Scope::ContinueScope);
 
   // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
   // there is no compound stmt.  C90 does not have this clause. We only do this
@@ -626,7 +648,12 @@ Parser::StmtResult Parser::ParseForStatement() {
     return true;
   }
   
-  EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
+  // C99 6.8.5p5 - In C99, the for statement is a block.  This is not
+  // the case for C90.  Start the loop scope.
+  if (getLang().C99)
+    EnterScope(Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope);
+  else
+    EnterScope(Scope::BreakScope | Scope::ContinueScope);
 
   SourceLocation LParenLoc = ConsumeParen();
   ExprResult Value;
diff --git a/test/Parser/if-scope-c90.c b/test/Parser/if-scope-c90.c
new file mode 100644 (file)
index 0000000..6040281
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang -parse-ast-check --std=c90 %s
+
+int f (int z)
+{ 
+   if (z > sizeof (enum {a, b}))
+      return a;
+   return b;
+} 
diff --git a/test/Parser/if-scope-c99.c b/test/Parser/if-scope-c99.c
new file mode 100644 (file)
index 0000000..6547e6f
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang -parse-ast-check --std=c99 %s
+
+int f (int z)
+{ 
+   if (z > sizeof (enum {a, b}))
+      return a;
+   return b; // expected-error{{use of undeclared identifier}}
+}