From 2364b4457f2b5b2dd54b0e15e8dcb5e62d211e37 Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Thu, 30 Jan 2014 18:09:55 +0000 Subject: [PATCH] Fix assertion failures on annot_* tokens in clang -E In particular, #pragma clang __debug, and #include implicitly changed into @import were causing assertion failures. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200475 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/PrintPreprocessedOutput.cpp | 9 ++++----- lib/Lex/TokenConcatenation.cpp | 9 ++++++--- test/Preprocessor/Inputs/a.h | 1 + test/Preprocessor/Inputs/module.map | 4 ++++ test/Preprocessor/annot-tokens.m | 5 +++++ 5 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 test/Preprocessor/Inputs/a.h create mode 100644 test/Preprocessor/Inputs/module.map create mode 100644 test/Preprocessor/annot-tokens.m diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index f3393bfe51..834e5262c6 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -342,6 +342,7 @@ void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc, OS << "@import " << Imported->getFullModuleName() << ";" << " /* clang -E: implicit import for \"" << File->getName() << "\" */"; EmittedTokensOnThisLine = true; + setEmittedDirectiveOnThisLine(); } } @@ -657,11 +658,9 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, // -traditional-cpp the lexer keeps /all/ whitespace, including comments. SourceLocation StartLoc = Tok.getLocation(); Callbacks->MoveToLine(StartLoc.getLocWithOffset(Tok.getLength())); - } else if (Tok.is(tok::annot_module_include) || - Tok.is(tok::annot_module_begin) || - Tok.is(tok::annot_module_end)) { - // PrintPPOutputPPCallbacks::InclusionDirective handles producing - // appropriate output here. Ignore this token entirely. + } else if (Tok.isAnnotation()) { + // PrintPPOutputPPCallbacks handles producing appropriate output here. + // Ignore this token entirely. PP.Lex(Tok); continue; } else if (IdentifierInfo *II = Tok.getIdentifierInfo()) { diff --git a/lib/Lex/TokenConcatenation.cpp b/lib/Lex/TokenConcatenation.cpp index 0a66bba91f..9de28a875e 100644 --- a/lib/Lex/TokenConcatenation.cpp +++ b/lib/Lex/TokenConcatenation.cpp @@ -163,8 +163,8 @@ bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok, return false; tok::TokenKind PrevKind = PrevTok.getKind(); - if (PrevTok.getIdentifierInfo()) // Language keyword or named operator. - PrevKind = tok::identifier; + if (!PrevTok.isAnnotation() && PrevTok.getIdentifierInfo()) + PrevKind = tok::identifier; // Language keyword or named operator. // Look up information on when we should avoid concatenation with prevtok. unsigned ConcatInfo = TokenInfo[PrevKind]; @@ -212,7 +212,7 @@ bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok, // In C++11, a string or character literal followed by an identifier is a // single token. - if (Tok.getIdentifierInfo()) + if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) return true; // A ud-suffix is an identifier. If the previous token ends with one, treat @@ -225,6 +225,9 @@ bool TokenConcatenation::AvoidConcat(const Token &PrevPrevTok, if (Tok.is(tok::numeric_constant)) return GetFirstChar(PP, Tok) != '.'; + if (Tok.isAnnotation()) // token will be put on its own line. + return false; + if (Tok.getIdentifierInfo() || Tok.is(tok::wide_string_literal) || Tok.is(tok::utf8_string_literal) || Tok.is(tok::utf16_string_literal) || Tok.is(tok::utf32_string_literal) || Tok.is(tok::wide_char_constant) || diff --git a/test/Preprocessor/Inputs/a.h b/test/Preprocessor/Inputs/a.h new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/test/Preprocessor/Inputs/a.h @@ -0,0 +1 @@ +// empty diff --git a/test/Preprocessor/Inputs/module.map b/test/Preprocessor/Inputs/module.map new file mode 100644 index 0000000000..a96765705e --- /dev/null +++ b/test/Preprocessor/Inputs/module.map @@ -0,0 +1,4 @@ +module a { + header "a.h" + export * +} diff --git a/test/Preprocessor/annot-tokens.m b/test/Preprocessor/annot-tokens.m new file mode 100644 index 0000000000..c5312ee2ea --- /dev/null +++ b/test/Preprocessor/annot-tokens.m @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -E %s -fmodules -fmodules-cache-path=%t -I%S/Inputs | FileCheck %s +// CHECK: @import a; /* clang -E: implicit import +#include "a.h" +// CHECK: #pragma clang __debug parser_crash +#pragma clang __debug parser_crash -- 2.40.0