summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/StaticAnalyzer/Core/RegionStore.cpp11
-rw-r--r--clang/test/Analysis/lambdas.cpp10
2 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 39b92ee3a18..ecb32cc378d 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1864,11 +1864,18 @@ SVal RegionStoreManager::getBindingForVar(RegionBindingsConstRef B,
return svalBuilder.getRegionValueSymbolVal(R);
// Is 'VD' declared constant? If so, retrieve the constant value.
- if (VD->getType().isConstQualified())
- if (const Expr *Init = VD->getInit())
+ if (VD->getType().isConstQualified()) {
+ if (const Expr *Init = VD->getInit()) {
if (Optional<SVal> V = svalBuilder.getConstantVal(Init))
return *V;
+ // If the variable is const qualified and has an initializer but
+ // we couldn't evaluate initializer to a value, treat the value as
+ // unknown.
+ return UnknownVal();
+ }
+ }
+
// This must come after the check for constants because closure-captured
// constant variables may appear in UnknownSpaceRegion.
if (isa<UnknownSpaceRegion>(MS))
diff --git a/clang/test/Analysis/lambdas.cpp b/clang/test/Analysis/lambdas.cpp
index f3ff9b95393..38a2e3a84fb 100644
--- a/clang/test/Analysis/lambdas.cpp
+++ b/clang/test/Analysis/lambdas.cpp
@@ -337,6 +337,16 @@ void captureByReference() {
lambda2();
}
+void testCapturedConstExprFloat() {
+ constexpr float localConstant = 4.0;
+ auto lambda = []{
+ // Don't treat localConstant as containing a garbage value
+ float copy = localConstant; // no-warning
+ (void)copy;
+ };
+
+ lambda();
+}
// CHECK: [B2 (ENTRY)]
// CHECK: Succs (1): B1
OpenPOWER on IntegriCloud