<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">I reverted this in r347314 for breaking many bots on <a href="http://lab.llvm.org:8011/console">lab.llvm.org:8011/console</a><div><br></div><div>I've also put a standalone repro at <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=907099#c2">https://bugs.chromium.org/p/chromium/issues/detail?id=907099#c2</a>.<br></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 20, 2018 at 3:56 AM Bill Wendling via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: void<br>
Date: Tue Nov 20 00:53:30 2018<br>
New Revision: 347294<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=347294&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=347294&view=rev</a><br>
Log:<br>
Use is.constant intrinsic for __builtin_constant_p<br>
<br>
Summary:<br>
A __builtin_constant_p may end up with a constant after inlining. Use<br>
the is.constant intrinsic if it's a variable that's in a context where<br>
it may resolve to a constant, e.g., an argument to a function after<br>
inlining.<br>
<br>
Reviewers: rsmith, shafik<br>
<br>
Subscribers: jfb, kristina, cfe-commits, nickdesaulniers, jyknight<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D54355" rel="noreferrer" target="_blank">https://reviews.llvm.org/D54355</a><br>
<br>
Modified:<br>
cfe/trunk/include/clang/AST/Expr.h<br>
cfe/trunk/lib/AST/ASTImporter.cpp<br>
cfe/trunk/lib/AST/Expr.cpp<br>
cfe/trunk/lib/AST/ExprConstant.cpp<br>
cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
cfe/trunk/lib/Sema/SemaDeclCXX.cpp<br>
cfe/trunk/lib/Sema/SemaExpr.cpp<br>
cfe/trunk/lib/Sema/SemaOverload.cpp<br>
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp<br>
cfe/trunk/lib/Sema/SemaType.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp<br>
cfe/trunk/test/Analysis/builtin-functions.cpp<br>
cfe/trunk/test/Sema/builtins.c<br>
cfe/trunk/test/SemaCXX/compound-literal.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/Expr.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Expr.h (original)<br>
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 00:53:30 2018<br>
@@ -901,10 +901,15 @@ public:<br>
<br>
/// ConstantExpr - An expression that occurs in a constant context.<br>
class ConstantExpr : public FullExpr {<br>
-public:<br>
ConstantExpr(Expr *subexpr)<br>
: FullExpr(ConstantExprClass, subexpr) {}<br>
<br>
+public:<br>
+ static ConstantExpr *Create(const ASTContext &Context, Expr *E) {<br>
+ assert(!isa<ConstantExpr>(E));<br>
+ return new (Context) ConstantExpr(E);<br>
+ }<br>
+<br>
/// Build an empty constant expression wrapper.<br>
explicit ConstantExpr(EmptyShell Empty)<br>
: FullExpr(ConstantExprClass, Empty) {}<br>
@@ -3091,8 +3096,8 @@ inline Expr *Expr::IgnoreImpCasts() {<br>
while (true)<br>
if (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))<br>
e = ice->getSubExpr();<br>
- else if (ConstantExpr *ce = dyn_cast<ConstantExpr>(e))<br>
- e = ce->getSubExpr();<br>
+ else if (FullExpr *fe = dyn_cast<FullExpr>(e))<br>
+ e = fe->getSubExpr();<br>
else<br>
break;<br>
return e;<br>
<br>
Modified: cfe/trunk/lib/AST/ASTImporter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 20 00:53:30 2018<br>
@@ -6375,7 +6375,7 @@ ExpectedStmt ASTNodeImporter::VisitConst<br>
Expr *ToSubExpr;<br>
std::tie(ToSubExpr) = *Imp;<br>
<br>
- return new (Importer.getToContext()) ConstantExpr(ToSubExpr);<br>
+ return ConstantExpr::Create(Importer.getToContext(), ToSubExpr);<br>
}<br>
<br>
ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) {<br>
<br>
Modified: cfe/trunk/lib/AST/Expr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Expr.cpp (original)<br>
+++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 20 00:53:30 2018<br>
@@ -2594,8 +2594,8 @@ Expr *Expr::IgnoreParenCasts() {<br>
E = NTTP->getReplacement();<br>
continue;<br>
}<br>
- if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {<br>
- E = CE->getSubExpr();<br>
+ if (FullExpr *FE = dyn_cast<FullExpr>(E)) {<br>
+ E = FE->getSubExpr();<br>
continue;<br>
}<br>
return E;<br>
@@ -2619,8 +2619,8 @@ Expr *Expr::IgnoreCasts() {<br>
E = NTTP->getReplacement();<br>
continue;<br>
}<br>
- if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {<br>
- E = CE->getSubExpr();<br>
+ if (FullExpr *FE = dyn_cast<FullExpr>(E)) {<br>
+ E = FE->getSubExpr();<br>
continue;<br>
}<br>
return E;<br>
@@ -2648,8 +2648,8 @@ Expr *Expr::IgnoreParenLValueCasts() {<br>
= dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {<br>
E = NTTP->getReplacement();<br>
continue;<br>
- } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {<br>
- E = CE->getSubExpr();<br>
+ } else if (FullExpr *FE = dyn_cast<FullExpr>(E)) {<br>
+ E = FE->getSubExpr();<br>
continue;<br>
}<br>
break;<br>
@@ -2920,6 +2920,12 @@ bool Expr::isConstantInitializer(ASTCont<br>
<br>
break;<br>
}<br>
+ case ConstantExprClass: {<br>
+ // FIXME: We should be able to return "true" here, but it can lead to extra<br>
+ // error messages. E.g. in Sema/array-init.c.<br>
+ const Expr *Exp = cast<ConstantExpr>(this)->getSubExpr();<br>
+ return Exp->isConstantInitializer(Ctx, false, Culprit);<br>
+ }<br>
case CompoundLiteralExprClass: {<br>
// This handles gcc's extension that allows global initializers like<br>
// "struct x {int x;} x = (struct x) {};".<br>
<br>
Modified: cfe/trunk/lib/AST/ExprConstant.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Nov 20 00:53:30 2018<br>
@@ -45,6 +45,7 @@<br>
#include "clang/AST/TypeLoc.h"<br>
#include "clang/Basic/Builtins.h"<br>
#include "clang/Basic/TargetInfo.h"<br>
+#include "llvm/Support/SaveAndRestore.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
#include <cstring><br>
#include <functional><br>
@@ -721,6 +722,10 @@ namespace {<br>
/// Whether or not we're currently speculatively evaluating.<br>
bool IsSpeculativelyEvaluating;<br>
<br>
+ /// Whether or not we're in a context where the front end requires a<br>
+ /// constant value.<br>
+ bool InConstantContext;<br>
+<br>
enum EvaluationMode {<br>
/// Evaluate as a constant expression. Stop if we find that the expression<br>
/// is not a constant expression.<br>
@@ -782,7 +787,7 @@ namespace {<br>
EvaluatingDecl((const ValueDecl *)nullptr),<br>
EvaluatingDeclValue(nullptr), HasActiveDiagnostic(false),<br>
HasFoldFailureDiagnostic(false), IsSpeculativelyEvaluating(false),<br>
- EvalMode(Mode) {}<br>
+ InConstantContext(false), EvalMode(Mode) {}<br>
<br>
void setEvaluatingDecl(APValue::LValueBase Base, APValue &Value) {<br>
EvaluatingDecl = Base;<br>
@@ -7348,6 +7353,8 @@ public:<br>
// Visitor Methods<br>
//===--------------------------------------------------------------------===//<br>
<br>
+ bool VisitConstantExpr(const ConstantExpr *E);<br>
+<br>
bool VisitIntegerLiteral(const IntegerLiteral *E) {<br>
return Success(E->getValue(), E);<br>
}<br>
@@ -8088,6 +8095,11 @@ static bool tryEvaluateBuiltinObjectSize<br>
return true;<br>
}<br>
<br>
+bool IntExprEvaluator::VisitConstantExpr(const ConstantExpr *E) {<br>
+ llvm::SaveAndRestore<bool> InConstantContext(Info.InConstantContext, true);<br>
+ return ExprEvaluatorBaseTy::VisitConstantExpr(E);<br>
+}<br>
+<br>
bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {<br>
if (unsigned BuiltinOp = E->getBuiltinCallee())<br>
return VisitBuiltinCallExpr(E, BuiltinOp);<br>
@@ -8175,8 +8187,20 @@ bool IntExprEvaluator::VisitBuiltinCallE<br>
return Success(Val.countLeadingZeros(), E);<br>
}<br>
<br>
- case Builtin::BI__builtin_constant_p:<br>
- return Success(EvaluateBuiltinConstantP(Info.Ctx, E->getArg(0)), E);<br>
+ case Builtin::BI__builtin_constant_p: {<br>
+ auto Arg = E->getArg(0);<br>
+ if (EvaluateBuiltinConstantP(Info.Ctx, Arg))<br>
+ return Success(true, E);<br>
+ auto ArgTy = Arg->IgnoreImplicit()->getType();<br>
+ if (!Info.InConstantContext && !Arg->HasSideEffects(Info.Ctx) &&<br>
+ !ArgTy->isAggregateType() && !ArgTy->isPointerType()) {<br>
+ // We can delay calculation of __builtin_constant_p until after<br>
+ // inlining. Note: This diagnostic won't be shown to the user.<br>
+ Info.FFDiag(E, diag::note_invalid_subexpr_in_const_expr);<br>
+ return false;<br>
+ }<br>
+ return Success(false, E);<br>
+ }<br>
<br>
case Builtin::BI__builtin_ctz:<br>
case Builtin::BI__builtin_ctzl:<br>
@@ -10746,6 +10770,14 @@ static bool FastEvaluateAsRValue(const E<br>
return false;<br>
}<br>
<br>
+static bool EvaluateAsRValue(const Expr *E, Expr::EvalResult &Result,<br>
+ const ASTContext &Ctx, EvalInfo &Info) {<br>
+ bool IsConst;<br>
+ if (FastEvaluateAsRValue(E, Result, Ctx, IsConst))<br>
+ return IsConst;<br>
+<br>
+ return EvaluateAsRValue(Info, E, Result.Val);<br>
+}<br>
<br>
/// EvaluateAsRValue - Return true if this is a constant which we can fold using<br>
/// any crazy technique (that has nothing to do with language standards) that<br>
@@ -10753,12 +10785,8 @@ static bool FastEvaluateAsRValue(const E<br>
/// in Result. If this expression is a glvalue, an lvalue-to-rvalue conversion<br>
/// will be applied to the result.<br>
bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const {<br>
- bool IsConst;<br>
- if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))<br>
- return IsConst;<br>
-<br>
EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);<br>
- return ::EvaluateAsRValue(Info, this, Result.Val);<br>
+ return ::EvaluateAsRValue(this, Result, Ctx, Info);<br>
}<br>
<br>
bool Expr::EvaluateAsBooleanCondition(bool &Result,<br>
@@ -10878,35 +10906,40 @@ bool Expr::isEvaluatable(const ASTContex<br>
<br>
APSInt Expr::EvaluateKnownConstInt(const ASTContext &Ctx,<br>
SmallVectorImpl<PartialDiagnosticAt> *Diag) const {<br>
- EvalResult EvalResult;<br>
- EvalResult.Diag = Diag;<br>
- bool Result = EvaluateAsRValue(EvalResult, Ctx);<br>
+ EvalResult EVResult;<br>
+ EVResult.Diag = Diag;<br>
+ EvalInfo Info(Ctx, EVResult, EvalInfo::EM_IgnoreSideEffects);<br>
+ Info.InConstantContext = true;<br>
+<br>
+ bool Result = ::EvaluateAsRValue(this, EVResult, Ctx, Info);<br>
(void)Result;<br>
assert(Result && "Could not evaluate expression");<br>
- assert(EvalResult.Val.isInt() && "Expression did not evaluate to integer");<br>
+ assert(EVResult.Val.isInt() && "Expression did not evaluate to integer");<br>
<br>
- return EvalResult.Val.getInt();<br>
+ return EVResult.Val.getInt();<br>
}<br>
<br>
APSInt Expr::EvaluateKnownConstIntCheckOverflow(<br>
const ASTContext &Ctx, SmallVectorImpl<PartialDiagnosticAt> *Diag) const {<br>
- EvalResult EvalResult;<br>
- EvalResult.Diag = Diag;<br>
- EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow);<br>
- bool Result = ::EvaluateAsRValue(Info, this, EvalResult.Val);<br>
+ EvalResult EVResult;<br>
+ EVResult.Diag = Diag;<br>
+ EvalInfo Info(Ctx, EVResult, EvalInfo::EM_EvaluateForOverflow);<br>
+ Info.InConstantContext = true;<br>
+<br>
+ bool Result = ::EvaluateAsRValue(Info, this, EVResult.Val);<br>
(void)Result;<br>
assert(Result && "Could not evaluate expression");<br>
- assert(EvalResult.Val.isInt() && "Expression did not evaluate to integer");<br>
+ assert(EVResult.Val.isInt() && "Expression did not evaluate to integer");<br>
<br>
- return EvalResult.Val.getInt();<br>
+ return EVResult.Val.getInt();<br>
}<br>
<br>
void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {<br>
bool IsConst;<br>
- EvalResult EvalResult;<br>
- if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) {<br>
- EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow);<br>
- (void)::EvaluateAsRValue(Info, this, EvalResult.Val);<br>
+ EvalResult EVResult;<br>
+ if (!FastEvaluateAsRValue(this, EVResult, Ctx, IsConst)) {<br>
+ EvalInfo Info(Ctx, EVResult, EvalInfo::EM_EvaluateForOverflow);<br>
+ (void)::EvaluateAsRValue(Info, this, EVResult.Val);<br>
}<br>
}<br>
<br>
@@ -10959,7 +10992,11 @@ static ICEDiag Worst(ICEDiag A, ICEDiag<br>
<br>
static ICEDiag CheckEvalInICE(const Expr* E, const ASTContext &Ctx) {<br>
Expr::EvalResult EVResult;<br>
- if (!E->EvaluateAsRValue(EVResult, Ctx) || EVResult.HasSideEffects ||<br>
+ Expr::EvalStatus Status;<br>
+ EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);<br>
+<br>
+ Info.InConstantContext = true;<br>
+ if (!::EvaluateAsRValue(E, EVResult, Ctx, Info) || EVResult.HasSideEffects ||<br>
!EVResult.Val.isInt())<br>
return ICEDiag(IK_NotICE, E->getBeginLoc());<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Nov 20 00:53:30 2018<br>
@@ -1926,6 +1926,26 @@ RValue CodeGenFunction::EmitBuiltinExpr(<br>
case Builtin::BI__builtin_rotateright64:<br>
return emitRotate(E, true);<br>
<br>
+ case Builtin::BI__builtin_constant_p: {<br>
+ llvm::Type *ResultType = ConvertType(E->getType());<br>
+ if (CGM.getCodeGenOpts().OptimizationLevel == 0)<br>
+ // At -O0, we don't perform inlining, so we don't need to delay the<br>
+ // processing.<br>
+ return RValue::get(ConstantInt::get(ResultType, 0));<br>
+ if (auto *DRE = dyn_cast<DeclRefExpr>(E->getArg(0)->IgnoreImplicit())) {<br>
+ auto DREType = DRE->getType();<br>
+ if (DREType->isAggregateType() || DREType->isFunctionType())<br>
+ return RValue::get(ConstantInt::get(ResultType, 0));<br>
+ }<br>
+ Value *ArgValue = EmitScalarExpr(E->getArg(0));<br>
+ llvm::Type *ArgType = ArgValue->getType();<br>
+<br>
+ Value *F = CGM.getIntrinsic(Intrinsic::is_constant, ArgType);<br>
+ Value *Result = Builder.CreateCall(F, ArgValue);<br>
+ if (Result->getType() != ResultType)<br>
+ Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true);<br>
+ return RValue::get(Result);<br>
+ }<br>
case Builtin::BI__builtin_object_size: {<br>
unsigned Type =<br>
E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue();<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Nov 20 00:53:30 2018<br>
@@ -13861,6 +13861,8 @@ Decl *Sema::BuildStaticAssertDeclaration<br>
ExprResult Converted = PerformContextuallyConvertToBool(AssertExpr);<br>
if (Converted.isInvalid())<br>
Failed = true;<br>
+ else<br>
+ Converted = ConstantExpr::Create(Context, Converted.get());<br>
<br>
llvm::APSInt Cond;<br>
if (!Failed && VerifyIntegerConstantExpression(Converted.get(), &Cond,<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Nov 20 00:53:30 2018<br>
@@ -5795,6 +5795,8 @@ Sema::BuildCompoundLiteralExpr(SourceLoc<br>
? VK_RValue<br>
: VK_LValue;<br>
<br>
+ if (isFileScope)<br>
+ LiteralExpr = ConstantExpr::Create(Context, LiteralExpr);<br>
Expr *E = new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType,<br>
VK, LiteralExpr, isFileScope);<br>
if (isFileScope) {<br>
@@ -5803,7 +5805,6 @@ Sema::BuildCompoundLiteralExpr(SourceLoc<br>
!literalType->isDependentType()) // C99 6.5.2.5p3<br>
if (CheckForConstantInitializer(LiteralExpr, literalType))<br>
return ExprError();<br>
- E = new (Context) ConstantExpr(E);<br>
} else if (literalType.getAddressSpace() != LangAS::opencl_private &&<br>
literalType.getAddressSpace() != LangAS::Default) {<br>
// Embedded-C extensions to C99 <a href="http://6.5.2.5" rel="noreferrer" target="_blank">6.5.2.5</a>:<br>
@@ -14167,12 +14168,15 @@ Sema::VerifyIntegerConstantExpression(Ex<br>
return ExprError();<br>
}<br>
<br>
+ if (!isa<ConstantExpr>(E))<br>
+ E = ConstantExpr::Create(Context, E);<br>
+<br>
// Circumvent ICE checking in C++11 to avoid evaluating the expression twice<br>
// in the non-ICE case.<br>
if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {<br>
if (Result)<br>
*Result = E->EvaluateKnownConstIntCheckOverflow(Context);<br>
- return new (Context) ConstantExpr(E);<br>
+ return E;<br>
}<br>
<br>
Expr::EvalResult EvalResult;<br>
@@ -14190,7 +14194,7 @@ Sema::VerifyIntegerConstantExpression(Ex<br>
if (Folded && getLangOpts().CPlusPlus11 && Notes.empty()) {<br>
if (Result)<br>
*Result = EvalResult.Val.getInt();<br>
- return new (Context) ConstantExpr(E);<br>
+ return E;<br>
}<br>
<br>
// If our only note is the usual "invalid subexpression" note, just point<br>
@@ -14218,7 +14222,7 @@ Sema::VerifyIntegerConstantExpression(Ex<br>
<br>
if (Result)<br>
*Result = EvalResult.Val.getInt();<br>
- return new (Context) ConstantExpr(E);<br>
+ return E;<br>
}<br>
<br>
namespace {<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Nov 20 00:53:30 2018<br>
@@ -5469,7 +5469,7 @@ static ExprResult CheckConvertedConstant<br>
<br>
if (Notes.empty()) {<br>
// It's a constant expression.<br>
- return new (S.Context) ConstantExpr(Result.get());<br>
+ return ConstantExpr::Create(S.Context, Result.get());<br>
}<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Nov 20 00:53:30 2018<br>
@@ -178,6 +178,8 @@ getDeducedParameterFromExpr(TemplateDedu<br>
while (true) {<br>
if (ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(E))<br>
E = IC->getSubExpr();<br>
+ else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E))<br>
+ E = CE->getSubExpr();<br>
else if (SubstNonTypeTemplateParmExpr *Subst =<br>
dyn_cast<SubstNonTypeTemplateParmExpr>(E))<br>
E = Subst->getReplacement();<br>
@@ -5225,6 +5227,8 @@ MarkUsedTemplateParameters(ASTContext &C<br>
while (true) {<br>
if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))<br>
E = ICE->getSubExpr();<br>
+ else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(E))<br>
+ E = CE->getSubExpr();<br>
else if (const SubstNonTypeTemplateParmExpr *Subst =<br>
dyn_cast<SubstNonTypeTemplateParmExpr>(E))<br>
E = Subst->getReplacement();<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Nov 20 00:53:30 2018<br>
@@ -2233,10 +2233,6 @@ QualType Sema::BuildArrayType(QualType T<br>
T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);<br>
}<br>
<br>
- if (ArraySize && !CurContext->isFunctionOrMethod())<br>
- // A file-scoped array must have a constant array size.<br>
- ArraySize = new (Context) ConstantExpr(ArraySize);<br>
-<br>
// OpenCL v1.2 s6.9.d: variable length arrays are not supported.<br>
if (getLangOpts().OpenCL && T->isVariableArrayType()) {<br>
Diag(Loc, diag::err_opencl_vla);<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Nov 20 00:53:30 2018<br>
@@ -1283,9 +1283,6 @@ void ExprEngine::Visit(const Stmt *S, Ex<br>
break;<br>
<br>
case Expr::ConstantExprClass:<br>
- // Handled due to it being a wrapper class.<br>
- break;<br>
-<br>
case Stmt::ExprWithCleanupsClass:<br>
// Handled due to fully linearised CFG.<br>
break;<br>
<br>
Modified: cfe/trunk/test/Analysis/builtin-functions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-functions.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-functions.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/builtin-functions.cpp (original)<br>
+++ cfe/trunk/test/Analysis/builtin-functions.cpp Tue Nov 20 00:53:30 2018<br>
@@ -70,14 +70,14 @@ void test_constant_p() {<br>
const int j = 2;<br>
constexpr int k = 3;<br>
clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}<br>
- clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{TRUE}}<br>
+ clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{UNKNOWN}}<br>
clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning {{TRUE}}<br>
clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning {{TRUE}}<br>
- clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{TRUE}}<br>
+ clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{UNKNOWN}}<br>
clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning {{TRUE}}<br>
clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning {{TRUE}}<br>
clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}<br>
- clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{TRUE}}<br>
+ clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{UNKNOWN}}<br>
clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning {{FALSE}}<br>
clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning {{TRUE}}<br>
}<br>
<br>
Modified: cfe/trunk/test/Sema/builtins.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/builtins.c (original)<br>
+++ cfe/trunk/test/Sema/builtins.c Tue Nov 20 00:53:30 2018<br>
@@ -122,6 +122,14 @@ int test16() {<br>
__builtin_constant_p(1, 2); // expected-error {{too many arguments}}<br>
}<br>
<br>
+// __builtin_constant_p cannot resolve non-constants as a file scoped array.<br>
+int expr;<br>
+char y[__builtin_constant_p(expr) ? -1 : 1]; // no warning, the builtin is false.<br>
+<br>
+// no warning, the builtin is false.<br>
+struct foo { int a; };<br>
+struct foo x = (struct foo) { __builtin_constant_p(42) ? 37 : 927 };<br>
+<br>
const int test17_n = 0;<br>
const char test17_c[] = {1, 2, 3, 0};<br>
const char test17_d[] = {1, 2, 3, 4};<br>
@@ -161,6 +169,7 @@ void test17() {<br>
F(&test17_d);<br>
F((struct Aggregate){0, 1});<br>
F((IntVector){0, 1, 2, 3});<br>
+ F(test17);<br>
<br>
// Ensure that a technique used in glibc is handled correctly.<br>
#define OPT(...) (__builtin_constant_p(__VA_ARGS__) && strlen(__VA_ARGS__) < 4)<br>
<br>
Modified: cfe/trunk/test/SemaCXX/compound-literal.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compound-literal.cpp?rev=347294&r1=347293&r2=347294&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compound-literal.cpp?rev=347294&r1=347293&r2=347294&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/compound-literal.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/compound-literal.cpp Tue Nov 20 00:53:30 2018<br>
@@ -36,8 +36,8 @@ namespace brace_initializers {<br>
<br>
POD p = (POD){1, 2};<br>
// CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::POD'<br>
- // CHECK: ConstantExpr {{.*}} 'brace_initializers::POD'<br>
- // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'brace_initializers::POD'<br>
+ // CHECK: CompoundLiteralExpr {{.*}} 'brace_initializers::POD'<br>
+ // CHECK-NEXT: ConstantExpr {{.*}} 'brace_initializers::POD'<br>
// CHECK-NEXT: InitListExpr {{.*}} 'brace_initializers::POD'<br>
// CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}<br>
// CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>