diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-22 05:16:28 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-22 05:16:28 +0000 |
commit | a36ce713cff561b88f1cba5aad3f384c0fb0a249 (patch) | |
tree | cedd68e5ed7ff9a21d326747c176dfee903a9a7b | |
parent | 0cebe3e29b22d11f2c65ef28fcfb5f0431877266 (diff) |
Fix a nasty C99 scope issue that Neil pointed out (for ifs)
This fixes test/Parser/control-scope.c
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41263 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Parse/ParseStmt.cpp | 14 | ||||
-rw-r--r-- | test/Parser/control-scope.c | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/Parse/ParseStmt.cpp b/Parse/ParseStmt.cpp index 6784f166c9..f96da44623 100644 --- a/Parse/ParseStmt.cpp +++ b/Parse/ParseStmt.cpp @@ -433,6 +433,10 @@ Parser::StmtResult Parser::ParseIfStatement() { 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 @@ Parser::StmtResult Parser::ParseIfStatement() { 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); diff --git a/test/Parser/control-scope.c b/test/Parser/control-scope.c new file mode 100644 index 0000000000..62f79dbdf1 --- /dev/null +++ b/test/Parser/control-scope.c @@ -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; +} |