arphaman updated this revision to Diff 405155. arphaman added a reviewer: egorzhdan. arphaman added a comment.
Fix test failure with asserts enabled. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116052/new/ https://reviews.llvm.org/D116052 Files: clang/lib/Frontend/PrintPreprocessedOutput.cpp clang/lib/Lex/Pragma.cpp clang/test/Preprocessor/pragma-missing-string-token.c Index: clang/test/Preprocessor/pragma-missing-string-token.c =================================================================== --- /dev/null +++ clang/test/Preprocessor/pragma-missing-string-token.c @@ -0,0 +1,27 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -emit-module -x c -fmodules -I %t/Inputs -fmodule-name=aa %t/Inputs/module.modulemap -o %t/aa.pcm +// RUN: rm %t/Inputs/b.h +// RUN: not %clang_cc1 -E -fmodules -I %t/Inputs -fmodule-file=%t/aa.pcm %s -o - -fallow-pcm-with-compiler-errors 2>&1 | FileCheck %s + +//--- Inputs/module.modulemap +module aa { + header "a.h" + header "b.h" +} + +//--- Inputs/a.h +#define TEST(x) x + +//--- Inputs/b.h +#define SUB "mypragma" + +//--- test.c +#include "a.h" + +_Pragma(SUB); +int a = TEST(SUB); + +// CHECK: int a +// CHECK: 1 error generated Index: clang/lib/Lex/Pragma.cpp =================================================================== --- clang/lib/Lex/Pragma.cpp +++ clang/lib/Lex/Pragma.cpp @@ -263,7 +263,12 @@ } SourceLocation RParenLoc = Tok.getLocation(); - std::string StrVal = getSpelling(StrTok); + bool Invalid = false; + std::string StrVal = getSpelling(StrTok, &Invalid); + if (Invalid) { + Diag(PragmaLoc, diag::err__Pragma_malformed); + return; + } // The _Pragma is lexically sound. Destringize according to C11 6.10.9.1: // "The string literal is destringized by deleting any encoding prefix, Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp =================================================================== --- clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -189,7 +189,8 @@ bool MoveToLine(const Token &Tok, bool RequireStartOfLine) { PresumedLoc PLoc = SM.getPresumedLoc(Tok.getLocation()); unsigned TargetLine = PLoc.isValid() ? PLoc.getLine() : CurLine; - bool IsFirstInFile = Tok.isAtStartOfLine() && PLoc.getLine() == 1; + bool IsFirstInFile = + Tok.isAtStartOfLine() && PLoc.isValid() && PLoc.getLine() == 1; return MoveToLine(TargetLine, RequireStartOfLine) || IsFirstInFile; }
Index: clang/test/Preprocessor/pragma-missing-string-token.c =================================================================== --- /dev/null +++ clang/test/Preprocessor/pragma-missing-string-token.c @@ -0,0 +1,27 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -emit-module -x c -fmodules -I %t/Inputs -fmodule-name=aa %t/Inputs/module.modulemap -o %t/aa.pcm +// RUN: rm %t/Inputs/b.h +// RUN: not %clang_cc1 -E -fmodules -I %t/Inputs -fmodule-file=%t/aa.pcm %s -o - -fallow-pcm-with-compiler-errors 2>&1 | FileCheck %s + +//--- Inputs/module.modulemap +module aa { + header "a.h" + header "b.h" +} + +//--- Inputs/a.h +#define TEST(x) x + +//--- Inputs/b.h +#define SUB "mypragma" + +//--- test.c +#include "a.h" + +_Pragma(SUB); +int a = TEST(SUB); + +// CHECK: int a +// CHECK: 1 error generated Index: clang/lib/Lex/Pragma.cpp =================================================================== --- clang/lib/Lex/Pragma.cpp +++ clang/lib/Lex/Pragma.cpp @@ -263,7 +263,12 @@ } SourceLocation RParenLoc = Tok.getLocation(); - std::string StrVal = getSpelling(StrTok); + bool Invalid = false; + std::string StrVal = getSpelling(StrTok, &Invalid); + if (Invalid) { + Diag(PragmaLoc, diag::err__Pragma_malformed); + return; + } // The _Pragma is lexically sound. Destringize according to C11 6.10.9.1: // "The string literal is destringized by deleting any encoding prefix, Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp =================================================================== --- clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -189,7 +189,8 @@ bool MoveToLine(const Token &Tok, bool RequireStartOfLine) { PresumedLoc PLoc = SM.getPresumedLoc(Tok.getLocation()); unsigned TargetLine = PLoc.isValid() ? PLoc.getLine() : CurLine; - bool IsFirstInFile = Tok.isAtStartOfLine() && PLoc.getLine() == 1; + bool IsFirstInFile = + Tok.isAtStartOfLine() && PLoc.isValid() && PLoc.getLine() == 1; return MoveToLine(TargetLine, RequireStartOfLine) || IsFirstInFile; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits