r257240 - Only take NULL macros instead of all macros into account for -Wnull-conversion.
Richard Trieu via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 8 17:10:18 PST 2016
Author: rtrieu
Date: Fri Jan 8 19:10:17 2016
New Revision: 257240
URL: http://llvm.org/viewvc/llvm-project?rev=257240&view=rev
Log:
Only take NULL macros instead of all macros into account for -Wnull-conversion.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/conversion.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=257240&r1=257239&r2=257240&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Jan 8 19:10:17 2016
@@ -7066,8 +7066,12 @@ static void DiagnoseNullConversion(Sema
// __null is usually wrapped in a macro. Go up a macro if that is the case.
if (NullKind == Expr::NPCK_GNUNull) {
- if (Loc.isMacroID())
- Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
+ if (Loc.isMacroID()) {
+ StringRef MacroName =
+ Lexer::getImmediateMacroName(Loc, S.SourceMgr, S.getLangOpts());
+ if (MacroName == "NULL")
+ Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
+ }
}
// Only warn if the null and context location are in the same macro expansion.
Modified: cfe/trunk/test/SemaCXX/conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion.cpp?rev=257240&r1=257239&r2=257240&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/conversion.cpp Fri Jan 8 19:10:17 2016
@@ -208,3 +208,23 @@ namespace test9 {
return EXIT();
}
}
+
+// Test NULL macro inside a macro has same warnings nullptr inside a macro.
+namespace test10 {
+#define test1(cond) \
+ ((cond) ? nullptr : NULL)
+#define test2(cond) \
+ ((cond) ? NULL : nullptr)
+
+#define assert(cond) \
+ ((cond) ? foo() : bar())
+ void foo();
+ void bar();
+
+ void run(int x) {
+ if (test1(x)) {}
+ if (test2(x)) {}
+ assert(test1(x));
+ assert(test2(x));
+ }
+}
More information about the cfe-commits
mailing list