]> granicus.if.org Git - clang/commitdiff
Introduce Sema::isNullExpr() that contains the checks that
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 23 Jan 2012 20:38:53 +0000 (20:38 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 23 Jan 2012 20:38:53 +0000 (20:38 +0000)
Sema::DiagnoseSentinelCalls() does.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148722 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaExpr.cpp

index 2055f3bf6ac17a8cdde5fe87b8253452cc426003..754b2906b3ef3ebdafd4b8768ed5aaedb300b0db 100644 (file)
@@ -1375,6 +1375,7 @@ public:
                                  QualType &ConvertedType);
   bool IsBlockPointerConversion(QualType FromType, QualType ToType,
                                 QualType& ConvertedType);
+  bool isNullExpr(const Expr *E) const;
   bool FunctionArgTypesAreEqual(const FunctionProtoType *OldType,
                                 const FunctionProtoType *NewType,
                                 unsigned *ArgPos = 0);
index 96496662503c33437e10db34b0c157b6927e1f5d..8d263b3b66242a2895f3e6a55a7e03dc2b7c70c9 100644 (file)
@@ -249,17 +249,7 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc,
   Expr *sentinelExpr = args[numArgs - numArgsAfterSentinel - 1];
   if (!sentinelExpr) return;
   if (sentinelExpr->isValueDependent()) return;
-
-  // nullptr_t is always treated as null.
-  if (sentinelExpr->getType()->isNullPtrType()) return;
-
-  if (sentinelExpr->getType()->isAnyPointerType() &&
-      sentinelExpr->IgnoreParenCasts()->isNullPointerConstant(Context,
-                                            Expr::NPC_ValueDependentIsNull))
-    return;
-
-  // Unfortunately, __null has type 'int'.
-  if (isa<GNUNullExpr>(sentinelExpr)) return;
+  if (isNullExpr(sentinelExpr)) return;
 
   // Pick a reasonable string to insert.  Optimistically use 'nil' or
   // 'NULL' if those are actually defined in the context.  Only use
@@ -289,6 +279,24 @@ SourceRange Sema::getExprRange(Expr *E) const {
   return E ? E->getSourceRange() : SourceRange();
 }
 
+bool Sema::isNullExpr(const Expr *E) const {
+  if (!E)
+    return false;
+
+  // nullptr_t is always treated as null.
+  if (E->getType()->isNullPtrType()) return true;
+
+  if (E->getType()->isAnyPointerType() &&
+      E->IgnoreParenCasts()->isNullPointerConstant(Context,
+                                            Expr::NPC_ValueDependentIsNull))
+    return true;
+
+  // Unfortunately, __null has type 'int'.
+  if (isa<GNUNullExpr>(E)) return true;
+
+  return false;
+}
+
 //===----------------------------------------------------------------------===//
 //  Standard Promotions and Conversions
 //===----------------------------------------------------------------------===//