diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-04-27 05:04:02 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-04-27 05:04:02 +0000 |
commit | b7d98d35ea723624345f06e5895ddce2e0388ef0 (patch) | |
tree | aabd233e19ac179216d6a8c569d2405f6afe5d8b /lib | |
parent | 3b887354b1b667c97d070ddc67b5354353c4c07b (diff) |
If a null statement was preceded by an empty macro keep its instantiation source location
in NullStmt.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130289 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Lex/PPMacroExpansion.cpp | 7 | ||||
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 5 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderStmt.cpp | 2 | ||||
-rw-r--r-- | lib/Serialization/ASTWriterStmt.cpp | 2 |
5 files changed, 13 insertions, 9 deletions
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 29f9cd6e32..32b2188af5 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -227,6 +227,9 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, // If we started lexing a macro, enter the macro expansion body. + // Remember where the token is instantiated. + SourceLocation InstantiateLoc = Identifier.getLocation(); + // If this macro expands to no tokens, don't bother to push it onto the // expansion stack, only to take it right back off. if (MI->getNumTokens() == 0) { @@ -249,6 +252,7 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, if (HadLeadingSpace) Identifier.setFlag(Token::LeadingSpace); } Identifier.setFlag(Token::LeadingEmptyMacro); + LastEmptyMacroInstantiationLoc = InstantiateLoc; ++NumFastMacroExpanded; return false; @@ -267,9 +271,6 @@ bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier, bool isAtStartOfLine = Identifier.isAtStartOfLine(); bool hasLeadingSpace = Identifier.hasLeadingSpace(); - // Remember where the token is instantiated. - SourceLocation InstantiateLoc = Identifier.getLocation(); - // Replace the result token. Identifier = MI->getReplacementToken(0); diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 3aec4ea210..5138cc1595 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -276,8 +276,10 @@ Retry: case tok::l_brace: // C99 6.8.2: compound-statement return ParseCompoundStatement(attrs); case tok::semi: { // C99 6.8.3p3: expression[opt] ';' - bool LeadingEmptyMacro = Tok.hasLeadingEmptyMacro(); - return Actions.ActOnNullStmt(ConsumeToken(), LeadingEmptyMacro); + SourceLocation LeadingEmptyMacroLoc; + if (Tok.hasLeadingEmptyMacro()) + LeadingEmptyMacroLoc = PP.getLastEmptyMacroInstantiationLoc(); + return Actions.ActOnNullStmt(ConsumeToken(), LeadingEmptyMacroLoc); } case tok::kw_if: // C99 6.8.4.1: if-statement diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 5e21a36758..38f3bf9e92 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -46,8 +46,9 @@ StmtResult Sema::ActOnExprStmt(FullExprArg expr) { } -StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc, bool LeadingEmptyMacro) { - return Owned(new (Context) NullStmt(SemiLoc, LeadingEmptyMacro)); +StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc, + SourceLocation LeadingEmptyMacroLoc) { + return Owned(new (Context) NullStmt(SemiLoc, LeadingEmptyMacroLoc)); } StmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg, SourceLocation StartLoc, diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 608aafc3ce..3435fd92d3 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -211,7 +211,7 @@ void ASTStmtReader::VisitStmt(Stmt *S) { void ASTStmtReader::VisitNullStmt(NullStmt *S) { VisitStmt(S); S->setSemiLoc(ReadSourceLocation(Record, Idx)); - S->LeadingEmptyMacro = Record[Idx++]; + S->LeadingEmptyMacro = ReadSourceLocation(Record, Idx); } void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) { diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 19cd834dd4..53fb9738e6 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -180,7 +180,7 @@ void ASTStmtWriter::VisitStmt(Stmt *S) { void ASTStmtWriter::VisitNullStmt(NullStmt *S) { VisitStmt(S); Writer.AddSourceLocation(S->getSemiLoc(), Record); - Record.push_back(S->LeadingEmptyMacro); + Writer.AddSourceLocation(S->LeadingEmptyMacro, Record); Code = serialization::STMT_NULL; } |