SourceLocation StartLoc = FirstCast->getLocStart();
SourceLocation EndLoc = FirstCast->getLocEnd();
+ // If the start/end location is a macro, get the expansion location.
+ StartLoc = SM.getFileLoc(StartLoc);
+ EndLoc = SM.getFileLoc(EndLoc);
+
if (SM.getFileID(StartLoc) == SM.getFileID(EndLoc) &&
SM.isFromMainFile(StartLoc) && SM.isFromMainFile(EndLoc)) {
CharSourceRange Range(SourceRange(StartLoc, EndLoc), true);
if (SM.getFileID(StartLoc) != SM.getFileID(EndLoc))
return;
- if (StartLoc.isMacroID())
- StartLoc = SM.getExpansionLoc(StartLoc);
- if (EndLoc.isMacroID())
- EndLoc = SM.getExpansionLoc(EndLoc);
+ // If the start/end location is a macro, get the expansion location.
+ StartLoc = SM.getFileLoc(StartLoc);
+ EndLoc = SM.getFileLoc(EndLoc);
if (!SM.isFromMainFile(StartLoc) || !SM.isFromMainFile(EndLoc))
return;
return g_null;
// CHECK: return g_null;
}
+
+// Test function-like macros where the parameter to the macro (expression)
+// results in a nullptr.
+void __dummy_assert_fail() {}
+
+void test_function_like_macro1() {
+ // This tests that the CastSequenceVisitor is working properly.
+#define my_assert(expr) \
+ ((expr) ? static_cast<void>(expr) : __dummy_assert_fail())
+
+ int *p;
+ my_assert(p != 0);
+ // CHECK: my_assert(p != nullptr);
+#undef my_assert
+}
+
+void test_function_like_macro2() {
+ // This tests that the implicit cast is working properly.
+#define my_macro(expr) \
+ (expr)
+
+ int *p;
+ my_macro(p != 0);
+ // CHECK: my_macro(p != nullptr);
+#undef my_macro
+}