[analyzer][PlistMacroExpansion] Part 5.: Support for # and ##
From what I can see, this should be the last patch needed to replicate macro
argument expansions.
Differential Revision: https://reviews.llvm.org/D52988
llvm-svn: 348025
diff --git a/clang/test/Analysis/plist-macros-with-expansion.cpp b/clang/test/Analysis/plist-macros-with-expansion.cpp
index 6bbaf3d..14dccd0 100644
--- a/clang/test/Analysis/plist-macros-with-expansion.cpp
+++ b/clang/test/Analysis/plist-macros-with-expansion.cpp
@@ -345,9 +345,17 @@
*ptr = 5; // expected-warning{{Dereference of null pointer}}
}
-// TODO: Should expand correctly.
// CHECK: <key>name</key><string>DECLARE_FUNC_AND_SET_TO_NULL</string>
-// CHECK-NEXT: <key>expansion</key><string>void generated_##whatever(); ptr = nullptr;</string>
+// CHECK-NEXT: <key>expansion</key><string>void generated_whatever(); ptr = nullptr;</string>
+
+void macroArgContainsHashHashInStringTest() {
+ int *a;
+ TO_NULL_AND_PRINT(a, "Will this ## cause a crash?");
+ *a = 5; // expected-warning{{Dereference of null pointer}}
+}
+
+// CHECK: <key>name</key><string>TO_NULL_AND_PRINT</string>
+// CHECK-NEXT: <key>expansion</key><string>a = 0; print( "Will this ## cause a crash?")</string>
#define PRINT_STR(str, ptr) \
print(#str); \
@@ -359,9 +367,17 @@
*ptr = 5; // expected-warning{{Dereference of null pointer}}
}
-// TODO: Should expand correctly.
// CHECK: <key>name</key><string>PRINT_STR</string>
-// CHECK-NEXT: <key>expansion</key><string>print(#Hello); ptr = nullptr</string>
+// CHECK-NEXT: <key>expansion</key><string>print("Hello"); ptr = nullptr</string>
+
+void macroArgContainsHashInStringTest() {
+ int *a;
+ TO_NULL_AND_PRINT(a, "Will this # cause a crash?");
+ *a = 5; // expected-warning{{Dereference of null pointer}}
+}
+
+// CHECK: <key>name</key><string>TO_NULL_AND_PRINT</string>
+// CHECK-NEXT: <key>expansion</key><string>a = 0; print( "Will this # cause a crash?")</string>
//===----------------------------------------------------------------------===//
// Tests for more complex macro expansions.