<div><div dir="auto">Should be fixed now. Sorry about the breakage. </div></div><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 21, 2018 at 4:51 AM Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">I've reverted this again in r347389. The standalone repro at <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=907099#c2" target="_blank">https://bugs.chromium.org/p/chromium/issues/detail?id=907099#c2</a> still asserts.<div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 20, 2018 at 6:26 PM Bill Wendling via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">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 15:24:16 2018<br>
New Revision: 347364<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=347364&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=347364&view=rev</a><br>
Log:<br>
Reinstate 347294 with a fix for the failures.<br>
<br>
EvaluateAsInt() is sometimes called in a constant context. When that's the<br>
case, we need to specify it as so.<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/Analysis/CFG.cpp<br>
cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
cfe/trunk/lib/CodeGen/CGExprScalar.cpp<br>
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp<br>
cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp<br>
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp<br>
cfe/trunk/lib/Sema/SemaCast.cpp<br>
cfe/trunk/lib/Sema/SemaChecking.cpp<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
cfe/trunk/lib/Sema/SemaDeclCXX.cpp<br>
cfe/trunk/lib/Sema/SemaExpr.cpp<br>
cfe/trunk/lib/Sema/SemaInit.cpp<br>
cfe/trunk/lib/Sema/SemaOpenMP.cpp<br>
cfe/trunk/lib/Sema/SemaOverload.cpp<br>
cfe/trunk/lib/Sema/SemaStmt.cpp<br>
cfe/trunk/lib/Sema/SemaStmtAsm.cpp<br>
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp<br>
cfe/trunk/lib/Sema/SemaType.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp<br>
cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Expr.h (original)<br>
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 15:24:16 2018<br>
@@ -600,7 +600,7 @@ public:<br>
<br>
/// EvaluateAsInt - Return true if this is a constant which we can fold and<br>
/// convert to an integer, using any crazy technique that we want to.<br>
- bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,<br>
+ bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,<br>
SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;<br>
<br>
/// EvaluateAsFloat - Return true if this is a constant which we can fold and<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>
@@ -3087,8 +3092,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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 20 15:24:16 2018<br>
@@ -6380,7 +6380,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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Expr.cpp (original)<br>
+++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 20 15:24:16 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>
@@ -2959,8 +2965,8 @@ bool Expr::isConstantInitializer(ASTCont<br>
const Expr *Elt = ILE->getInit(ElementNo++);<br>
if (Field->isBitField()) {<br>
// Bitfields have to evaluate to an integer.<br>
- llvm::APSInt ResultTmp;<br>
- if (!Elt->EvaluateAsInt(ResultTmp, Ctx)) {<br>
+ EvalResult Result;<br>
+ if (!Elt->EvaluateAsInt(Result, Ctx)) {<br>
if (Culprit)<br>
*Culprit = Elt;<br>
return false;<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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Nov 20 15:24:16 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>
@@ -5625,8 +5630,10 @@ static bool getBytesReturnedByAllocSizeC<br>
return false;<br>
<br>
auto EvaluateAsSizeT = [&](const Expr *E, APSInt &Into) {<br>
- if (!E->EvaluateAsInt(Into, Ctx, Expr::SE_AllowSideEffects))<br>
+ Expr::EvalResult ExprResult;<br>
+ if (!E->EvaluateAsInt(ExprResult, Ctx, Expr::SE_AllowSideEffects))<br>
return false;<br>
+ Into = ExprResult.Val.getInt();<br>
if (Into.isNegative() || !Into.isIntN(BitsInSizeT))<br>
return false;<br>
Into = Into.zextOrSelf(BitsInSizeT);<br>
@@ -7348,6 +7355,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 +8097,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 +8189,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 +10772,35 @@ static bool FastEvaluateAsRValue(const E<br>
return false;<br>
}<br>
<br>
+static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result,<br>
+ Expr::SideEffectsKind SEK) {<br>
+ return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) ||<br>
+ (SEK < Expr::SE_AllowUndefinedBehavior && Result.HasUndefinedBehavior);<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>
+static bool EvaluateAsInt(const Expr *E, Expr::EvalResult &ExprResult,<br>
+ const ASTContext &Ctx,<br>
+ Expr::SideEffectsKind AllowSideEffects,<br>
+ EvalInfo &Info) {<br>
+ if (!E->getType()->isIntegralOrEnumerationType())<br>
+ return false;<br>
+<br>
+ if (!::EvaluateAsRValue(E, ExprResult, Ctx, Info) ||<br>
+ !ExprResult.Val.isInt() ||<br>
+ hasUnacceptableSideEffect(ExprResult, AllowSideEffects))<br>
+ return false;<br>
+<br>
+ return true;<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 +10808,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>
@@ -10768,24 +10819,10 @@ bool Expr::EvaluateAsBooleanCondition(bo<br>
HandleConversionToBool(Scratch.Val, Result);<br>
}<br>
<br>
-static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result,<br>
- Expr::SideEffectsKind SEK) {<br>
- return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) ||<br>
- (SEK < Expr::SE_AllowUndefinedBehavior && Result.HasUndefinedBehavior);<br>
-}<br>
-<br>
-bool Expr::EvaluateAsInt(APSInt &Result, const ASTContext &Ctx,<br>
+bool Expr::EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,<br>
SideEffectsKind AllowSideEffects) const {<br>
- if (!getType()->isIntegralOrEnumerationType())<br>
- return false;<br>
-<br>
- EvalResult ExprResult;<br>
- if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isInt() ||<br>
- hasUnacceptableSideEffect(ExprResult, AllowSideEffects))<br>
- return false;<br>
-<br>
- Result = ExprResult.Val.getInt();<br>
- return true;<br>
+ EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);<br>
+ return ::EvaluateAsInt(this, Result, Ctx, AllowSideEffects, Info);<br>
}<br>
<br>
bool Expr::EvaluateAsFloat(APFloat &Result, const ASTContext &Ctx,<br>
@@ -10878,35 +10915,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 +11001,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>
@@ -11397,12 +11443,20 @@ bool Expr::isIntegerConstantExpr(llvm::A<br>
<br>
if (!isIntegerConstantExpr(Ctx, Loc))<br>
return false;<br>
+<br>
// The only possible side-effects here are due to UB discovered in the<br>
// evaluation (for instance, INT_MAX + 1). In such a case, we are still<br>
// required to treat the expression as an ICE, so we produce the folded<br>
// value.<br>
- if (!EvaluateAsInt(Value, Ctx, SE_AllowSideEffects))<br>
+ EvalResult ExprResult;<br>
+ Expr::EvalStatus Status;<br>
+ EvalInfo Info(Ctx, Status, EvalInfo::EM_IgnoreSideEffects);<br>
+ Info.InConstantContext = true;<br>
+<br>
+ if (!::EvaluateAsInt(this, ExprResult, Ctx, SE_AllowSideEffects, Info))<br>
llvm_unreachable("ICE cannot be evaluated!");<br>
+<br>
+ Value = ExprResult.Val.getInt();<br>
return true;<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Analysis/CFG.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Analysis/CFG.cpp (original)<br>
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Nov 20 15:24:16 2018<br>
@@ -1039,12 +1039,14 @@ private:<br>
if (!areExprTypesCompatible(Expr1, Expr2))<br>
return {};<br>
<br>
- llvm::APSInt L1, L2;<br>
-<br>
- if (!Expr1->EvaluateAsInt(L1, *Context) ||<br>
- !Expr2->EvaluateAsInt(L2, *Context))<br>
+ Expr::EvalResult L1Result, L2Result;<br>
+ if (!Expr1->EvaluateAsInt(L1Result, *Context) ||<br>
+ !Expr2->EvaluateAsInt(L2Result, *Context))<br>
return {};<br>
<br>
+ llvm::APSInt L1 = L1Result.Val.getInt();<br>
+ llvm::APSInt L2 = L2Result.Val.getInt();<br>
+<br>
// Can't compare signed with unsigned or with different bit width.<br>
if (L1.isSigned() != L2.isSigned() || L1.getBitWidth() != L2.getBitWidth())<br>
return {};<br>
@@ -1134,13 +1136,16 @@ private:<br>
case BO_And: {<br>
// If either operand is zero, we know the value<br>
// must be false.<br>
- llvm::APSInt IntVal;<br>
- if (Bop->getLHS()->EvaluateAsInt(IntVal, *Context)) {<br>
+ Expr::EvalResult LHSResult;<br>
+ if (Bop->getLHS()->EvaluateAsInt(LHSResult, *Context)) {<br>
+ llvm::APSInt IntVal = LHSResult.Val.getInt();<br>
if (!IntVal.getBoolValue()) {<br>
return TryResult(false);<br>
}<br>
}<br>
- if (Bop->getRHS()->EvaluateAsInt(IntVal, *Context)) {<br>
+ Expr::EvalResult RHSResult;<br>
+ if (Bop->getRHS()->EvaluateAsInt(RHSResult, *Context)) {<br>
+ llvm::APSInt IntVal = RHSResult.Val.getInt();<br>
if (!IntVal.getBoolValue()) {<br>
return TryResult(false);<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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Nov 20 15:24:16 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>
@@ -2190,10 +2210,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(<br>
<br>
case Builtin::BI__builtin___memcpy_chk: {<br>
// fold __builtin_memcpy_chk(x, y, cst1, cst2) to memcpy iff cst1<=cst2.<br>
- llvm::APSInt Size, DstSize;<br>
- if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||<br>
- !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))<br>
+ Expr::EvalResult SizeResult, DstSizeResult;<br>
+ if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) ||<br>
+ !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext()))<br>
break;<br>
+ llvm::APSInt Size = SizeResult.Val.getInt();<br>
+ llvm::APSInt DstSize = DstSizeResult.Val.getInt();<br>
if (Size.ugt(DstSize))<br>
break;<br>
Address Dest = EmitPointerWithAlignment(E->getArg(0));<br>
@@ -2214,10 +2236,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(<br>
<br>
case Builtin::BI__builtin___memmove_chk: {<br>
// fold __builtin_memmove_chk(x, y, cst1, cst2) to memmove iff cst1<=cst2.<br>
- llvm::APSInt Size, DstSize;<br>
- if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||<br>
- !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))<br>
+ Expr::EvalResult SizeResult, DstSizeResult;<br>
+ if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) ||<br>
+ !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext()))<br>
break;<br>
+ llvm::APSInt Size = SizeResult.Val.getInt();<br>
+ llvm::APSInt DstSize = DstSizeResult.Val.getInt();<br>
if (Size.ugt(DstSize))<br>
break;<br>
Address Dest = EmitPointerWithAlignment(E->getArg(0));<br>
@@ -2252,10 +2276,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(<br>
}<br>
case Builtin::BI__builtin___memset_chk: {<br>
// fold __builtin_memset_chk(x, y, cst1, cst2) to memset iff cst1<=cst2.<br>
- llvm::APSInt Size, DstSize;<br>
- if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||<br>
- !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))<br>
+ Expr::EvalResult SizeResult, DstSizeResult;<br>
+ if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) ||<br>
+ !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext()))<br>
break;<br>
+ llvm::APSInt Size = SizeResult.Val.getInt();<br>
+ llvm::APSInt DstSize = DstSizeResult.Val.getInt();<br>
if (Size.ugt(DstSize))<br>
break;<br>
Address Dest = EmitPointerWithAlignment(E->getArg(0));<br>
@@ -5769,10 +5795,11 @@ Value *CodeGenFunction::EmitARMBuiltinEx<br>
llvm::FunctionType *FTy =<br>
llvm::FunctionType::get(VoidTy, /*Variadic=*/false);<br>
<br>
- APSInt Value;<br>
- if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (!E->getArg(0)->EvaluateAsInt(Result, CGM.getContext()))<br>
llvm_unreachable("Sema will ensure that the parameter is constant");<br>
<br>
+ llvm::APSInt Value = Result.Val.getInt();<br>
uint64_t ZExtValue = Value.zextOrTrunc(IsThumb ? 16 : 32).getZExtValue();<br>
<br>
llvm::InlineAsm *Emit =<br>
@@ -6875,10 +6902,11 @@ Value *CodeGenFunction::EmitAArch64Built<br>
}<br>
<br>
if (BuiltinID == AArch64::BI__getReg) {<br>
- APSInt Value;<br>
- if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (!E->getArg(0)->EvaluateAsInt(Result, CGM.getContext()))<br>
llvm_unreachable("Sema will ensure that the parameter is constant");<br>
<br>
+ llvm::APSInt Value = Result.Val.getInt();<br>
LLVMContext &Context = CGM.getLLVMContext();<br>
std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Nov 20 15:24:16 2018<br>
@@ -2522,9 +2522,9 @@ llvm::DIType *CGDebugInfo::CreateType(co<br>
Count = CAT->getSize().getZExtValue();<br>
else if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {<br>
if (Expr *Size = VAT->getSizeExpr()) {<br>
- llvm::APSInt V;<br>
- if (Size->EvaluateAsInt(V, CGM.getContext()))<br>
- Count = V.getExtValue();<br>
+ Expr::EvalResult Result;<br>
+ if (Size->EvaluateAsInt(Result, CGM.getContext()))<br>
+ Count = Result.Val.getInt().getExtValue();<br>
}<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Nov 20 15:24:16 2018<br>
@@ -1717,8 +1717,9 @@ Value *ScalarExprEmitter::VisitMemberExp<br>
CGF.EmitIgnoredExpr(E->getBase());<br>
return CGF.emitScalarConstant(Constant, E);<br>
} else {<br>
- llvm::APSInt Value;<br>
- if (E->EvaluateAsInt(Value, CGF.getContext(), Expr::SE_AllowSideEffects)) {<br>
+ Expr::EvalResult Result;<br>
+ if (E->EvaluateAsInt(Result, CGF.getContext(), Expr::SE_AllowSideEffects)) {<br>
+ llvm::APSInt Value = Result.Val.getInt();<br>
CGF.EmitIgnoredExpr(E->getBase());<br>
return Builder.getInt(Value);<br>
}<br>
@@ -2597,9 +2598,11 @@ Value *ScalarExprEmitter::VisitUnaryLNot<br>
<br>
Value *ScalarExprEmitter::VisitOffsetOfExpr(OffsetOfExpr *E) {<br>
// Try folding the offsetof to a constant.<br>
- llvm::APSInt Value;<br>
- if (E->EvaluateAsInt(Value, CGF.getContext()))<br>
+ Expr::EvalResult EVResult;<br>
+ if (E->EvaluateAsInt(EVResult, CGF.getContext())) {<br>
+ llvm::APSInt Value = EVResult.Val.getInt();<br>
return Builder.getInt(Value);<br>
+ }<br>
<br>
// Loop over the components of the offsetof to compute the value.<br>
unsigned n = E->getNumComponents();<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Nov 20 15:24:16 2018<br>
@@ -6795,10 +6795,11 @@ private:<br>
}<br>
<br>
// Check if the length evaluates to 1.<br>
- llvm::APSInt ConstLength;<br>
- if (!Length->EvaluateAsInt(ConstLength, CGF.getContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (!Length->EvaluateAsInt(Result, CGF.getContext()))<br>
return true; // Can have more that size 1.<br>
<br>
+ llvm::APSInt ConstLength = Result.Val.getInt();<br>
return ConstLength.getSExtValue() != 1;<br>
}<br>
<br>
@@ -9162,8 +9163,8 @@ void CGOpenMPRuntime::emitDeclareSimdFun<br>
ParamAttrTy &ParamAttr = ParamAttrs[Pos];<br>
ParamAttr.Kind = Linear;<br>
if (*SI) {<br>
- if (!(*SI)->EvaluateAsInt(ParamAttr.StrideOrArg, C,<br>
- Expr::SE_AllowSideEffects)) {<br>
+ Expr::EvalResult Result;<br>
+ if (!(*SI)->EvaluateAsInt(Result, C, Expr::SE_AllowSideEffects)) {<br>
if (const auto *DRE =<br>
cast<DeclRefExpr>((*SI)->IgnoreParenImpCasts())) {<br>
if (const auto *StridePVD = cast<ParmVarDecl>(DRE->getDecl())) {<br>
@@ -9172,6 +9173,8 @@ void CGOpenMPRuntime::emitDeclareSimdFun<br>
ParamPositions[StridePVD->getCanonicalDecl()]);<br>
}<br>
}<br>
+ } else {<br>
+ ParamAttr.StrideOrArg = Result.Val.getInt();<br>
}<br>
}<br>
++SI;<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Tue Nov 20 15:24:16 2018<br>
@@ -1822,9 +1822,9 @@ llvm::Value* CodeGenFunction::EmitAsmInp<br>
// If this can't be a register or memory, i.e., has to be a constant<br>
// (immediate or symbolic), try to emit it as such.<br>
if (!Info.allowsRegister() && !Info.allowsMemory()) {<br>
- llvm::APSInt Result;<br>
+ Expr::EvalResult Result;<br>
if (InputExpr->EvaluateAsInt(Result, getContext()))<br>
- return llvm::ConstantInt::get(getLLVMContext(), Result);<br>
+ return llvm::ConstantInt::get(getLLVMContext(), Result.Val.getInt());<br>
assert(!Info.requiresImmediateConstant() &&<br>
"Required-immediate inlineasm arg isn't constant?");<br>
}<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Nov 20 15:24:16 2018<br>
@@ -2321,9 +2321,11 @@ bool CodeGenFunction::EmitOMPWorksharing<br>
Chunk = EmitScalarConversion(Chunk, ChunkExpr->getType(),<br>
S.getIterationVariable()->getType(),<br>
S.getBeginLoc());<br>
- llvm::APSInt EvaluatedChunk;<br>
- if (ChunkExpr->EvaluateAsInt(EvaluatedChunk, getContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (ChunkExpr->EvaluateAsInt(Result, getContext())) {<br>
+ llvm::APSInt EvaluatedChunk = Result.Val.getInt();<br>
HasChunkSizeOne = (EvaluatedChunk.getLimitedValue() == 1);<br>
+ }<br>
}<br>
const unsigned IVSize = getContext().getTypeSize(IVExpr->getType());<br>
const bool IVSigned = IVExpr->getType()->hasSignedIntegerRepresentation();<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Nov 20 15:24:16 2018<br>
@@ -1513,10 +1513,11 @@ bool CodeGenFunction::ConstantFoldsToSim<br>
bool AllowLabels) {<br>
// FIXME: Rename and handle conversion of other evaluatable things<br>
// to bool.<br>
- llvm::APSInt Int;<br>
- if (!Cond->EvaluateAsInt(Int, getContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (!Cond->EvaluateAsInt(Result, getContext()))<br>
return false; // Not foldable, not integer or not fully evaluatable.<br>
<br>
+ llvm::APSInt Int = Result.Val.getInt();<br>
if (!AllowLabels && CodeGenFunction::ContainsLabel(Cond))<br>
return false; // Contains a label.<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)<br>
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Nov 20 15:24:16 2018<br>
@@ -1309,11 +1309,10 @@ static bool isInLoop(const ASTContext &C<br>
case Stmt::ObjCForCollectionStmtClass:<br>
return true;<br>
case Stmt::DoStmtClass: {<br>
- const Expr *Cond = cast<DoStmt>(S)->getCond();<br>
- llvm::APSInt Val;<br>
- if (!Cond->EvaluateAsInt(Val, Ctx))<br>
+ Expr::EvalResult Result;<br>
+ if (!cast<DoStmt>(S)->getCond()->EvaluateAsInt(Result, Ctx))<br>
return true;<br>
- return Val.getBoolValue();<br>
+ return Result.Val.getInt().getBoolValue();<br>
}<br>
default:<br>
break;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaCast.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Nov 20 15:24:16 2018<br>
@@ -2554,8 +2554,9 @@ void CastOperation::CheckCStyleCast() {<br>
<br>
// OpenCL v2.0 s6.13.10 - Allow casts from '0' to event_t type.<br>
if (Self.getLangOpts().OpenCL && DestType->isEventT()) {<br>
- llvm::APSInt CastInt;<br>
- if (SrcExpr.get()->EvaluateAsInt(CastInt, Self.Context)) {<br>
+ Expr::EvalResult Result;<br>
+ if (SrcExpr.get()->EvaluateAsInt(Result, Self.Context)) {<br>
+ llvm::APSInt CastInt = Result.Val.getInt();<br>
if (0 == CastInt) {<br>
Kind = CK_ZeroToOCLOpaqueType;<br>
return;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Nov 20 15:24:16 2018<br>
@@ -247,13 +247,16 @@ static void SemaBuiltinMemChkCall(Sema &<br>
const Expr *SizeArg = TheCall->getArg(SizeIdx);<br>
const Expr *DstSizeArg = TheCall->getArg(DstSizeIdx);<br>
<br>
- llvm::APSInt Size, DstSize;<br>
+ Expr::EvalResult SizeResult, DstSizeResult;<br>
<br>
// find out if both sizes are known at compile time<br>
- if (!SizeArg->EvaluateAsInt(Size, S.Context) ||<br>
- !DstSizeArg->EvaluateAsInt(DstSize, S.Context))<br>
+ if (!SizeArg->EvaluateAsInt(SizeResult, S.Context) ||<br>
+ !DstSizeArg->EvaluateAsInt(DstSizeResult, S.Context))<br>
return;<br>
<br>
+ llvm::APSInt Size = SizeResult.Val.getInt();<br>
+ llvm::APSInt DstSize = DstSizeResult.Val.getInt();<br>
+<br>
if (Size.ule(DstSize))<br>
return;<br>
<br>
@@ -6483,13 +6486,12 @@ checkFormatStringExpr(Sema &S, const Exp<br>
return SLCT_NotALiteral;<br>
}<br>
case Stmt::BinaryOperatorClass: {<br>
- llvm::APSInt LResult;<br>
- llvm::APSInt RResult;<br>
-<br>
const BinaryOperator *BinOp = cast<BinaryOperator>(E);<br>
<br>
// A string literal + an int offset is still a string literal.<br>
if (BinOp->isAdditiveOp()) {<br>
+ Expr::EvalResult LResult, RResult;<br>
+<br>
bool LIsInt = BinOp->getLHS()->EvaluateAsInt(LResult, S.Context);<br>
bool RIsInt = BinOp->getRHS()->EvaluateAsInt(RResult, S.Context);<br>
<br>
@@ -6498,12 +6500,12 @@ checkFormatStringExpr(Sema &S, const Exp<br>
<br>
if (LIsInt) {<br>
if (BinOpKind == BO_Add) {<br>
- sumOffsets(Offset, LResult, BinOpKind, RIsInt);<br>
+ sumOffsets(Offset, LResult.Val.getInt(), BinOpKind, RIsInt);<br>
E = BinOp->getRHS();<br>
goto tryAgain;<br>
}<br>
} else {<br>
- sumOffsets(Offset, RResult, BinOpKind, RIsInt);<br>
+ sumOffsets(Offset, RResult.Val.getInt(), BinOpKind, RIsInt);<br>
E = BinOp->getLHS();<br>
goto tryAgain;<br>
}<br>
@@ -6516,9 +6518,10 @@ checkFormatStringExpr(Sema &S, const Exp<br>
const UnaryOperator *UnaOp = cast<UnaryOperator>(E);<br>
auto ASE = dyn_cast<ArraySubscriptExpr>(UnaOp->getSubExpr());<br>
if (UnaOp->getOpcode() == UO_AddrOf && ASE) {<br>
- llvm::APSInt IndexResult;<br>
+ Expr::EvalResult IndexResult;<br>
if (ASE->getRHS()->EvaluateAsInt(IndexResult, S.Context)) {<br>
- sumOffsets(Offset, IndexResult, BO_Add, /*RHS is int*/ true);<br>
+ sumOffsets(Offset, IndexResult.Val.getInt(), BO_Add,<br>
+ /*RHS is int*/ true);<br>
E = ASE->getBase();<br>
goto tryAgain;<br>
}<br>
@@ -10263,8 +10266,8 @@ static bool AnalyzeBitFieldAssignment(Se<br>
Expr *OriginalInit = Init->IgnoreParenImpCasts();<br>
unsigned FieldWidth = Bitfield->getBitWidthValue(S.Context);<br>
<br>
- llvm::APSInt Value;<br>
- if (!OriginalInit->EvaluateAsInt(Value, S.Context,<br>
+ Expr::EvalResult Result;<br>
+ if (!OriginalInit->EvaluateAsInt(Result, S.Context,<br>
Expr::SE_AllowSideEffects)) {<br>
// The RHS is not constant. If the RHS has an enum type, make sure the<br>
// bitfield is wide enough to hold all the values of the enum without<br>
@@ -10320,6 +10323,8 @@ static bool AnalyzeBitFieldAssignment(Se<br>
return false;<br>
}<br>
<br>
+ llvm::APSInt Value = Result.Val.getInt();<br>
+<br>
unsigned OriginalWidth = Value.getBitWidth();<br>
<br>
if (!Value.isSigned() || Value.isNegative())<br>
@@ -10932,8 +10937,11 @@ CheckImplicitConversion(Sema &S, Expr *E<br>
if (SourceRange.Width > TargetRange.Width) {<br>
// If the source is a constant, use a default-on diagnostic.<br>
// TODO: this should happen for bitfield stores, too.<br>
- llvm::APSInt Value(32);<br>
- if (E->EvaluateAsInt(Value, S.Context, Expr::SE_AllowSideEffects)) {<br>
+ Expr::EvalResult Result;<br>
+ if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects)) {<br>
+ llvm::APSInt Value(32);<br>
+ Value = Result.Val.getInt();<br>
+<br>
if (S.SourceMgr.isInSystemMacro(CC))<br>
return;<br>
<br>
@@ -10977,9 +10985,10 @@ CheckImplicitConversion(Sema &S, Expr *E<br>
// source value is exactly the width of the target type, which will<br>
// cause a negative value to be stored.<br>
<br>
- llvm::APSInt Value;<br>
- if (E->EvaluateAsInt(Value, S.Context, Expr::SE_AllowSideEffects) &&<br>
+ Expr::EvalResult Result;<br>
+ if (E->EvaluateAsInt(Result, S.Context, Expr::SE_AllowSideEffects) &&<br>
!S.SourceMgr.isInSystemMacro(CC)) {<br>
+ llvm::APSInt Value = Result.Val.getInt();<br>
if (isSameWidthConstantConversion(S, E, T, CC)) {<br>
std::string PrettySourceValue = Value.toString(10);<br>
std::string PrettyTargetValue = PrettyPrintInRange(Value, TargetRange);<br>
@@ -12266,9 +12275,11 @@ void Sema::CheckArrayAccess(const Expr *<br>
if (!ArrayTy)<br>
return;<br>
<br>
- llvm::APSInt index;<br>
- if (!IndexExpr->EvaluateAsInt(index, Context, Expr::SE_AllowSideEffects))<br>
+ Expr::EvalResult Result;<br>
+ if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))<br>
return;<br>
+<br>
+ llvm::APSInt index = Result.Val.getInt();<br>
if (IndexNegated)<br>
index = -index;<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 20 15:24:16 2018<br>
@@ -5575,11 +5575,13 @@ static QualType TryToFixInvalidVariablyM<br>
if (VLATy->getElementType()->isVariablyModifiedType())<br>
return QualType();<br>
<br>
- llvm::APSInt Res;<br>
+ Expr::EvalResult Result;<br>
if (!VLATy->getSizeExpr() ||<br>
- !VLATy->getSizeExpr()->EvaluateAsInt(Res, Context))<br>
+ !VLATy->getSizeExpr()->EvaluateAsInt(Result, Context))<br>
return QualType();<br>
<br>
+ llvm::APSInt Res = Result.Val.getInt();<br>
+<br>
// Check whether the array size is negative.<br>
if (Res.isSigned() && Res.isNegative()) {<br>
SizeIsNegative = true;<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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Nov 20 15:24:16 2018<br>
@@ -13860,6 +13860,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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Nov 20 15:24:16 2018<br>
@@ -4376,10 +4376,11 @@ ExprResult Sema::ActOnOMPArraySectionExp<br>
return ExprError();<br>
<br>
if (LowerBound && !OriginalTy->isAnyPointerType()) {<br>
- llvm::APSInt LowerBoundValue;<br>
- if (LowerBound->EvaluateAsInt(LowerBoundValue, Context)) {<br>
+ Expr::EvalResult Result;<br>
+ if (LowerBound->EvaluateAsInt(Result, Context)) {<br>
// OpenMP 4.5, [2.4 Array Sections]<br>
// The array section must be a subset of the original array.<br>
+ llvm::APSInt LowerBoundValue = Result.Val.getInt();<br>
if (LowerBoundValue.isNegative()) {<br>
Diag(LowerBound->getExprLoc(), diag::err_omp_section_not_subset_of_array)<br>
<< LowerBound->getSourceRange();<br>
@@ -4389,10 +4390,11 @@ ExprResult Sema::ActOnOMPArraySectionExp<br>
}<br>
<br>
if (Length) {<br>
- llvm::APSInt LengthValue;<br>
- if (Length->EvaluateAsInt(LengthValue, Context)) {<br>
+ Expr::EvalResult Result;<br>
+ if (Length->EvaluateAsInt(Result, Context)) {<br>
// OpenMP 4.5, [2.4 Array Sections]<br>
// The length must evaluate to non-negative integers.<br>
+ llvm::APSInt LengthValue = Result.Val.getInt();<br>
if (LengthValue.isNegative()) {<br>
Diag(Length->getExprLoc(), diag::err_omp_section_length_negative)<br>
<< LengthValue.toString(/*Radix=*/10, /*Signed=*/true)<br>
@@ -5795,6 +5797,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 +5807,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>
@@ -8399,8 +8402,8 @@ static bool canConvertIntToOtherIntTy(Se<br>
// Reject cases where the value of the Int is unknown as that would<br>
// possibly cause truncation, but accept cases where the scalar can be<br>
// demoted without loss of precision.<br>
- llvm::APSInt Result;<br>
- bool CstInt = Int->get()->EvaluateAsInt(Result, S.Context);<br>
+ Expr::EvalResult EVResult;<br>
+ bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.Context);<br>
int Order = S.Context.getIntegerTypeOrder(OtherIntTy, IntTy);<br>
bool IntSigned = IntTy->hasSignedIntegerRepresentation();<br>
bool OtherIntSigned = OtherIntTy->hasSignedIntegerRepresentation();<br>
@@ -8408,6 +8411,7 @@ static bool canConvertIntToOtherIntTy(Se<br>
if (CstInt) {<br>
// If the scalar is constant and is of a higher order and has more active<br>
// bits that the vector element type, reject it.<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
unsigned NumBits = IntSigned<br>
? (Result.isNegative() ? Result.getMinSignedBits()<br>
: Result.getActiveBits())<br>
@@ -8435,8 +8439,9 @@ static bool canConvertIntTyToFloatTy(Sem<br>
<br>
// Determine if the integer constant can be expressed as a floating point<br>
// number of the appropriate type.<br>
- llvm::APSInt Result;<br>
- bool CstInt = Int->get()->EvaluateAsInt(Result, S.Context);<br>
+ Expr::EvalResult EVResult;<br>
+ bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.Context);<br>
+<br>
uint64_t Bits = 0;<br>
if (CstInt) {<br>
// Reject constants that would be truncated if they were converted to<br>
@@ -8444,6 +8449,7 @@ static bool canConvertIntTyToFloatTy(Sem<br>
// FIXME: Ideally the conversion to an APFloat and from an APFloat<br>
// could be avoided if there was a convertFromAPInt method<br>
// which could signal back if implicit truncation occurred.<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
llvm::APFloat Float(S.Context.getFloatTypeSemantics(FloatTy));<br>
Float.convertFromAPInt(Result, IntTy->hasSignedIntegerRepresentation(),<br>
llvm::APFloat::rmTowardZero);<br>
@@ -8783,9 +8789,10 @@ static void DiagnoseBadDivideOrRemainder<br>
ExprResult &RHS,<br>
SourceLocation Loc, bool IsDiv) {<br>
// Check for division/remainder by zero.<br>
- llvm::APSInt RHSValue;<br>
+ Expr::EvalResult RHSValue;<br>
if (!RHS.get()->isValueDependent() &&<br>
- RHS.get()->EvaluateAsInt(RHSValue, S.Context) && RHSValue == 0)<br>
+ RHS.get()->EvaluateAsInt(RHSValue, S.Context) &&<br>
+ RHSValue.Val.getInt() == 0)<br>
S.DiagRuntimeBehavior(Loc, RHS.get(),<br>
S.PDiag(diag::warn_remainder_division_by_zero)<br>
<< IsDiv << RHS.get()->getSourceRange());<br>
@@ -9027,8 +9034,9 @@ static void diagnoseStringPlusInt(Sema &<br>
if (!IsStringPlusInt || IndexExpr->isValueDependent())<br>
return;<br>
<br>
- llvm::APSInt index;<br>
- if (IndexExpr->EvaluateAsInt(index, Self.getASTContext())) {<br>
+ Expr::EvalResult Result;<br>
+ if (IndexExpr->EvaluateAsInt(Result, Self.getASTContext())) {<br>
+ llvm::APSInt index = Result.Val.getInt();<br>
unsigned StrLenWithNull = StrExpr->getLength() + 1;<br>
if (index.isNonNegative() &&<br>
index <= llvm::APSInt(llvm::APInt(index.getBitWidth(), StrLenWithNull),<br>
@@ -9172,10 +9180,11 @@ QualType Sema::CheckAdditionOperands(Exp<br>
if (PExp->IgnoreParenCasts()->isNullPointerConstant(<br>
Context, Expr::NPC_ValueDependentIsNotNull)) {<br>
// In C++ adding zero to a null pointer is defined.<br>
- llvm::APSInt KnownVal;<br>
+ Expr::EvalResult KnownVal;<br>
if (!getLangOpts().CPlusPlus ||<br>
(!IExp->isValueDependent() &&<br>
- (!IExp->EvaluateAsInt(KnownVal, Context) || KnownVal != 0))) {<br>
+ (!IExp->EvaluateAsInt(KnownVal, Context) ||<br>
+ KnownVal.Val.getInt() != 0))) {<br>
// Check the conditions to see if this is the 'p = nullptr + n' idiom.<br>
bool IsGNUIdiom = BinaryOperator::isNullPointerArithmeticExtension(<br>
Context, BO_Add, PExp, IExp);<br>
@@ -9250,10 +9259,11 @@ QualType Sema::CheckSubtractionOperands(<br>
if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant(Context,<br>
Expr::NPC_ValueDependentIsNotNull)) {<br>
// In C++ adding zero to a null pointer is defined.<br>
- llvm::APSInt KnownVal;<br>
+ Expr::EvalResult KnownVal;<br>
if (!getLangOpts().CPlusPlus ||<br>
(!RHS.get()->isValueDependent() &&<br>
- (!RHS.get()->EvaluateAsInt(KnownVal, Context) || KnownVal != 0))) {<br>
+ (!RHS.get()->EvaluateAsInt(KnownVal, Context) ||<br>
+ KnownVal.Val.getInt() != 0))) {<br>
diagnoseArithmeticOnNullPointer(*this, Loc, LHS.get(), false);<br>
}<br>
}<br>
@@ -9329,11 +9339,12 @@ static void DiagnoseBadShiftValues(Sema&<br>
if (S.getLangOpts().OpenCL)<br>
return;<br>
<br>
- llvm::APSInt Right;<br>
// Check right/shifter operand<br>
+ Expr::EvalResult RHSResult;<br>
if (RHS.get()->isValueDependent() ||<br>
- !RHS.get()->EvaluateAsInt(Right, S.Context))<br>
+ !RHS.get()->EvaluateAsInt(RHSResult, S.Context))<br>
return;<br>
+ llvm::APSInt Right = RHSResult.Val.getInt();<br>
<br>
if (Right.isNegative()) {<br>
S.DiagRuntimeBehavior(Loc, RHS.get(),<br>
@@ -9356,11 +9367,12 @@ static void DiagnoseBadShiftValues(Sema&<br>
// according to C++ has undefined behavior ([expr.shift] 5.8/2). Unsigned<br>
// integers have defined behavior modulo one more than the maximum value<br>
// representable in the result type, so never warn for those.<br>
- llvm::APSInt Left;<br>
+ Expr::EvalResult LHSResult;<br>
if (LHS.get()->isValueDependent() ||<br>
LHSType->hasUnsignedIntegerRepresentation() ||<br>
- !LHS.get()->EvaluateAsInt(Left, S.Context))<br>
+ !LHS.get()->EvaluateAsInt(LHSResult, S.Context))<br>
return;<br>
+ llvm::APSInt Left = LHSResult.Val.getInt();<br>
<br>
// If LHS does not have a signed type and non-negative value<br>
// then, the behavior is undefined. Warn about it.<br>
@@ -10730,8 +10742,9 @@ inline QualType Sema::CheckLogicalOperan<br>
// that isn't 0 or 1 (which indicate a potential logical operation that<br>
// happened to fold to true/false) then warn.<br>
// Parens on the RHS are ignored.<br>
- llvm::APSInt Result;<br>
- if (RHS.get()->EvaluateAsInt(Result, Context))<br>
+ Expr::EvalResult EVResult;<br>
+ if (RHS.get()->EvaluateAsInt(EVResult, Context)) {<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&<br>
!RHS.get()->getExprLoc().isMacroID()) ||<br>
(Result != 0 && Result != 1)) {<br>
@@ -10751,6 +10764,7 @@ inline QualType Sema::CheckLogicalOperan<br>
SourceRange(getLocForEndOfToken(LHS.get()->getEndLoc()),<br>
RHS.get()->getEndLoc()));<br>
}<br>
+ }<br>
}<br>
<br>
if (!Context.getLangOpts().CPlusPlus) {<br>
@@ -14166,12 +14180,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>
@@ -14189,7 +14206,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>
@@ -14217,7 +14234,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/SemaInit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Nov 20 15:24:16 2018<br>
@@ -8050,8 +8050,9 @@ ExprResult InitializationSequence::Perfo<br>
break;<br>
}<br>
<br>
- llvm::APSInt Result;<br>
- Init->EvaluateAsInt(Result, S.Context);<br>
+ Expr::EvalResult EVResult;<br>
+ Init->EvaluateAsInt(EVResult, S.Context);<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
const uint64_t SamplerValue = Result.getLimitedValue();<br>
// 32-bit value of sampler's initializer is interpreted as<br>
// bit-field with the following structure:<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Nov 20 15:24:16 2018<br>
@@ -5020,15 +5020,16 @@ checkOpenMPLoop(OpenMPDirectiveKind DKin<br>
unsigned NestedLoopCount = 1;<br>
if (CollapseLoopCountExpr) {<br>
// Found 'collapse' clause - calculate collapse number.<br>
- llvm::APSInt Result;<br>
+ Expr::EvalResult Result;<br>
if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))<br>
- NestedLoopCount = Result.getLimitedValue();<br>
+ NestedLoopCount = Result.Val.getInt().getLimitedValue();<br>
}<br>
unsigned OrderedLoopCount = 1;<br>
if (OrderedLoopCountExpr) {<br>
// Found 'ordered' clause - calculate collapse number.<br>
- llvm::APSInt Result;<br>
- if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) {<br>
+ Expr::EvalResult EVResult;<br>
+ if (OrderedLoopCountExpr->EvaluateAsInt(EVResult, SemaRef.getASTContext())) {<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
if (Result.getLimitedValue() < NestedLoopCount) {<br>
SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),<br>
diag::err_omp_wrong_ordered_loop_count)<br>
@@ -5624,7 +5625,6 @@ static bool checkSimdlenSafelenSpecified<br>
}<br>
<br>
if (Simdlen && Safelen) {<br>
- llvm::APSInt SimdlenRes, SafelenRes;<br>
const Expr *SimdlenLength = Simdlen->getSimdlen();<br>
const Expr *SafelenLength = Safelen->getSafelen();<br>
if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() ||<br>
@@ -5635,8 +5635,11 @@ static bool checkSimdlenSafelenSpecified<br>
SafelenLength->isInstantiationDependent() ||<br>
SafelenLength->containsUnexpandedParameterPack())<br>
return false;<br>
- SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context);<br>
- SafelenLength->EvaluateAsInt(SafelenRes, S.Context);<br>
+ Expr::EvalResult SimdlenResult, SafelenResult;<br>
+ SimdlenLength->EvaluateAsInt(SimdlenResult, S.Context);<br>
+ SafelenLength->EvaluateAsInt(SafelenResult, S.Context);<br>
+ llvm::APSInt SimdlenRes = SimdlenResult.Val.getInt();<br>
+ llvm::APSInt SafelenRes = SafelenResult.Val.getInt();<br>
// OpenMP 4.5 [2.8.1, simd Construct, Restrictions]<br>
// If both simdlen and safelen clauses are specified, the value of the<br>
// simdlen parameter must be less than or equal to the value of the safelen<br>
@@ -10641,10 +10644,11 @@ static bool checkOMPArraySectionConstant<br>
SingleElement = true;<br>
ArraySizes.push_back(llvm::APSInt::get(1));<br>
} else {<br>
- llvm::APSInt ConstantLengthValue;<br>
- if (!Length->EvaluateAsInt(ConstantLengthValue, Context))<br>
+ Expr::EvalResult Result;<br>
+ if (!Length->EvaluateAsInt(Result, Context))<br>
return false;<br>
<br>
+ llvm::APSInt ConstantLengthValue = Result.Val.getInt();<br>
SingleElement = (ConstantLengthValue.getSExtValue() == 1);<br>
ArraySizes.push_back(ConstantLengthValue);<br>
}<br>
@@ -10665,9 +10669,12 @@ static bool checkOMPArraySectionConstant<br>
// This is an array subscript which has implicit length 1!<br>
ArraySizes.push_back(llvm::APSInt::get(1));<br>
} else {<br>
- llvm::APSInt ConstantLengthValue;<br>
- if (!Length->EvaluateAsInt(ConstantLengthValue, Context) ||<br>
- ConstantLengthValue.getSExtValue() != 1)<br>
+ Expr::EvalResult Result;<br>
+ if (!Length->EvaluateAsInt(Result, Context))<br>
+ return false;<br>
+<br>
+ llvm::APSInt ConstantLengthValue = Result.Val.getInt();<br>
+ if (ConstantLengthValue.getSExtValue() != 1)<br>
return false;<br>
<br>
ArraySizes.push_back(ConstantLengthValue);<br>
@@ -12190,9 +12197,11 @@ static bool checkArrayExpressionDoesNotR<br>
// If there is a lower bound that does not evaluates to zero, we are not<br>
// covering the whole dimension.<br>
if (LowerBound) {<br>
- llvm::APSInt ConstLowerBound;<br>
- if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (!LowerBound->EvaluateAsInt(Result, SemaRef.getASTContext()))<br>
return false; // Can't get the integer value as a constant.<br>
+<br>
+ llvm::APSInt ConstLowerBound = Result.Val.getInt();<br>
if (ConstLowerBound.getSExtValue())<br>
return true;<br>
}<br>
@@ -12212,10 +12221,11 @@ static bool checkArrayExpressionDoesNotR<br>
if (!CATy)<br>
return false;<br>
<br>
- llvm::APSInt ConstLength;<br>
- if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext()))<br>
return false; // Can't get the integer value as a constant.<br>
<br>
+ llvm::APSInt ConstLength = Result.Val.getInt();<br>
return CATy->getSize().getSExtValue() != ConstLength.getSExtValue();<br>
}<br>
<br>
@@ -12246,10 +12256,11 @@ static bool checkArrayExpressionDoesNotR<br>
}<br>
<br>
// Check if the length evaluates to 1.<br>
- llvm::APSInt ConstLength;<br>
- if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext()))<br>
+ Expr::EvalResult Result;<br>
+ if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext()))<br>
return false; // Can't get the integer value as a constant.<br>
<br>
+ llvm::APSInt ConstLength = Result.Val.getInt();<br>
return ConstLength.getSExtValue() != 1;<br>
}<br>
<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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Nov 20 15:24:16 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/SemaStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Nov 20 15:24:16 2018<br>
@@ -945,8 +945,11 @@ Sema::ActOnFinishSwitchStmt(SourceLocati<br>
llvm::APSInt ConstantCondValue;<br>
bool HasConstantCond = false;<br>
if (!HasDependentValue && !TheDefaultStmt) {<br>
- HasConstantCond = CondExpr->EvaluateAsInt(ConstantCondValue, Context,<br>
+ Expr::EvalResult Result;<br>
+ HasConstantCond = CondExpr->EvaluateAsInt(Result, Context,<br>
Expr::SE_AllowSideEffects);<br>
+ if (Result.Val.isInt())<br>
+ ConstantCondValue = Result.Val.getInt();<br>
assert(!HasConstantCond ||<br>
(ConstantCondValue.getBitWidth() == CondWidth &&<br>
ConstantCondValue.isSigned() == CondIsSigned));<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Tue Nov 20 15:24:16 2018<br>
@@ -378,11 +378,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL<br>
<< InputExpr->getSourceRange());<br>
} else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {<br>
if (!InputExpr->isValueDependent()) {<br>
- llvm::APSInt Result;<br>
- if (!InputExpr->EvaluateAsInt(Result, Context))<br>
+ Expr::EvalResult EVResult;<br>
+ if (!InputExpr->EvaluateAsInt(EVResult, Context))<br>
return StmtError(<br>
Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)<br>
<< Info.getConstraintStr() << InputExpr->getSourceRange());<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
if (!Info.isValidAsmImmediate(Result))<br>
return StmtError(Diag(InputExpr->getBeginLoc(),<br>
diag::err_invalid_asm_value_for_constraint)<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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Nov 20 15:24:16 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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Nov 20 15:24:16 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/Checkers/BuiltinFunctionChecker.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp Tue Nov 20 15:24:16 2018<br>
@@ -101,9 +101,10 @@ bool BuiltinFunctionChecker::evalCall(co<br>
// This must be resolvable at compile time, so we defer to the constant<br>
// evaluator for a value.<br>
SVal V = UnknownVal();<br>
- llvm::APSInt Result;<br>
- if (CE->EvaluateAsInt(Result, C.getASTContext(), Expr::SE_NoSideEffects)) {<br>
+ Expr::EvalResult EVResult;<br>
+ if (CE->EvaluateAsInt(EVResult, C.getASTContext(), Expr::SE_NoSideEffects)) {<br>
// Make sure the result has the correct type.<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
SValBuilder &SVB = C.getSValBuilder();<br>
BasicValueFactory &BVF = SVB.getBasicValueFactory();<br>
BVF.getAPSIntType(CE->getType()).apply(Result);<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp Tue Nov 20 15:24:16 2018<br>
@@ -597,9 +597,10 @@ void WalkAST::checkCall_mkstemp(const Ca<br>
unsigned suffix = 0;<br>
if (ArgSuffix.second >= 0) {<br>
const Expr *suffixEx = CE->getArg((unsigned)ArgSuffix.second);<br>
- llvm::APSInt Result;<br>
- if (!suffixEx->EvaluateAsInt(Result, BR.getContext()))<br>
+ Expr::EvalResult EVResult;<br>
+ if (!suffixEx->EvaluateAsInt(EVResult, BR.getContext()))<br>
return;<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
// FIXME: Issue a warning.<br>
if (Result.isNegative())<br>
return;<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp Tue Nov 20 15:24:16 2018<br>
@@ -135,9 +135,9 @@ private:<br>
bool isIntZeroExpr(const Expr *E) const {<br>
if (!E->getType()->isIntegralOrEnumerationType())<br>
return false;<br>
- llvm::APSInt Result;<br>
+ Expr::EvalResult Result;<br>
if (E->EvaluateAsInt(Result, Context))<br>
- return Result == 0;<br>
+ return Result.Val.getInt() == 0;<br>
return false;<br>
}<br>
<br>
@@ -191,8 +191,11 @@ private:<br>
if (const BinaryOperator *BOp = dyn_cast<BinaryOperator>(rhse)) {<br>
if (BOp->getOpcode() == BO_Div) {<br>
const Expr *denom = BOp->getRHS()->IgnoreParenImpCasts();<br>
- if (denom->EvaluateAsInt(denomVal, Context))<br>
+ Expr::EvalResult Result;<br>
+ if (denom->EvaluateAsInt(Result, Context)) {<br>
+ denomVal = Result.Val.getInt();<br>
denomKnown = true;<br>
+ }<br>
const Expr *numerator = BOp->getLHS()->IgnoreParenImpCasts();<br>
if (numerator->isEvaluatable(Context))<br>
numeratorKnown = true;<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp Tue Nov 20 15:24:16 2018<br>
@@ -87,9 +87,10 @@ void Callback::run(const MatchFinder::Ma<br>
MacroIndicatesWeShouldSkipTheCheck = true;<br>
}<br>
if (!MacroIndicatesWeShouldSkipTheCheck) {<br>
- llvm::APSInt Result;<br>
+ Expr::EvalResult EVResult;<br>
if (CheckIfNull->IgnoreParenCasts()->EvaluateAsInt(<br>
- Result, ACtx, Expr::SE_AllowSideEffects)) {<br>
+ EVResult, ACtx, Expr::SE_AllowSideEffects)) {<br>
+ llvm::APSInt Result = EVResult.Val.getInt();<br>
if (Result == 0) {<br>
if (!C->Pedantic)<br>
return;<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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Nov 20 15:24:16 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/lib/StaticAnalyzer/Core/ExprEngineC.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Tue Nov 20 15:24:16 2018<br>
@@ -810,8 +810,9 @@ void ExprEngine::<br>
VisitOffsetOfExpr(const OffsetOfExpr *OOE,<br>
ExplodedNode *Pred, ExplodedNodeSet &Dst) {<br>
StmtNodeBuilder B(Pred, Dst, *currBldrCtx);<br>
- APSInt IV;<br>
- if (OOE->EvaluateAsInt(IV, getContext())) {<br>
+ Expr::EvalResult Result;<br>
+ if (OOE->EvaluateAsInt(Result, getContext())) {<br>
+ APSInt IV = Result.Val.getInt();<br>
assert(IV.getBitWidth() == getContext().getTypeSize(OOE->getType()));<br>
assert(OOE->getType()->isBuiltinType());<br>
assert(OOE->getType()->getAs<BuiltinType>()->isInteger());<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp Tue Nov 20 15:24:16 2018<br>
@@ -362,9 +362,9 @@ Optional<SVal> SValBuilder::getConstantV<br>
return None;<br>
<br>
ASTContext &Ctx = getContext();<br>
- llvm::APSInt Result;<br>
+ Expr::EvalResult Result;<br>
if (E->EvaluateAsInt(Result, Ctx))<br>
- return makeIntVal(Result);<br>
+ return makeIntVal(Result.Val.getInt());<br>
<br>
if (Loc::isLocType(E->getType()))<br>
if (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))<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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-functions.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/builtin-functions.cpp (original)<br>
+++ cfe/trunk/test/Analysis/builtin-functions.cpp Tue Nov 20 15:24:16 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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/builtins.c (original)<br>
+++ cfe/trunk/test/Sema/builtins.c Tue Nov 20 15:24:16 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=347364&r1=347363&r2=347364&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compound-literal.cpp?rev=347364&r1=347363&r2=347364&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/compound-literal.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/compound-literal.cpp Tue Nov 20 15:24:16 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>
</blockquote></div></div>