r251407 - [analyzer] Fix lambdas that are capturing constants.
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 27 06:46:39 PDT 2015
Author: xazax
Date: Tue Oct 27 08:46:39 2015
New Revision: 251407
URL: http://llvm.org/viewvc/llvm-project?rev=251407&view=rev
Log:
[analyzer] Fix lambdas that are capturing constants.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/lambdas.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=251407&r1=251406&r2=251407&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Oct 27 08:46:39 2015
@@ -1859,13 +1859,20 @@ void ExprEngine::VisitCommonDeclRefExpr(
FieldDecl *LambdaThisCaptureField;
CXXRec->getCaptureFields(LambdaCaptureFields, LambdaThisCaptureField);
const FieldDecl *FD = LambdaCaptureFields[VD];
- Loc CXXThis =
- svalBuilder.getCXXThis(MD, LocCtxt->getCurrentStackFrame());
- SVal CXXThisVal = state->getSVal(CXXThis);
- V = state->getLValue(FD, CXXThisVal);
- if (FD->getType()->isReferenceType() &&
- !VD->getType()->isReferenceType())
- CaptureByReference = true;
+ if (!FD) {
+ // When a constant is captured, sometimes no corresponding field is
+ // created in the lambda object.
+ assert(VD->getType().isConstQualified());
+ V = state->getLValue(VD, LocCtxt);
+ } else {
+ Loc CXXThis =
+ svalBuilder.getCXXThis(MD, LocCtxt->getCurrentStackFrame());
+ SVal CXXThisVal = state->getSVal(CXXThis);
+ V = state->getLValue(FD, CXXThisVal);
+ if (FD->getType()->isReferenceType() &&
+ !VD->getType()->isReferenceType())
+ CaptureByReference = true;
+ }
} else {
V = state->getLValue(VD, LocCtxt);
}
Modified: cfe/trunk/test/Analysis/lambdas.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lambdas.cpp?rev=251407&r1=251406&r2=251407&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/lambdas.cpp (original)
+++ cfe/trunk/test/Analysis/lambdas.cpp Tue Oct 27 08:46:39 2015
@@ -195,6 +195,21 @@ struct DontCrash {
}
};
+
+// Capture constants
+
+void captureConstants() {
+ const int i = 5;
+ [=]() {
+ if (i != 5)
+ clang_analyzer_warnIfReached();
+ }();
+ [&] {
+ if (i != 5)
+ clang_analyzer_warnIfReached();
+ }();
+}
+
// CHECK: [B2 (ENTRY)]
// CHECK: Succs (1): B1
// CHECK: [B1]
More information about the cfe-commits
mailing list