Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp =================================================================== --- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -853,15 +853,24 @@ // we will find tok::l_paren, tok::r_paren, and tok::comma that do not divide // actual macro arguments, or do not represent the macro argument's closing // parantheses, so we'll count how many parantheses aren't closed yet. + // If ParanthesesDepth + // * = 0, then there are no more arguments to lex. + // * = 1, then if we find a tok::comma, we can start lexing the next arg. + // * > 1, then tok::comma is a part of the current arg. int ParanthesesDepth = 1; - for (unsigned Index = 0; Index < MI->getNumParams(); ++Index) { + // If we encounter __VA_ARGS__, we will lex until the closing tok::r_paren, + // even if we lex a tok::comma and ParanthesesDepth == 1. + const IdentifierInfo *__VA_ARGS__II = PP.getIdentifierInfo("__VA_ARGS__"); + + for (const IdentifierInfo *UnexpArgII : MacroArgs) { MacroArgMap::mapped_type ExpandedArgTokens; // Lex the first token of the next macro parameter. RawLexer.LexFromRawLexer(TheTok); - while (TheTok.isNot(tok::comma) || ParanthesesDepth != 1) { + while (!(ParanthesesDepth == 1 && + (UnexpArgII == __VA_ARGS__II ? false : TheTok.is(tok::comma)))) { assert(TheTok.isNot(tok::eof) && "EOF encountered while looking for expanded macro args!"); @@ -881,12 +890,10 @@ RawLexer.LexFromRawLexer(TheTok); } - Args.insert(std::make_pair(MacroArgs[Index], ExpandedArgTokens)); + Args.insert(std::make_pair(UnexpArgII, ExpandedArgTokens)); } - // TODO: The condition really should be TheTok.is(tok::r_paren), but variadic - // macro arguments are not handled yet. - assert(TheTok.isOneOf(tok::r_paren, tok::comma) && + assert(TheTok.is(tok::r_paren) && "Expanded macro argument acquisition failed! After the end of the loop" " this token should be ')'!"); 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 @@ -3,7 +3,7 @@ clang_version -clang version 8.0.0 (http://mainstream.inf.elte.hu/Szelethus/clang 650e3f54f6a63798143c7181035a285f03dccb7f) (https://github.com/llvm-mirror/llvm 1ffbf26a1a0a190d69327af875a3337b74a2ce82) +clang version 8.0.0 (http://mainstream.inf.elte.hu/Szelethus/clang 531e9e44e37061619212a542a5d1076525fdbea9) (https://github.com/llvm-mirror/llvm 1ffbf26a1a0a190d69327af875a3337b74a2ce82) diagnostics @@ -3590,7 +3590,7 @@ file0 nameVARIADIC_SET_TO_NULL - expansionptr = nullptr ; variadicFunc ( 1 ) + expansionptr = nullptr ; variadicFunc ( 1 , 5 , "haha!" ) kindevent @@ -3722,12 +3722,12 @@ start - line277 + line276 col3 file0 - line277 + line276 col5 file0 @@ -3735,12 +3735,12 @@ end - line278 + line277 col3 file0 - line278 + line277 col30 file0 @@ -3752,7 +3752,7 @@ kindmacro_expansion location - line278 + line277 col3 file0 @@ -3763,7 +3763,7 @@ kindevent location - line278 + line277 col3 file0 @@ -3771,12 +3771,12 @@ - line278 + line277 col3 file0 - line278 + line277 col45 file0 @@ -3796,12 +3796,12 @@ start - line279 + line278 col3 file0 - line279 + line278 col3 file0 @@ -3809,12 +3809,12 @@ end - line279 + line278 col8 file0 - line279 + line278 col8 file0 @@ -3826,7 +3826,7 @@ kindevent location - line279 + line278 col8 file0 @@ -3834,12 +3834,12 @@ - line279 + line278 col4 file0 - line279 + line278 col6 file0 @@ -3863,7 +3863,7 @@ issue_hash_function_offset3 location - line279 + line278 col8 file0 @@ -3871,10 +3871,10 @@ 0 + 275 276 277 278 - 279 @@ -3889,12 +3889,12 @@ start - line291 + line290 col3 file0 - line291 + line290 col5 file0 @@ -3902,12 +3902,12 @@ end - line292 + line291 col3 file0 - line292 + line291 col11 file0 @@ -3919,7 +3919,7 @@ kindmacro_expansion location - line292 + line291 col3 file0 @@ -3930,7 +3930,7 @@ kindevent location - line292 + line291 col3 file0 @@ -3938,12 +3938,12 @@ - line292 + line291 col3 file0 - line292 + line291 col23 file0 @@ -3963,12 +3963,12 @@ start - line293 + line292 col3 file0 - line293 + line292 col3 file0 @@ -3976,12 +3976,12 @@ end - line293 + line292 col8 file0 - line293 + line292 col8 file0 @@ -3993,7 +3993,7 @@ kindevent location - line293 + line292 col8 file0 @@ -4001,12 +4001,12 @@ - line293 + line292 col4 file0 - line293 + line292 col6 file0 @@ -4030,7 +4030,7 @@ issue_hash_function_offset3 location - line293 + line292 col8 file0 @@ -4038,10 +4038,10 @@ 0 + 289 290 291 292 - 293 Index: test/Analysis/plist-macros-with-expansion.cpp =================================================================== --- test/Analysis/plist-macros-with-expansion.cpp +++ test/Analysis/plist-macros-with-expansion.cpp @@ -261,9 +261,8 @@ *ptr = 5; // expected-warning{{Dereference of null pointer}} } -// TODO: Should correctly display the rest of the parameters. // CHECK: nameVARIADIC_SET_TO_NULL -// CHECK: expansionptr = nullptr ; variadicFunc ( 1 ) +// CHECK: expansionptr = nullptr ; variadicFunc ( 1 , 5 , "haha!" ) //===----------------------------------------------------------------------===// // Tests for # and ##.