summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/CFG.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2018-11-27 14:01:40 +0000
committerHans Wennborg <hans@hanshq.net>2018-11-27 14:01:40 +0000
commit8c79706e89dd2792bcc7b1e44d8f5db6abaf1617 (patch)
treeb1ebe35d9001f44880de2719abd98aeaa260270a /clang/lib/Analysis/CFG.cpp
parent032f3e7fd8a12ceab800b0d9c3aca0f769f7b7cc (diff)
downloadbcm5719-llvm-8c79706e89dd2792bcc7b1e44d8f5db6abaf1617.tar.gz
bcm5719-llvm-8c79706e89dd2792bcc7b1e44d8f5db6abaf1617.zip
Revert r347417 "Re-Reinstate 347294 with a fix for the failures."
This caused a miscompile in Chrome (see crbug.com/908372) that's illustrated by this small reduction: static bool f(int *a, int *b) { return !__builtin_constant_p(b - a) || (!(b - a)); } int arr[] = {1,2,3}; bool g() { return f(arr, arr + 3); } $ clang -O2 -S -emit-llvm a.cc -o - g() should return true, but after r347417 it became false for some reason. This also reverts the follow-up commits. r347417: > Re-Reinstate 347294 with a fix for the failures. > > Don't try to emit a scalar expression for a non-scalar argument to > __builtin_constant_p(). > > Third time's a charm! r347446: > The result of is.constant() is unsigned. r347480: > A __builtin_constant_p() returns 0 with a function type. r347512: > isEvaluatable() implies a constant context. > > Assume that we're in a constant context if we're asking if the expression can > be compiled into a constant initializer. This fixes the issue where a > __builtin_constant_p() in a compound literal was diagnosed as not being > constant, even though it's always possible to convert the builtin into a > constant. r347531: > A "constexpr" is evaluated in a constant context. Make sure this is reflected > if a __builtin_constant_p() is a part of a constexpr. llvm-svn: 347656
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r--clang/lib/Analysis/CFG.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 96130c25be8..cfda27dd37a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -1039,13 +1039,11 @@ private:
if (!areExprTypesCompatible(Expr1, Expr2))
return {};
- Expr::EvalResult L1Result, L2Result;
- if (!Expr1->EvaluateAsInt(L1Result, *Context) ||
- !Expr2->EvaluateAsInt(L2Result, *Context))
- return {};
+ llvm::APSInt L1, L2;
- llvm::APSInt L1 = L1Result.Val.getInt();
- llvm::APSInt L2 = L2Result.Val.getInt();
+ if (!Expr1->EvaluateAsInt(L1, *Context) ||
+ !Expr2->EvaluateAsInt(L2, *Context))
+ return {};
// Can't compare signed with unsigned or with different bit width.
if (L1.isSigned() != L2.isSigned() || L1.getBitWidth() != L2.getBitWidth())
@@ -1136,16 +1134,13 @@ private:
case BO_And: {
// If either operand is zero, we know the value
// must be false.
- Expr::EvalResult LHSResult;
- if (Bop->getLHS()->EvaluateAsInt(LHSResult, *Context)) {
- llvm::APSInt IntVal = LHSResult.Val.getInt();
+ llvm::APSInt IntVal;
+ if (Bop->getLHS()->EvaluateAsInt(IntVal, *Context)) {
if (!IntVal.getBoolValue()) {
return TryResult(false);
}
}
- Expr::EvalResult RHSResult;
- if (Bop->getRHS()->EvaluateAsInt(RHSResult, *Context)) {
- llvm::APSInt IntVal = RHSResult.Val.getInt();
+ if (Bop->getRHS()->EvaluateAsInt(IntVal, *Context)) {
if (!IntVal.getBoolValue()) {
return TryResult(false);
}
OpenPOWER on IntegriCloud