gchatelet updated this revision to Diff 251671.
gchatelet marked an inline comment as done.
gchatelet added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76504/new/

https://reviews.llvm.org/D76504

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,18 +1649,16 @@
   case Builtin::BI__builtin_nontemporal_store:
     return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-    clang::Expr *DstOp = TheCall->getArg(0);
-    clang::Expr *SrcOp = TheCall->getArg(1);
     clang::Expr *SizeOp = TheCall->getArg(2);
-    // If any arg is instantiation dependent we bail out.
-    if (DstOp->isInstantiationDependent() ||
-        SrcOp->isInstantiationDependent() || 
SizeOp->isInstantiationDependent())
+    // We warn about copying to or from `nullptr` pointers when size is greater
+    // than 0. When `size` is instantiation dependent we cannot evaluate its
+    // value so we bail out.
+    if (SizeOp->isInstantiationDependent())
       break;
-    // __builtin_memcpy_inline size argument is a constant by definition.
-    if (SizeOp->EvaluateKnownConstInt(Context).isNullValue())
-      break;
-    CheckNonNullArgument(*this, DstOp, TheCall->getExprLoc());
-    CheckNonNullArgument(*this, SrcOp, TheCall->getExprLoc());
+    if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+      CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
+      CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+    }
     break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)


Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1649,18 +1649,16 @@
   case Builtin::BI__builtin_nontemporal_store:
     return SemaBuiltinNontemporalOverloaded(TheCallResult);
   case Builtin::BI__builtin_memcpy_inline: {
-    clang::Expr *DstOp = TheCall->getArg(0);
-    clang::Expr *SrcOp = TheCall->getArg(1);
     clang::Expr *SizeOp = TheCall->getArg(2);
-    // If any arg is instantiation dependent we bail out.
-    if (DstOp->isInstantiationDependent() ||
-        SrcOp->isInstantiationDependent() || SizeOp->isInstantiationDependent())
+    // We warn about copying to or from `nullptr` pointers when size is greater
+    // than 0. When `size` is instantiation dependent we cannot evaluate its
+    // value so we bail out.
+    if (SizeOp->isInstantiationDependent())
       break;
-    // __builtin_memcpy_inline size argument is a constant by definition.
-    if (SizeOp->EvaluateKnownConstInt(Context).isNullValue())
-      break;
-    CheckNonNullArgument(*this, DstOp, TheCall->getExprLoc());
-    CheckNonNullArgument(*this, SrcOp, TheCall->getExprLoc());
+    if (!SizeOp->EvaluateKnownConstInt(Context).isNullValue()) {
+      CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
+      CheckNonNullArgument(*this, TheCall->getArg(1), TheCall->getExprLoc());
+    }
     break;
   }
 #define BUILTIN(ID, TYPE, ATTRS)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to