Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp =================================================================== --- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -851,7 +851,7 @@ // If this is a function-like macro, skip its arguments, as // getExpandedMacro() already printed them. If this is the case, let's // first jumo to the '(' token. - if (MI->getNumParams() != 0) + if (std::next(It)->is(tok::l_paren)) It = getMatchingRParen(++It, E); continue; } @@ -879,7 +879,15 @@ getMacroNameAndPrintExpansion(Printer, ArgIt->getLocation(), PP, Info.Args, AlreadyProcessedTokens); - if (MI->getNumParams() != 0) + // Peek the next token if it is a tok::l_paren. This way we can decide + // if this is the application or just a reference to a function maxro + // symbol: + // + // #define apply(f) ... + // #define func(x) ... + // apply(func) + // apply(func(42)) + if (std::next(ArgIt)->is(tok::l_paren)) ArgIt = getMatchingRParen(++ArgIt, ArgEnd); } continue; Index: test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist =================================================================== --- test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist +++ test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist @@ -5168,6 +5168,468 @@ file0 + + path + + + kindcontrol + edges + + + start + + + line451 + col33 + file0 + + + line451 + col33 + file0 + + + end + + + line451 + col37 + file0 + + + line451 + col39 + file0 + + + + + + + kindevent + location + + line451 + col37 + file0 + + ranges + + + + line451 + col37 + file0 + + + line451 + col41 + file0 + + + + depth0 + extended_message + Calling 'foo' + message + Calling 'foo' + + + kindevent + location + + line449 + col1 + file0 + + depth1 + extended_message + Entered call from 'useZeroApplier1' + message + Entered call from 'useZeroApplier1' + + + kindevent + location + + line449 + col1 + file0 + + ranges + + + + line449 + col1 + file0 + + + line449 + col16 + file0 + + + + depth1 + extended_message + Returning zero + message + Returning zero + + + kindevent + location + + line451 + col37 + file0 + + ranges + + + + line451 + col37 + file0 + + + line451 + col41 + file0 + + + + depth0 + extended_message + Returning from 'foo' + message + Returning from 'foo' + + + kindcontrol + edges + + + start + + + line451 + col37 + file0 + + + line451 + col39 + file0 + + + end + + + line451 + col35 + file0 + + + line451 + col35 + file0 + + + + + + + kindevent + location + + line451 + col35 + file0 + + ranges + + + + line451 + col33 + file0 + + + line451 + col41 + file0 + + + + depth0 + extended_message + Division by zero + message + Division by zero + + + macro_expansions + + + location + + line449 + col1 + file0 + + nameAPPLY_ZERO1 + expansionint foo() { return x; }(0) + + + descriptionDivision by zero + categoryLogic error + typeDivision by zero + check_namecore.DivideZero + + issue_hash_content_of_line_in_context7ff82561a6c752746649d05220deeb40 + issue_context_kindfunction + issue_contextuseZeroApplier1 + issue_hash_function_offset0 + location + + line451 + col35 + file0 + + + + path + + + kindcontrol + edges + + + start + + + line452 + col33 + file0 + + + line452 + col33 + file0 + + + end + + + line452 + col37 + file0 + + + line452 + col39 + file0 + + + + + + + kindevent + location + + line452 + col37 + file0 + + ranges + + + + line452 + col37 + file0 + + + line452 + col41 + file0 + + + + depth0 + extended_message + Calling 'bar' + message + Calling 'bar' + + + kindevent + location + + line450 + col1 + file0 + + depth1 + extended_message + Entered call from 'useZeroApplier2' + message + Entered call from 'useZeroApplier2' + + + kindevent + location + + line450 + col1 + file0 + + ranges + + + + line450 + col1 + file0 + + + line450 + col11 + file0 + + + + depth1 + extended_message + Returning zero + message + Returning zero + + + kindevent + location + + line452 + col37 + file0 + + ranges + + + + line452 + col37 + file0 + + + line452 + col41 + file0 + + + + depth0 + extended_message + Returning from 'bar' + message + Returning from 'bar' + + + kindcontrol + edges + + + start + + + line452 + col37 + file0 + + + line452 + col39 + file0 + + + end + + + line452 + col35 + file0 + + + line452 + col35 + file0 + + + + + + + kindevent + location + + line452 + col35 + file0 + + ranges + + + + line452 + col33 + file0 + + + line452 + col41 + file0 + + + + depth0 + extended_message + Division by zero + message + Division by zero + + + macro_expansions + + + location + + line450 + col1 + file0 + + nameAPPLY_ZERO2 + expansionint bar() { return 0; } + + + descriptionDivision by zero + categoryLogic error + typeDivision by zero + check_namecore.DivideZero + + issue_hash_content_of_line_in_contextdd82c11b436b00009e37f54b1620a728 + issue_context_kindfunction + issue_contextuseZeroApplier2 + issue_hash_function_offset0 + location + + line452 + col35 + file0 + + Index: test/Analysis/plist-macros-with-expansion.cpp =================================================================== --- test/Analysis/plist-macros-with-expansion.cpp +++ test/Analysis/plist-macros-with-expansion.cpp @@ -441,3 +441,17 @@ } // CHECK: nameYET_ANOTHER_SET_TO_NULL // CHECK-NEXT: expansionprint((void *)5); print((void *)"Remember the Vasa"); ptr = nullptr; + +#define FOO(x) int foo() { return x; } +#define APPLY_ZERO1(function) function(0) +#define BAR(x) int bar() { return x; } +#define APPLY_ZERO2 BAR(0) +APPLY_ZERO1(FOO) +APPLY_ZERO2 +void useZeroApplier1() { (void)(1 / foo()); } // expected-warning{{Division by zero}} +void useZeroApplier2() { (void)(1 / bar()); } // expected-warning{{Division by zero}} + +// CHECK: nameAPPLY_ZERO1 +// CHECK-NEXT: expansionint foo() { return x; }(0) +// CHECK: nameAPPLY_ZERO2 +// CHECK-NEXT: expansionint bar() { return 0; }