mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-24 01:58:21 +00:00
Fix a nasty C99 scope issue that Neil pointed out (for ifs)
This fixes test/Parser/control-scope.c llvm-svn: 41263
This commit is contained in:
parent
8a63218855
commit
37e54f454a
@ -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);
|
||||
|
8
clang/test/Parser/control-scope.c
Normal file
8
clang/test/Parser/control-scope.c
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user