summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2018-11-20 08:53:30 +0000
committerBill Wendling <isanbard@gmail.com>2018-11-20 08:53:30 +0000
commit107b0e9881c87dba9f51109bae70b63d9e444546 (patch)
treec2bcc110804ddf7dca9704e3a47a2f26a6e2bcd5 /clang/lib/Sema/SemaExpr.cpp
parentcabb36d38d9e71610c7767a22477576aa8a4d9fa (diff)
downloadbcm5719-llvm-107b0e9881c87dba9f51109bae70b63d9e444546.tar.gz
bcm5719-llvm-107b0e9881c87dba9f51109bae70b63d9e444546.zip
Use is.constant intrinsic for __builtin_constant_p
Summary: A __builtin_constant_p may end up with a constant after inlining. Use the is.constant intrinsic if it's a variable that's in a context where it may resolve to a constant, e.g., an argument to a function after inlining. Reviewers: rsmith, shafik Subscribers: jfb, kristina, cfe-commits, nickdesaulniers, jyknight Differential Revision: https://reviews.llvm.org/D54355 llvm-svn: 347294
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 980dbf9921f..eab07b166da 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5795,6 +5795,8 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo,
? VK_RValue
: VK_LValue;
+ if (isFileScope)
+ LiteralExpr = ConstantExpr::Create(Context, LiteralExpr);
Expr *E = new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType,
VK, LiteralExpr, isFileScope);
if (isFileScope) {
@@ -5803,7 +5805,6 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo,
!literalType->isDependentType()) // C99 6.5.2.5p3
if (CheckForConstantInitializer(LiteralExpr, literalType))
return ExprError();
- E = new (Context) ConstantExpr(E);
} else if (literalType.getAddressSpace() != LangAS::opencl_private &&
literalType.getAddressSpace() != LangAS::Default) {
// Embedded-C extensions to C99 6.5.2.5:
@@ -14167,12 +14168,15 @@ Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
return ExprError();
}
+ if (!isa<ConstantExpr>(E))
+ E = ConstantExpr::Create(Context, E);
+
// Circumvent ICE checking in C++11 to avoid evaluating the expression twice
// in the non-ICE case.
if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
if (Result)
*Result = E->EvaluateKnownConstIntCheckOverflow(Context);
- return new (Context) ConstantExpr(E);
+ return E;
}
Expr::EvalResult EvalResult;
@@ -14190,7 +14194,7 @@ Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
if (Folded && getLangOpts().CPlusPlus11 && Notes.empty()) {
if (Result)
*Result = EvalResult.Val.getInt();
- return new (Context) ConstantExpr(E);
+ return E;
}
// If our only note is the usual "invalid subexpression" note, just point
@@ -14218,7 +14222,7 @@ Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
if (Result)
*Result = EvalResult.Val.getInt();
- return new (Context) ConstantExpr(E);
+ return E;
}
namespace {
OpenPOWER on IntegriCloud