Closed llvmbot closed 11 years ago
r168984.
That seems fine to me. I assume that means that the LHS range has one end pointing into the macro arg expansion and the other pointing into the macro expansion?
Yes, thinko, your highlighting looks right to me (what I proposed is closer to how we'd highlight if the caret pointed within the range).
That seems fine to me. I assume that means that the LHS range has one end pointing into the macro arg expansion and the other pointing into the macro expansion?
Another example:
I tried implementing your approach, and I'm getting the following:
How about we start by 'normalizing' each range into something we can highlight: find the lowest common ancestor FileID (by taking immediate expansion ranges only) of the beginning and end of each range, and use that. Then, since we must still have begin <= end, and we now have the same FileID for begin and end, we must have a contiguous range at every level in which we can highlight the range.
For the original example and for the example in comment#1, for the LHS range, we would step out of the macro argument expansion and into the macro expansion for BARC, highlighting the "a+b+c" expression. For the RHS range, we would keep the current range (contained entirely within the macro arg expansion for __VA_ARGS__).
That'd give something like this for the example in comment#0:
bar.c:4:20: warning: expression result unused [-Wunused-value]
iequals(LINE, BARC(4,3,2,6,8), 8);
^~~~~~~
Richard, do you have any ideas here? I have no clue how to solve this short of ripping out the whole getImmediateMacroCallerLoc/getImmediateMacroCalleeLoc concept; fundamentally, if we step into of a macro argument with getImmediateSpellingLoc(), we immediately lose track of the original macro argument expansion.
You can see more clearly what's happening with the following valid testcase:
void iequals(int,int,int); void foo_aa() {
iequals(__LINE__, BARC(4,3,2,6,8), 8);
}
Extended Description
Typescript for reproducing the problem:
$ cat bar.c void foo_aa() {
define / / BARC(c, / /b, a, ...) (a+b+/ /c + __VA_ARGS__ +0)
} $ clang -c bar.c -emit-llvm bar.c:4:2: warning: implicit declaration of function 'iequals' is invalid in C99 [-Wimplicit-function-declaration] iequals(LINE, BARC(4,3,2,6,8), 8); ^ bar.c:4:20: warning: expression result unused [-Wunused-value] clang: /scratch/bb-slaves/mipssw005/LLVM_optimize_install/source/tools/clang/lib/Frontend/TextDiagnostic.cpp:1086: void clang::TextDiagnostic::highlightRange(const clang::CharSourceRange&, unsigned int, clang::FileID, const SourceColumnMap&, std::string&, const clang::SourceManager&): Assertion `StartColNo <= EndColNo && "Invalid range!"' failed. 0 clang 0x00000000020b701f 1 clang 0x00000000020b8f9a 2 libpthread.so.0 0x00007f8dd46a88f0 3 libc.so.6 0x00007f8dd3997a75 gsignal + 53 4 libc.so.6 0x00007f8dd399b5c0 abort + 384 5 libc.so.6 0x00007f8dd3990941 assert_fail + 241 6 clang 0x000000000071c774 clang::TextDiagnostic::highlightRange(clang::CharSourceRange const&, unsigned int, clang::FileID, SourceColumnMap const&, std::string&, clang::SourceManager const&) + 1748 7 clang 0x000000000071daea clang::TextDiagnostic::emitSnippetAndCaret(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::SmallVectorImpl&, llvm::ArrayRef, clang::SourceManager const&) + 2394
8 clang 0x0000000000712893 clang::DiagnosticRenderer::emitMacroExpansionsAndCarets(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::SmallVectorImpl&, llvm::ArrayRef, clang::SourceManager const&, unsigned int&, unsigned int) + 211
9 clang 0x0000000000712ee6 clang::DiagnosticRenderer::emitMacroExpansionsAndCarets(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::SmallVectorImpl&, llvm::ArrayRef, clang::SourceManager const&, unsigned int&, unsigned int) + 1830
10 clang 0x0000000000713637 clang::DiagnosticRenderer::emitDiagnostic(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRef, llvm::ArrayRef, clang::SourceManager const, llvm::PointerUnion<clang::Diagnostic const, clang::StoredDiagnostic const>) + 983
11 clang 0x00000000006dba51 clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) + 561
12 clang 0x00000000013da8a4 clang::DiagnosticIDs::EmitDiag(clang::DiagnosticsEngine&, clang::DiagnosticIDs::Level) const + 52
13 clang 0x00000000013dcbde clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const + 462
14 clang 0x00000000013d64e4 clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) + 36
15 clang 0x0000000000a3e99e clang::Sema::EmitCurrentDiagnostic(unsigned int) + 862
16 clang 0x0000000000a4700f
17 clang 0x0000000000b67d0d clang::Sema::DiagRuntimeBehavior(clang::SourceLocation, clang::Stmt const, clang::PartialDiagnostic const&) + 1565
18 clang 0x0000000000c789e8 clang::Sema::DiagnoseUnusedExprResult(clang::Stmt const) + 456
19 clang 0x0000000000b8aafe clang::Sema::CreateBuiltinBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr, clang::Expr) + 2862
20 clang 0x0000000000b8aed3 clang::Sema::BuildBinOp(clang::Scope, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr, clang::Expr) + 259
21 clang 0x0000000000b8b286 clang::Sema::ActOnBinOp(clang::Scope, clang::SourceLocation, clang::tok::TokenKind, clang::Expr, clang::Expr) + 278
22 clang 0x00000000009e7dc0 clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr, true>, clang::prec::Level) + 2400
23 clang 0x00000000009e9349 clang::Parser::ParseExpression(clang::Parser::TypeCastState) + 25
24 clang 0x00000000009ebaa4 clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr&, clang::SourceLocation&) + 2500
25 clang 0x00000000009e5f3a clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) + 698
26 clang 0x00000000009e73dd clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState) + 29
27 clang 0x00000000009e8def clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 31
28 clang 0x00000000009e8ec2 clang::Parser::ParseExpressionList(llvm::SmallVectorImpl<clang::Expr>&, llvm::SmallVectorImpl&, void (clang::Sema:: )(clang::Scope, clang::Expr, llvm::ArrayRef<clang::Expr>), clang::Expr) + 130
29 clang 0x00000000009e96ba clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr, true>) + 874
30 clang 0x00000000009e5d78 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState) + 248
31 clang 0x00000000009e73dd clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState) + 29
32 clang 0x00000000009e8def clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 31
33 clang 0x00000000009e9339 clang::Parser::ParseExpression(clang::Parser::TypeCastState) + 9
34 clang 0x0000000000a191e8 clang::Parser::ParseExprStatement() + 72
35 clang 0x0000000000a14605 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt, 32u>&, bool, clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&) + 1909
36 clang 0x0000000000a1479e clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt, 32u>&, bool, clang::SourceLocation) + 142
37 clang 0x0000000000a15801 clang::Parser::ParseCompoundStatementBody(bool) + 1841
38 clang 0x0000000000a15e6a clang::Parser::ParseFunctionStatementBody(clang::Decl, clang::Parser::ParseScope&) + 154
39 clang 0x00000000009b9aa9 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList) + 2617
40 clang 0x00000000009cc64d clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, bool, clang::SourceLocation, clang::Parser::ForRangeInit) + 3085
41 clang 0x00000000009b5099 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 249
42 clang 0x00000000009b56c4 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec, clang::AccessSpecifier) + 804
43 clang 0x00000000009b70ba clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec) + 1674
44 clang 0x00000000009b7652 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&) + 194
45 clang 0x00000000009ae548 clang::ParseAST(clang::Sema&, bool, bool) + 296
46 clang 0x00000000008336fe clang::CodeGenAction::ExecuteAction() + 78
47 clang 0x00000000006ba8b9 clang::FrontendAction::Execute() + 185
48 clang 0x0000000000697655 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 341
49 clang 0x000000000067f20c clang::ExecuteCompilerInvocation(clang::CompilerInstance ) + 1708
50 clang 0x00000000006767b8 cc1_main(char const, char const, char const, void) + 1240
51 clang 0x000000000067d847 main + 7431
52 libc.so.6 0x00007f8dd3982c4d libc_start_main + 253
53 clang 0x0000000000675749
Stack dump:
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/bar-3QBo5S.c clang: note: diagnostic msg: /tmp/bar-3QBo5S.sh clang: note: diagnostic msg:
$