diff options
author | James Y Knight <jyknight@google.com> | 2019-12-03 23:32:57 -0500 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2019-12-04 15:12:17 -0500 |
commit | 90fce46fa6c9ccec86f642be0a75da2d0a5b11c1 (patch) | |
tree | 14959e616a4d695f876942bac5e44ac0d3334933 /clang/lib/AST/ExprConstant.cpp | |
parent | 975a43512709a9e989dea11d2fefab9212e3a4f4 (diff) | |
download | bcm5719-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.cpp | 5 |
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, |