summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorJames Y Knight <jyknight@google.com>2019-12-03 23:32:57 -0500
committerJames Y Knight <jyknight@google.com>2019-12-04 15:12:17 -0500
commit90fce46fa6c9ccec86f642be0a75da2d0a5b11c1 (patch)
tree14959e616a4d695f876942bac5e44ac0d3334933 /clang/lib/AST/ExprConstant.cpp
parent975a43512709a9e989dea11d2fefab9212e3a4f4 (diff)
downloadbcm5719-llvm-90fce46fa6c9ccec86f642be0a75da2d0a5b11c1.tar.gz
bcm5719-llvm-90fce46fa6c9ccec86f642be0a75da2d0a5b11c1.zip
Fix crash-on-invalid-code in lambda constant evaluation.
If the lambda used 'this' without without capturing it, an error was emitted, but the constant evaluator would still attempt to lookup the capture, and failing to find it, dereference a null pointer. This only happens in C++17 (as that's when lambdas were made potentially-constexpr). Therefore, I also updated the lambda-expressions.cpp test to run in both C++14 and C++17 modes.
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index df80cb4f944..7a17b76f05d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7861,6 +7861,11 @@ public:
// either copied into the closure object's field that represents the '*this'
// or refers to '*this'.
if (isLambdaCallOperator(Info.CurrentCall->Callee)) {
+ // Ensure we actually have captured 'this'. (an error will have
+ // been previously reported if not).
+ if (!Info.CurrentCall->LambdaThisCaptureField)
+ return false;
+
// Update 'Result' to refer to the data member/field of the closure object
// that represents the '*this' capture.
if (!HandleLValueMember(Info, E, Result,
OpenPOWER on IntegriCloud