aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2020-03-20 16:23:49 +0100
committerGuillaume Chatelet <gchatelet@google.com>2020-03-21 12:42:06 +0100
commitd260a10d98dff6e34d081e570df1f7c0a50b9a73 (patch)
tree2f3340027cf419f6ff360c51460c47c55a0b7571 /clang/lib/Sema/SemaChecking.cpp
parentf9a8650578dcd1358179798117aecab3e3c35176 (diff)
downloadllvm-d260a10d98dff6e34d081e570df1f7c0a50b9a73.zip
llvm-d260a10d98dff6e34d081e570df1f7c0a50b9a73.tar.gz
llvm-d260a10d98dff6e34d081e570df1f7c0a50b9a73.tar.bz2
[clang] Fix crash during template sema checking
Summary: If the size parameter of `__builtin_memcpy_inline` comes from an un-instantiated template parameter current code would crash. Reviewers: efriedma, courbet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76504
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 8a2b4b0..c3e168c1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1649,11 +1649,16 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
case Builtin::BI__builtin_nontemporal_store:
return SemaBuiltinNontemporalOverloaded(TheCallResult);
case Builtin::BI__builtin_memcpy_inline: {
- // __builtin_memcpy_inline size argument is a constant by definition.
- if (TheCall->getArg(2)->EvaluateKnownConstInt(Context).isNullValue())
+ clang::Expr *SizeOp = TheCall->getArg(2);
+ // We warn about copying to or from `nullptr` pointers when `size` is
+ // greater than 0. When `size` is value dependent we cannot evaluate its
+ // value so we bail out.
+ if (SizeOp->isValueDependent())
break;
- CheckNonNullArgument(*this, TheCall->getArg(0), TheCall->getExprLoc());
- CheckNonNullArgument(*this, TheCall->getArg(1), 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)