diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/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)