[PATCH] D131532: [Sema] Avoid isNullPointerConstant invocation
Justin Stitt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 10 17:05:31 PDT 2022
justinstitt updated this revision to Diff 451687.
justinstitt added a comment.
use @rtrieu 's suggestion regarding not invoking isNullPointerConstant as opposed to checking for C++ lang opt.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131532/new/
https://reviews.llvm.org/D131532
Files:
clang/lib/Sema/SemaChecking.cpp
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13339,10 +13339,10 @@
return;
// Check for NULL (GNUNull) or nullptr (CXX11_nullptr).
- const Expr::NullPointerConstantKind NullKind =
- E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull);
- if (NullKind != Expr::NPCK_GNUNull && NullKind != Expr::NPCK_CXX11_nullptr)
- return;
+ const Expr *NewE = E->IgnoreParenImpCasts();
+ bool GNUNull = isa<GNUNullExpr>(NewE);
+ bool NullPtr = NewE->getType()->isNullPtrType();
+ if (!GNUNull && !NullPtr) return;
// Return if target type is a safe conversion.
if (T->isAnyPointerType() || T->isBlockPointerType() ||
@@ -13358,7 +13358,7 @@
CC = S.SourceMgr.getTopMacroCallerLoc(CC);
// __null is usually wrapped in a macro. Go up a macro if that is the case.
- if (NullKind == Expr::NPCK_GNUNull && Loc.isMacroID()) {
+ if (GNUNull && Loc.isMacroID()) {
StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics(
Loc, S.SourceMgr, S.getLangOpts());
if (MacroName == "NULL")
@@ -13370,7 +13370,7 @@
return;
S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
- << (NullKind == Expr::NPCK_CXX11_nullptr) << T << SourceRange(CC)
+ << NullPtr << T << SourceRange(CC)
<< FixItHint::CreateReplacement(Loc,
S.getFixItZeroLiteralForType(T, Loc));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131532.451687.patch
Type: text/x-patch
Size: 1523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220811/aa89bb88/attachment.bin>
More information about the cfe-commits
mailing list