r200475 - Fix assertion failures on annot_* tokens in clang -E

Ben Langmuir blangmuir at apple.com
Thu Jan 30 10:09:56 PST 2014


Author: benlangmuir
Date: Thu Jan 30 12:09:55 2014
New Revision: 200475

URL: http://llvm.org/viewvc/llvm-project?rev=200475&view=rev
Log:
Fix assertion failures on annot_* tokens in clang -E

In particular, #pragma clang __debug, and #include implicitly changed
into @import were causing assertion failures.

Added:
    cfe/trunk/test/Preprocessor/Inputs/a.h
    cfe/trunk/test/Preprocessor/Inputs/module.map
    cfe/trunk/test/Preprocessor/annot-tokens.m
Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/lib/Lex/TokenConcatenation.cpp

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=200475&r1=200474&r2=200475&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Thu Jan 30 12:09:55 2014
@@ -342,6 +342,7 @@ void PrintPPOutputPPCallbacks::Inclusion
     OS << "@import " << Imported->getFullModuleName() << ";"
        << " /* clang -E: implicit import for \"" << File->getName() << "\" */";
     EmittedTokensOnThisLine = true;
+    setEmittedDirectiveOnThisLine();
   }
 }
 
@@ -657,11 +658,9 @@ static void PrintPreprocessedTokens(Prep
       // -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()) {

Modified: cfe/trunk/lib/Lex/TokenConcatenation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenConcatenation.cpp?rev=200475&r1=200474&r2=200475&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenConcatenation.cpp (original)
+++ cfe/trunk/lib/Lex/TokenConcatenation.cpp Thu Jan 30 12:09:55 2014
@@ -163,8 +163,8 @@ bool TokenConcatenation::AvoidConcat(con
     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(con
 
     // 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(con
     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) ||

Added: cfe/trunk/test/Preprocessor/Inputs/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/a.h?rev=200475&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/Inputs/a.h (added)
+++ cfe/trunk/test/Preprocessor/Inputs/a.h Thu Jan 30 12:09:55 2014
@@ -0,0 +1 @@
+// empty

Added: cfe/trunk/test/Preprocessor/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/module.map?rev=200475&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/Inputs/module.map (added)
+++ cfe/trunk/test/Preprocessor/Inputs/module.map Thu Jan 30 12:09:55 2014
@@ -0,0 +1,4 @@
+module a {
+  header "a.h"
+  export *
+}

Added: cfe/trunk/test/Preprocessor/annot-tokens.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/annot-tokens.m?rev=200475&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/annot-tokens.m (added)
+++ cfe/trunk/test/Preprocessor/annot-tokens.m Thu Jan 30 12:09:55 2014
@@ -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





More information about the cfe-commits mailing list