Index: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -904,8 +904,6 @@
continue;
}
- // TODO: Handle tok::hash and tok::hashhash.
-
// If control reached here, then this token isn't a macro identifier, nor an
// unexpanded macro argument that we need to handle, print it.
Printer.printToken(T);
@@ -1094,14 +1092,25 @@
}
void TokenPrinter::printToken(const Token &Tok) {
- // If the tokens were already space separated, or if they must be to avoid
- // them being implicitly pasted, add a space between them.
// If this is the first token to be printed, don't print space.
- if (PrevTok.isNot(tok::unknown) && (Tok.hasLeadingSpace() ||
- ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok)))
- OS << ' ';
+ if (PrevTok.isNot(tok::unknown)) {
+ // If the tokens were already space separated, or if they must be to avoid
+ // them being implicitly pasted, add a space between them.
+ if(Tok.hasLeadingSpace() || ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok,
+ Tok)) {
+ // AvoidConcat doesn't check for ##, don't print a space around it.
+ if (PrevTok.isNot(tok::hashhash) && Tok.isNot(tok::hashhash)) {
+ OS << ' ';
+ }
+ }
+ }
- OS << PP.getSpelling(Tok);
+ if (!Tok.isOneOf(tok::hash, tok::hashhash)) {
+ if (PrevTok.is(tok::hash))
+ OS << '\"' << PP.getSpelling(Tok) << '\"';
+ else
+ OS << PP.getSpelling(Tok);
+ }
PrevPrevTok = PrevTok;
PrevTok = Tok;
Index: cfe/trunk/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
===================================================================
--- cfe/trunk/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ cfe/trunk/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -4555,7 +4555,7 @@
file0
nameDECLARE_FUNC_AND_SET_TO_NULL
- expansionvoid generated_##whatever(); ptr = nullptr;
+ expansionvoid generated_whatever(); ptr = nullptr;
descriptionDereference of null pointer (loaded from variable 'ptr')
@@ -4595,12 +4595,12 @@
start
- line357
+ line352
col3
file0
- line357
+ line352
col5
file0
@@ -4608,12 +4608,181 @@
end
- line358
+ line353
col3
file0
- line358
+ line353
+ col19
+ file0
+
+
+
+
+
+
+ kindevent
+ location
+
+ line353
+ col3
+ file0
+
+ ranges
+
+
+
+ line353
+ col3
+ file0
+
+
+ line353
+ col53
+ file0
+
+
+
+ depth0
+ extended_message
+ Null pointer value stored to 'a'
+ message
+ Null pointer value stored to 'a'
+
+
+ kindcontrol
+ edges
+
+
+ start
+
+
+ line354
+ col3
+ file0
+
+
+ line354
+ col3
+ file0
+
+
+ end
+
+
+ line354
+ col6
+ file0
+
+
+ line354
+ col6
+ file0
+
+
+
+
+
+
+ kindevent
+ location
+
+ line354
+ col6
+ file0
+
+ ranges
+
+
+
+ line354
+ col4
+ file0
+
+
+ line354
+ col4
+ file0
+
+
+
+ depth0
+ extended_message
+ Dereference of null pointer (loaded from variable 'a')
+ message
+ Dereference of null pointer (loaded from variable 'a')
+
+
+ macro_expansions
+
+
+ location
+
+ line353
+ col3
+ file0
+
+ nameTO_NULL_AND_PRINT
+ expansiona = 0; print( "Will this ## cause a crash?")
+
+
+ descriptionDereference of null pointer (loaded from variable 'a')
+ categoryLogic error
+ typeDereference of null pointer
+ check_namecore.NullDereference
+
+ issue_hash_content_of_line_in_context6817572ced27cb7d28fc87b2aba75fb4
+ issue_context_kindfunction
+ issue_contextmacroArgContainsHashHashInStringTest
+ issue_hash_function_offset3
+ location
+
+ line354
+ col6
+ file0
+
+ ExecutedLines
+
+ 0
+
+ 351
+ 352
+ 353
+ 354
+
+
+
+
+ path
+
+
+ kindcontrol
+ edges
+
+
+ start
+
+
+ line365
+ col3
+ file0
+
+
+ line365
+ col5
+ file0
+
+
+ end
+
+
+ line366
+ col3
+ file0
+
+
+ line366
col11
file0
@@ -4625,7 +4794,7 @@
kindevent
location
- line358
+ line366
col3
file0
@@ -4633,12 +4802,12 @@
- line358
+ line366
col3
file0
- line358
+ line366
col23
file0
@@ -4658,12 +4827,12 @@
start
- line359
+ line367
col3
file0
- line359
+ line367
col3
file0
@@ -4671,12 +4840,12 @@
end
- line359
+ line367
col8
file0
- line359
+ line367
col8
file0
@@ -4688,7 +4857,7 @@
kindevent
location
- line359
+ line367
col8
file0
@@ -4696,12 +4865,12 @@
- line359
+ line367
col4
file0
- line359
+ line367
col6
file0
@@ -4719,12 +4888,12 @@
location
- line358
+ line366
col3
file0
namePRINT_STR
- expansionprint(#Hello); ptr = nullptr
+ expansionprint("Hello"); ptr = nullptr
descriptionDereference of null pointer (loaded from variable 'ptr')
@@ -4738,7 +4907,7 @@
issue_hash_function_offset3
location
- line359
+ line367
col8
file0
@@ -4746,10 +4915,179 @@
0
- 356
- 357
- 358
- 359
+ 364
+ 365
+ 366
+ 367
+
+
+
+
+ path
+
+
+ kindcontrol
+ edges
+
+
+ start
+
+
+ line374
+ col3
+ file0
+
+
+ line374
+ col5
+ file0
+
+
+ end
+
+
+ line375
+ col3
+ file0
+
+
+ line375
+ col19
+ file0
+
+
+
+
+
+
+ kindevent
+ location
+
+ line375
+ col3
+ file0
+
+ ranges
+
+
+
+ line375
+ col3
+ file0
+
+
+ line375
+ col52
+ file0
+
+
+
+ depth0
+ extended_message
+ Null pointer value stored to 'a'
+ message
+ Null pointer value stored to 'a'
+
+
+ kindcontrol
+ edges
+
+
+ start
+
+
+ line376
+ col3
+ file0
+
+
+ line376
+ col3
+ file0
+
+
+ end
+
+
+ line376
+ col6
+ file0
+
+
+ line376
+ col6
+ file0
+
+
+
+
+
+
+ kindevent
+ location
+
+ line376
+ col6
+ file0
+
+ ranges
+
+
+
+ line376
+ col4
+ file0
+
+
+ line376
+ col4
+ file0
+
+
+
+ depth0
+ extended_message
+ Dereference of null pointer (loaded from variable 'a')
+ message
+ Dereference of null pointer (loaded from variable 'a')
+
+
+ macro_expansions
+
+
+ location
+
+ line375
+ col3
+ file0
+
+ nameTO_NULL_AND_PRINT
+ expansiona = 0; print( "Will this # cause a crash?")
+
+
+ descriptionDereference of null pointer (loaded from variable 'a')
+ categoryLogic error
+ typeDereference of null pointer
+ check_namecore.NullDereference
+
+ issue_hash_content_of_line_in_contextb1da2db423e721067ed5cfda858890be
+ issue_context_kindfunction
+ issue_contextmacroArgContainsHashInStringTest
+ issue_hash_function_offset3
+ location
+
+ line376
+ col6
+ file0
+
+ ExecutedLines
+
+ 0
+
+ 373
+ 374
+ 375
+ 376
@@ -4764,12 +5102,12 @@
start
- line406
+ line422
col3
file0
- line406
+ line422
col5
file0
@@ -4777,12 +5115,12 @@
end
- line406
+ line422
col18
file0
- line406
+ line422
col43
file0
@@ -4794,7 +5132,7 @@
kindevent
location
- line406
+ line422
col18
file0
@@ -4802,12 +5140,12 @@
- line406
+ line422
col18
file0
- line406
+ line422
col49
file0
@@ -4823,7 +5161,7 @@
kindevent
location
- line401
+ line417
col1
file0
@@ -4841,12 +5179,12 @@
start
- line401
+ line417
col1
file0
- line401
+ line417
col3
file0
@@ -4854,12 +5192,12 @@
end
- line402
+ line418
col3
file0
- line402
+ line418
col21
file0
@@ -4871,7 +5209,7 @@
kindevent
location
- line402
+ line418
col3
file0
@@ -4879,12 +5217,12 @@
- line402
+ line418
col3
file0
- line402
+ line418
col27
file0
@@ -4902,7 +5240,7 @@
location
- line402
+ line418
col3
file0
@@ -4921,7 +5259,7 @@
issue_hash_function_offset1
location
- line402
+ line418
col3
file0
@@ -4929,10 +5267,10 @@
0
- 401
- 402
- 405
- 406
+ 417
+ 418
+ 421
+ 422
@@ -4947,12 +5285,12 @@
start
- line421
+ line437
col3
file0
- line421
+ line437
col5
file0
@@ -4960,12 +5298,12 @@
end
- line422
+ line438
col3
file0
- line422
+ line438
col25
file0
@@ -4977,7 +5315,7 @@
kindevent
location
- line422
+ line438
col3
file0
@@ -4985,12 +5323,12 @@
- line422
+ line438
col3
file0
- line422
+ line438
col67
file0
@@ -5010,12 +5348,12 @@
start
- line423
+ line439
col3
file0
- line423
+ line439
col3
file0
@@ -5023,12 +5361,12 @@
end
- line423
+ line439
col8
file0
- line423
+ line439
col8
file0
@@ -5040,7 +5378,7 @@
kindevent
location
- line423
+ line439
col8
file0
@@ -5048,12 +5386,12 @@
- line423
+ line439
col4
file0
- line423
+ line439
col6
file0
@@ -5071,7 +5409,7 @@
location
- line422
+ line438
col3
file0
@@ -5090,7 +5428,7 @@
issue_hash_function_offset3
location
- line423
+ line439
col8
file0
@@ -5098,17 +5436,17 @@
0
- 420
- 421
- 422
- 423
+ 436
+ 437
+ 438
+ 439
files
- /home/eumakri/Documents/macro_expansion/clang/test/Analysis/plist-macros-with-expansion.cpp
+ /home/szelethus/Documents/macro_expansion/clang/test/Analysis/plist-macros-with-expansion.cpp
Index: cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp
===================================================================
--- cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp
+++ cfe/trunk/test/Analysis/plist-macros-with-expansion.cpp
@@ -345,9 +345,17 @@
*ptr = 5; // expected-warning{{Dereference of null pointer}}
}
-// TODO: Should expand correctly.
// CHECK: nameDECLARE_FUNC_AND_SET_TO_NULL
-// CHECK-NEXT: expansionvoid generated_##whatever(); ptr = nullptr;
+// CHECK-NEXT: expansionvoid generated_whatever(); ptr = nullptr;
+
+void macroArgContainsHashHashInStringTest() {
+ int *a;
+ TO_NULL_AND_PRINT(a, "Will this ## cause a crash?");
+ *a = 5; // expected-warning{{Dereference of null pointer}}
+}
+
+// CHECK: nameTO_NULL_AND_PRINT
+// CHECK-NEXT: expansiona = 0; print( "Will this ## cause a crash?")
#define PRINT_STR(str, ptr) \
print(#str); \
@@ -359,9 +367,17 @@
*ptr = 5; // expected-warning{{Dereference of null pointer}}
}
-// TODO: Should expand correctly.
// CHECK: namePRINT_STR
-// CHECK-NEXT: expansionprint(#Hello); ptr = nullptr
+// CHECK-NEXT: expansionprint("Hello"); ptr = nullptr
+
+void macroArgContainsHashInStringTest() {
+ int *a;
+ TO_NULL_AND_PRINT(a, "Will this # cause a crash?");
+ *a = 5; // expected-warning{{Dereference of null pointer}}
+}
+
+// CHECK: nameTO_NULL_AND_PRINT
+// CHECK-NEXT: expansiona = 0; print( "Will this # cause a crash?")
//===----------------------------------------------------------------------===//
// Tests for more complex macro expansions.