Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===================================================================
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -873,15 +873,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;
+ // 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!");
@@ -904,9 +913,7 @@
Args.emplace(UnexpArgII, std::move(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
@@ -3588,7 +3588,7 @@
file0
nameVARIADIC_SET_TO_NULL
- expansionptr = nullptr; variadicFunc( 1)
+ expansionptr = nullptr; variadicFunc( 1, 5, "haha!")
kindevent
@@ -3720,12 +3720,12 @@
start
- line277
+ line276
col3
file0
- line277
+ line276
col5
file0
@@ -3733,12 +3733,12 @@
end
- line278
+ line277
col3
file0
- line278
+ line277
col30
file0
@@ -3750,7 +3750,7 @@
kindmacro_expansion
location
- line278
+ line277
col3
file0
@@ -3761,7 +3761,7 @@
kindevent
location
- line278
+ line277
col3
file0
@@ -3769,12 +3769,12 @@
- line278
+ line277
col3
file0
- line278
+ line277
col45
file0
@@ -3794,12 +3794,12 @@
start
- line279
+ line278
col3
file0
- line279
+ line278
col3
file0
@@ -3807,12 +3807,12 @@
end
- line279
+ line278
col8
file0
- line279
+ line278
col8
file0
@@ -3824,7 +3824,7 @@
kindevent
location
- line279
+ line278
col8
file0
@@ -3832,12 +3832,12 @@
- line279
+ line278
col4
file0
- line279
+ line278
col6
file0
@@ -3861,7 +3861,7 @@
issue_hash_function_offset3
location
- line279
+ line278
col8
file0
@@ -3869,10 +3869,10 @@
0
+ 275
276
277
278
- 279
@@ -3887,12 +3887,12 @@
start
- line291
+ line290
col3
file0
- line291
+ line290
col5
file0
@@ -3900,12 +3900,12 @@
end
- line292
+ line291
col3
file0
- line292
+ line291
col11
file0
@@ -3917,7 +3917,7 @@
kindmacro_expansion
location
- line292
+ line291
col3
file0
@@ -3928,7 +3928,7 @@
kindevent
location
- line292
+ line291
col3
file0
@@ -3936,12 +3936,12 @@
- line292
+ line291
col3
file0
- line292
+ line291
col23
file0
@@ -3961,12 +3961,12 @@
start
- line293
+ line292
col3
file0
- line293
+ line292
col3
file0
@@ -3974,12 +3974,12 @@
end
- line293
+ line292
col8
file0
- line293
+ line292
col8
file0
@@ -3991,7 +3991,7 @@
kindevent
location
- line293
+ line292
col8
file0
@@ -3999,12 +3999,12 @@
- line293
+ line292
col4
file0
- line293
+ line292
col6
file0
@@ -4028,7 +4028,7 @@
issue_hash_function_offset3
location
- line293
+ line292
col8
file0
@@ -4036,10 +4036,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 ##.