summaryrefslogtreecommitdiff
path: root/lib/AST/Expr.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
commite44c638ccfb9c020561219a3bfc76ce41a99cf4b (patch)
tree1c2a925b80306bd7ce2c14d3ef737ff3a190e671 /lib/AST/Expr.cpp
parent58828cc308e0a6030d0418573376624d01baa7d3 (diff)
downloadclang-e44c638ccfb9c020561219a3bfc76ce41a99cf4b.tar.gz
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r--lib/AST/Expr.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index e343949ac1..ec6f084aed 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -2594,8 +2594,8 @@ Expr *Expr::IgnoreParenCasts() {
E = NTTP->getReplacement();
continue;
}
- if (FullExpr *FE = dyn_cast<FullExpr>(E)) {
- E = FE->getSubExpr();
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
+ E = CE->getSubExpr();
continue;
}
return E;
@@ -2619,8 +2619,8 @@ Expr *Expr::IgnoreCasts() {
E = NTTP->getReplacement();
continue;
}
- if (FullExpr *FE = dyn_cast<FullExpr>(E)) {
- E = FE->getSubExpr();
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
+ E = CE->getSubExpr();
continue;
}
return E;
@@ -2648,8 +2648,8 @@ Expr *Expr::IgnoreParenLValueCasts() {
= dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
E = NTTP->getReplacement();
continue;
- } else if (FullExpr *FE = dyn_cast<FullExpr>(E)) {
- E = FE->getSubExpr();
+ } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
+ E = CE->getSubExpr();
continue;
}
break;
@@ -2920,12 +2920,6 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef,
break;
}
- case ConstantExprClass: {
- // FIXME: We should be able to return "true" here, but it can lead to extra
- // error messages. E.g. in Sema/array-init.c.
- const Expr *Exp = cast<ConstantExpr>(this)->getSubExpr();
- return Exp->isConstantInitializer(Ctx, false, Culprit);
- }
case CompoundLiteralExprClass: {
// This handles gcc's extension that allows global initializers like
// "struct x {int x;} x = (struct x) {};".
@@ -2965,8 +2959,8 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef,
const Expr *Elt = ILE->getInit(ElementNo++);
if (Field->isBitField()) {
// Bitfields have to evaluate to an integer.
- EvalResult Result;
- if (!Elt->EvaluateAsInt(Result, Ctx)) {
+ llvm::APSInt ResultTmp;
+ if (!Elt->EvaluateAsInt(ResultTmp, Ctx)) {
if (Culprit)
*Culprit = Elt;
return false;