Issue |
77125
|
Summary |
clang::html::HighlightMacros() causing ICE? ("Top level include stack isn't our primary lexer?")
|
Labels |
clang
|
Assignees |
|
Reporter |
SergeiYLarin
|
Hi everyone,
I seem to run into ICE with SA html report creation for specific macros: __has_include and __has_include_next(). The issue seems to be the use of isInPrimaryFile() when parsing without Lexer available (invoke Preprocessor::Lex from SA) Here is the relevant part of the call stack:
clang/lib/Lex/PPLexerChange.cpp:41: bool clang::Preprocessor::isInPrimaryFile() const: Assertion `IsFileLexer(IncludeMacroStack[0]) && “Top level include stack isn’t our primary lexer?”’ failed.
#4 0x0 in clang::Preprocessor::isInPrimaryFile (this=0xe6f3dd8) at /repo/llvm/clang/lib/Lex/PPLexerChange.cpp:40
#5 0x0 in clang::Preprocessor::getIncludeNextStart (this=0xe6f3dd8, IncludeNextTok=…) at /repo/llvm/clang/lib/Lex/PPDirectives.cpp:1929
#6 0x0 in clang::Preprocessor::EvaluateHasIncludeNext (this=0xe6f3dd8, Tok=…, II=0xe6f6b48) at /repo/llvm/clang/lib/Lex/PPMacroExpansion.cpp:1285
#7 0x0 in clang::Preprocessor::ExpandBuiltinMacro (this=0xe6f3dd8, Tok=…) at /repo/llvm/clang/lib/Lex/PPMacroExpansion.cpp:1810
#8 0x0 in clang::Preprocessor::HandleMacroExpandedIdentifier (this=0xe6f3dd8, Identifier=…, M=…) at /repo/llvm/clang/lib/Lex/PPMacroExpansion.cpp:503
#9 0x0 in clang::Preprocessor::HandleIdentifier (this=0xe6f3dd8, Identifier=…) at /repo/llvm/clang/lib/Lex/Preprocessor.cpp:825
#10 0x0 in clang::TokenLexer::Lex (this=0xe7d7a10, Tok=…) at /repo/llvm/clang/lib/Lex/TokenLexer.cpp:717
#11 0x0 in clang::Preprocessor::Lex (this=0xe6f3dd8, Result=…) at /repo/llvm/clang/lib/Lex/Preprocessor.cpp:889
#12 0x0 in clang::html::HighlightMacros (R=…, FID=…, PP=…) at /repo/llvm/clang/lib/Rewrite/HTMLRewrite.cpp:696
#13 0x0 in (anonymous namespace)::HTMLDiagnostics::RewriteFile (this=0xe69c9d0, R=…, path=…, FID=…) at /repo/llvm/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:882
The .cpp that reproduces it (for me) is here:
bin/clang -cc1 -analyze -analyzer-checker=core -analyzer-output html foo.cpp
#if 0
#elif 1
#if 0
#if __has_include_next(<stdio.h>)
#endif
#endif
#endif
class class_1 {
private:
void fun_1(char* var_1);
public:
int fun_2();
};
void *memset(void *, int, int) ;
void class_1::fun_1(char* var_1) {
unsigned int i = 0;
for (i = 16; var_1[i] != 0; i++)
var_1[i - 16] = var_1[i];
}
int class_1::fun_2() {
unsigned char var_2[100];
char var_3[300];
fun_1(var_3);
memset(var_2, 0, 100);
return 0;
}
SA warning expected:
clang_sa_warning: The left operand of ‘!=’ is a garbage value [core.UndefinedBinaryOperatorResult]
Any comments on whether Preprocessor::EvaluateHasIncludeNext needs fixing or the top level invocation (html::HighlightMacros) needs adjustment very much appreciated!
Sergei Larin
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs