[PATCH] D76504: [clang] Fix crash during template sema checking

Guillaume Chatelet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 20 09:44:42 PDT 2020


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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76504.251671.patch
Type: text/x-patch
Size: 1494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200320/2c10cd67/attachment.bin>


More information about the cfe-commits mailing list