r347417 - Re-Reinstate 347294 with a fix for the failures.
Bill Wendling via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 27 11:56:58 PST 2018
For reference, this is what I get:
[morbo at fawn:llvm] llvm.obj/bin/clang -o - -emit-llvm -O2 t.i -S
; ModuleID = 't.i'
source_filename = "t.i"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@arr = dso_local local_unnamed_addr global [3 x i32] [i32 1, i32 2, i32 3],
align 4
@str = private unnamed_addr constant [31 x i8] c"(b - a) non-const or
non-zero!\00", align 1
@str.2 = private unnamed_addr constant [27 x i8] c"(b - a) is a constant
zero\00", align 1
; Function Attrs: nounwind uwtable
define dso_local void @f(i32* %a, i32* %b) local_unnamed_addr #0 {
entry:
%sub.ptr.lhs.cast = ptrtoint i32* %b to i64
%sub.ptr.rhs.cast = ptrtoint i32* %a to i64
%sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
%sub.ptr.div = ashr exact i64 %sub.ptr.sub, 2
%0 = tail call i1 @llvm.is.constant.i64(i64 %sub.ptr.div)
%.not = xor i1 %0, true
%tobool = icmp eq i64 %sub.ptr.sub, 0
%or.cond = or i1 %tobool, %.not
br i1 %or.cond, label %if.then, label %if.else
if.then: ; preds = %entry
%puts = tail call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x
i8]* @str, i64 0, i64 0))
br label %if.end
if.else: ; preds = %entry
%puts8 = tail call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x
i8]* @str.2, i64 0, i64 0))
br label %if.end
if.end: ; preds = %if.else,
%if.then
ret void
}
; Function Attrs: nounwind readnone
declare i1 @llvm.is.constant.i64(i64) #1
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
entry:
%puts8.i = tail call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27
x i8]* @str.2, i64 0, i64 0)) #2
ret i32 0
}
; Function Attrs: nounwind
declare i32 @puts(i8* nocapture readonly) local_unnamed_addr #2
attributes #0 = { nounwind uwtable
"correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"min-legal-vector-width"="0" "no-frame-pointer-elim"="false"
"no-infs-fp-math"="false" "no-jump-tables"="false"
"no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false"
"no-trapping-math"="false" "stack-protector-buffer-size"="8"
"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone }
attributes #2 = { nounwind }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 8.0.0 (trunk) (llvm/trunk 347690)"}
[morbo at fawn:llvm] llvm.obj/bin/clang -o - -O2 t.i -S
.text
.file "t.i"
.globl f # -- Begin function f
.p2align 4, 0x90
.type f, at function
f: # @f
.cfi_startproc
# %bb.0: # %entry
movl $.Lstr, %edi
jmp puts # TAILCALL
.Lfunc_end0:
.size f, .Lfunc_end0-f
.cfi_endproc
# -- End function
.globl main # -- Begin function main
.p2align 4, 0x90
.type main, at function
main: # @main
.cfi_startproc
# %bb.0: # %entry
pushq %rax
.cfi_def_cfa_offset 16
movl $.Lstr.2, %edi
callq puts
xorl %eax, %eax
popq %rcx
.cfi_def_cfa_offset 8
retq
.Lfunc_end1:
.size main, .Lfunc_end1-main
.cfi_endproc
# -- End function
.type arr, at object # @arr
.data
.globl arr
.p2align 2
arr:
.long 1 # 0x1
.long 2 # 0x2
.long 3 # 0x3
.size arr, 12
.type .Lstr, at object # @str
.section .rodata.str1.1,"aMS", at progbits,1
.Lstr:
.asciz "(b - a) non-const or non-zero!"
.size .Lstr, 31
.type .Lstr.2, at object # @str.2
.Lstr.2:
.asciz "(b - a) is a constant zero"
.size .Lstr.2, 27
.ident "clang version 8.0.0 (trunk) (llvm/trunk 347690)"
.section ".note.GNU-stack","", at progbits
.addrsig
On Tue, Nov 27, 2018 at 11:56 AM Bill Wendling <isanbard at gmail.com> wrote:
> I'm not able to reproduce the error with ToT. Please give me a testcase
> that fails with ToT + my patches that you reverted.
>
> -bw
>
> On Tue, Nov 27, 2018 at 6:05 AM Hans Wennborg <hwennborg at google.com>
> wrote:
>
>> I've reverted this and the follow-ups in r347656 and included a
>> reduced repro for the miscompile.
>>
>> On Tue, Nov 27, 2018 at 11:36 AM, Hans Wennborg <hwennborg at google.com>
>> wrote:
>> > We're hitting test failures due to this in Chromium:
>> > https://crbug.com/908372 I'm still not sure what's going on, just
>> > wanted to give a heads up in case someone else is seeing issues.
>> >
>> > On Wed, Nov 21, 2018 at 9:44 PM, Bill Wendling via cfe-commits
>> > <cfe-commits at lists.llvm.org> wrote:
>> >> Author: void
>> >> Date: Wed Nov 21 12:44:18 2018
>> >> New Revision: 347417
>> >>
>> >> URL: http://llvm.org/viewvc/llvm-project?rev=347417&view=rev
>> >> Log:
>> >> Re-Reinstate 347294 with a fix for the failures.
>> >>
>> >> Don't try to emit a scalar expression for a non-scalar argument to
>> >> __builtin_constant_p().
>> >>
>> >> Third time's a charm!
>> >>
>> >> Added:
>> >> cfe/trunk/test/CodeGenCXX/builtin-constant-p.cpp
>> >> Modified:
>> >> cfe/trunk/include/clang/AST/Expr.h
>> >> cfe/trunk/lib/AST/ASTImporter.cpp
>> >> cfe/trunk/lib/AST/Expr.cpp
>> >> cfe/trunk/lib/AST/ExprConstant.cpp
>> >> cfe/trunk/lib/Analysis/CFG.cpp
>> >> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>> >> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> >> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>> >> cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>> >> cfe/trunk/lib/CodeGen/CGStmt.cpp
>> >> cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
>> >> cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
>> >> cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>> >> cfe/trunk/lib/Sema/SemaCast.cpp
>> >> cfe/trunk/lib/Sema/SemaChecking.cpp
>> >> cfe/trunk/lib/Sema/SemaDecl.cpp
>> >> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> >> cfe/trunk/lib/Sema/SemaExpr.cpp
>> >> cfe/trunk/lib/Sema/SemaInit.cpp
>> >> cfe/trunk/lib/Sema/SemaOpenMP.cpp
>> >> cfe/trunk/lib/Sema/SemaOverload.cpp
>> >> cfe/trunk/lib/Sema/SemaStmt.cpp
>> >> cfe/trunk/lib/Sema/SemaStmtAsm.cpp
>> >> cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
>> >> cfe/trunk/lib/Sema/SemaType.cpp
>> >> cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
>> >> cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
>> >>
>> cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
>> >>
>> cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
>> >> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>> >> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
>> >> cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
>> >> cfe/trunk/test/Analysis/builtin-functions.cpp
>> >> cfe/trunk/test/Sema/builtins.c
>> >> cfe/trunk/test/SemaCXX/compound-literal.cpp
>> >>
>> >> Modified: cfe/trunk/include/clang/AST/Expr.h
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/include/clang/AST/Expr.h (original)
>> >> +++ cfe/trunk/include/clang/AST/Expr.h Wed Nov 21 12:44:18 2018
>> >> @@ -600,7 +600,7 @@ public:
>> >>
>> >> /// EvaluateAsInt - Return true if this is a constant which we can
>> fold and
>> >> /// convert to an integer, using any crazy technique that we want
>> to.
>> >> - bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
>> >> + bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
>> >> SideEffectsKind AllowSideEffects =
>> SE_NoSideEffects) const;
>> >>
>> >> /// EvaluateAsFloat - Return true if this is a constant which we
>> can fold and
>> >> @@ -901,10 +901,15 @@ public:
>> >>
>> >> /// ConstantExpr - An expression that occurs in a constant context.
>> >> class ConstantExpr : public FullExpr {
>> >> -public:
>> >> ConstantExpr(Expr *subexpr)
>> >> : FullExpr(ConstantExprClass, subexpr) {}
>> >>
>> >> +public:
>> >> + static ConstantExpr *Create(const ASTContext &Context, Expr *E) {
>> >> + assert(!isa<ConstantExpr>(E));
>> >> + return new (Context) ConstantExpr(E);
>> >> + }
>> >> +
>> >> /// Build an empty constant expression wrapper.
>> >> explicit ConstantExpr(EmptyShell Empty)
>> >> : FullExpr(ConstantExprClass, Empty) {}
>> >> @@ -3087,8 +3092,8 @@ inline Expr *Expr::IgnoreImpCasts() {
>> >> while (true)
>> >> if (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
>> >> e = ice->getSubExpr();
>> >> - else if (ConstantExpr *ce = dyn_cast<ConstantExpr>(e))
>> >> - e = ce->getSubExpr();
>> >> + else if (FullExpr *fe = dyn_cast<FullExpr>(e))
>> >> + e = fe->getSubExpr();
>> >> else
>> >> break;
>> >> return e;
>> >>
>> >> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
>> >> +++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -6380,7 +6380,7 @@ ExpectedStmt ASTNodeImporter::VisitConst
>> >> Expr *ToSubExpr;
>> >> std::tie(ToSubExpr) = *Imp;
>> >>
>> >> - return new (Importer.getToContext()) ConstantExpr(ToSubExpr);
>> >> + return ConstantExpr::Create(Importer.getToContext(), ToSubExpr);
>> >> }
>> >>
>> >> ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) {
>> >>
>> >> Modified: cfe/trunk/lib/AST/Expr.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/AST/Expr.cpp (original)
>> >> +++ cfe/trunk/lib/AST/Expr.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -2594,8 +2594,8 @@ Expr *Expr::IgnoreParenCasts() {
>> >> E = NTTP->getReplacement();
>> >> continue;
>> >> }
>> >> - if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
>> >> - E = CE->getSubExpr();
>> >> + if (FullExpr *FE = dyn_cast<FullExpr>(E)) {
>> >> + E = FE->getSubExpr();
>> >> continue;
>> >> }
>> >> return E;
>> >> @@ -2619,8 +2619,8 @@ Expr *Expr::IgnoreCasts() {
>> >> E = NTTP->getReplacement();
>> >> continue;
>> >> }
>> >> - if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
>> >> - E = CE->getSubExpr();
>> >> + if (FullExpr *FE = dyn_cast<FullExpr>(E)) {
>> >> + E = FE->getSubExpr();
>> >> continue;
>> >> }
>> >> return E;
>> >> @@ -2648,8 +2648,8 @@ Expr *Expr::IgnoreParenLValueCasts() {
>> >> =
>> dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
>> >> E = NTTP->getReplacement();
>> >> continue;
>> >> - } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
>> >> - E = CE->getSubExpr();
>> >> + } else if (FullExpr *FE = dyn_cast<FullExpr>(E)) {
>> >> + E = FE->getSubExpr();
>> >> continue;
>> >> }
>> >> break;
>> >> @@ -2920,6 +2920,12 @@ bool Expr::isConstantInitializer(ASTCont
>> >>
>> >> break;
>> >> }
>> >> + case ConstantExprClass: {
>> >> + // FIXME: We should be able to return "true" here, but it can
>> lead to extra
>> >> + // error messages. E.g. in Sema/array-init.c.
>> >> + const Expr *Exp = cast<ConstantExpr>(this)->getSubExpr();
>> >> + return Exp->isConstantInitializer(Ctx, false, Culprit);
>> >> + }
>> >> case CompoundLiteralExprClass: {
>> >> // This handles gcc's extension that allows global initializers
>> like
>> >> // "struct x {int x;} x = (struct x) {};".
>> >> @@ -2959,8 +2965,8 @@ bool Expr::isConstantInitializer(ASTCont
>> >> const Expr *Elt = ILE->getInit(ElementNo++);
>> >> if (Field->isBitField()) {
>> >> // Bitfields have to evaluate to an integer.
>> >> - llvm::APSInt ResultTmp;
>> >> - if (!Elt->EvaluateAsInt(ResultTmp, Ctx)) {
>> >> + EvalResult Result;
>> >> + if (!Elt->EvaluateAsInt(Result, Ctx)) {
>> >> if (Culprit)
>> >> *Culprit = Elt;
>> >> return false;
>> >>
>> >> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>> >> +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -45,6 +45,7 @@
>> >> #include "clang/AST/TypeLoc.h"
>> >> #include "clang/Basic/Builtins.h"
>> >> #include "clang/Basic/TargetInfo.h"
>> >> +#include "llvm/Support/SaveAndRestore.h"
>> >> #include "llvm/Support/raw_ostream.h"
>> >> #include <cstring>
>> >> #include <functional>
>> >> @@ -721,6 +722,10 @@ namespace {
>> >> /// Whether or not we're currently speculatively evaluating.
>> >> bool IsSpeculativelyEvaluating;
>> >>
>> >> + /// Whether or not we're in a context where the front end
>> requires a
>> >> + /// constant value.
>> >> + bool InConstantContext;
>> >> +
>> >> enum EvaluationMode {
>> >> /// Evaluate as a constant expression. Stop if we find that the
>> expression
>> >> /// is not a constant expression.
>> >> @@ -782,7 +787,7 @@ namespace {
>> >> EvaluatingDecl((const ValueDecl *)nullptr),
>> >> EvaluatingDeclValue(nullptr), HasActiveDiagnostic(false),
>> >> HasFoldFailureDiagnostic(false),
>> IsSpeculativelyEvaluating(false),
>> >> - EvalMode(Mode) {}
>> >> + InConstantContext(false), EvalMode(Mode) {}
>> >>
>> >> void setEvaluatingDecl(APValue::LValueBase Base, APValue &Value) {
>> >> EvaluatingDecl = Base;
>> >> @@ -5625,8 +5630,10 @@ static bool getBytesReturnedByAllocSizeC
>> >> return false;
>> >>
>> >> auto EvaluateAsSizeT = [&](const Expr *E, APSInt &Into) {
>> >> - if (!E->EvaluateAsInt(Into, Ctx, Expr::SE_AllowSideEffects))
>> >> + Expr::EvalResult ExprResult;
>> >> + if (!E->EvaluateAsInt(ExprResult, Ctx, Expr::SE_AllowSideEffects))
>> >> return false;
>> >> + Into = ExprResult.Val.getInt();
>> >> if (Into.isNegative() || !Into.isIntN(BitsInSizeT))
>> >> return false;
>> >> Into = Into.zextOrSelf(BitsInSizeT);
>> >> @@ -7348,6 +7355,8 @@ public:
>> >> // Visitor Methods
>> >>
>> //===--------------------------------------------------------------------===//
>> >>
>> >> + bool VisitConstantExpr(const ConstantExpr *E);
>> >> +
>> >> bool VisitIntegerLiteral(const IntegerLiteral *E) {
>> >> return Success(E->getValue(), E);
>> >> }
>> >> @@ -8088,6 +8097,11 @@ static bool tryEvaluateBuiltinObjectSize
>> >> return true;
>> >> }
>> >>
>> >> +bool IntExprEvaluator::VisitConstantExpr(const ConstantExpr *E) {
>> >> + llvm::SaveAndRestore<bool>
>> InConstantContext(Info.InConstantContext, true);
>> >> + return ExprEvaluatorBaseTy::VisitConstantExpr(E);
>> >> +}
>> >> +
>> >> bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
>> >> if (unsigned BuiltinOp = E->getBuiltinCallee())
>> >> return VisitBuiltinCallExpr(E, BuiltinOp);
>> >> @@ -8175,8 +8189,20 @@ bool IntExprEvaluator::VisitBuiltinCallE
>> >> return Success(Val.countLeadingZeros(), E);
>> >> }
>> >>
>> >> - case Builtin::BI__builtin_constant_p:
>> >> - return Success(EvaluateBuiltinConstantP(Info.Ctx, E->getArg(0)),
>> E);
>> >> + case Builtin::BI__builtin_constant_p: {
>> >> + auto Arg = E->getArg(0);
>> >> + if (EvaluateBuiltinConstantP(Info.Ctx, Arg))
>> >> + return Success(true, E);
>> >> + auto ArgTy = Arg->IgnoreImplicit()->getType();
>> >> + if (!Info.InConstantContext && !Arg->HasSideEffects(Info.Ctx) &&
>> >> + !ArgTy->isAggregateType() && !ArgTy->isPointerType()) {
>> >> + // We can delay calculation of __builtin_constant_p until after
>> >> + // inlining. Note: This diagnostic won't be shown to the user.
>> >> + Info.FFDiag(E, diag::note_invalid_subexpr_in_const_expr);
>> >> + return false;
>> >> + }
>> >> + return Success(false, E);
>> >> + }
>> >>
>> >> case Builtin::BI__builtin_ctz:
>> >> case Builtin::BI__builtin_ctzl:
>> >> @@ -10746,6 +10772,35 @@ static bool FastEvaluateAsRValue(const E
>> >> return false;
>> >> }
>> >>
>> >> +static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result,
>> >> + Expr::SideEffectsKind SEK) {
>> >> + return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) ||
>> >> + (SEK < Expr::SE_AllowUndefinedBehavior &&
>> Result.HasUndefinedBehavior);
>> >> +}
>> >> +
>> >> +static bool EvaluateAsRValue(const Expr *E, Expr::EvalResult &Result,
>> >> + const ASTContext &Ctx, EvalInfo &Info) {
>> >> + bool IsConst;
>> >> + if (FastEvaluateAsRValue(E, Result, Ctx, IsConst))
>> >> + return IsConst;
>> >> +
>> >> + return EvaluateAsRValue(Info, E, Result.Val);
>> >> +}
>> >> +
>> >> +static bool EvaluateAsInt(const Expr *E, Expr::EvalResult &ExprResult,
>> >> + const ASTContext &Ctx,
>> >> + Expr::SideEffectsKind AllowSideEffects,
>> >> + EvalInfo &Info) {
>> >> + if (!E->getType()->isIntegralOrEnumerationType())
>> >> + return false;
>> >> +
>> >> + if (!::EvaluateAsRValue(E, ExprResult, Ctx, Info) ||
>> >> + !ExprResult.Val.isInt() ||
>> >> + hasUnacceptableSideEffect(ExprResult, AllowSideEffects))
>> >> + return false;
>> >> +
>> >> + return true;
>> >> +}
>> >>
>> >> /// EvaluateAsRValue - Return true if this is a constant which we can
>> fold using
>> >> /// any crazy technique (that has nothing to do with language
>> standards) that
>> >> @@ -10753,12 +10808,8 @@ static bool FastEvaluateAsRValue(const E
>> >> /// in Result. If this expression is a glvalue, an lvalue-to-rvalue
>> conversion
>> >> /// will be applied to the result.
>> >> bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext
>> &Ctx) const {
>> >> - bool IsConst;
>> >> - if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
>> >> - return IsConst;
>> >> -
>> >> EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
>> >> - return ::EvaluateAsRValue(Info, this, Result.Val);
>> >> + return ::EvaluateAsRValue(this, Result, Ctx, Info);
>> >> }
>> >>
>> >> bool Expr::EvaluateAsBooleanCondition(bool &Result,
>> >> @@ -10768,24 +10819,10 @@ bool Expr::EvaluateAsBooleanCondition(bo
>> >> HandleConversionToBool(Scratch.Val, Result);
>> >> }
>> >>
>> >> -static bool hasUnacceptableSideEffect(Expr::EvalStatus &Result,
>> >> - Expr::SideEffectsKind SEK) {
>> >> - return (SEK < Expr::SE_AllowSideEffects && Result.HasSideEffects) ||
>> >> - (SEK < Expr::SE_AllowUndefinedBehavior &&
>> Result.HasUndefinedBehavior);
>> >> -}
>> >> -
>> >> -bool Expr::EvaluateAsInt(APSInt &Result, const ASTContext &Ctx,
>> >> +bool Expr::EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
>> >> SideEffectsKind AllowSideEffects) const {
>> >> - if (!getType()->isIntegralOrEnumerationType())
>> >> - return false;
>> >> -
>> >> - EvalResult ExprResult;
>> >> - if (!EvaluateAsRValue(ExprResult, Ctx) || !ExprResult.Val.isInt() ||
>> >> - hasUnacceptableSideEffect(ExprResult, AllowSideEffects))
>> >> - return false;
>> >> -
>> >> - Result = ExprResult.Val.getInt();
>> >> - return true;
>> >> + EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
>> >> + return ::EvaluateAsInt(this, Result, Ctx, AllowSideEffects, Info);
>> >> }
>> >>
>> >> bool Expr::EvaluateAsFloat(APFloat &Result, const ASTContext &Ctx,
>> >> @@ -10878,35 +10915,40 @@ bool Expr::isEvaluatable(const ASTContex
>> >>
>> >> APSInt Expr::EvaluateKnownConstInt(const ASTContext &Ctx,
>> >> SmallVectorImpl<PartialDiagnosticAt> *Diag) const
>> {
>> >> - EvalResult EvalResult;
>> >> - EvalResult.Diag = Diag;
>> >> - bool Result = EvaluateAsRValue(EvalResult, Ctx);
>> >> + EvalResult EVResult;
>> >> + EVResult.Diag = Diag;
>> >> + EvalInfo Info(Ctx, EVResult, EvalInfo::EM_IgnoreSideEffects);
>> >> + Info.InConstantContext = true;
>> >> +
>> >> + bool Result = ::EvaluateAsRValue(this, EVResult, Ctx, Info);
>> >> (void)Result;
>> >> assert(Result && "Could not evaluate expression");
>> >> - assert(EvalResult.Val.isInt() && "Expression did not evaluate to
>> integer");
>> >> + assert(EVResult.Val.isInt() && "Expression did not evaluate to
>> integer");
>> >>
>> >> - return EvalResult.Val.getInt();
>> >> + return EVResult.Val.getInt();
>> >> }
>> >>
>> >> APSInt Expr::EvaluateKnownConstIntCheckOverflow(
>> >> const ASTContext &Ctx, SmallVectorImpl<PartialDiagnosticAt>
>> *Diag) const {
>> >> - EvalResult EvalResult;
>> >> - EvalResult.Diag = Diag;
>> >> - EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow);
>> >> - bool Result = ::EvaluateAsRValue(Info, this, EvalResult.Val);
>> >> + EvalResult EVResult;
>> >> + EVResult.Diag = Diag;
>> >> + EvalInfo Info(Ctx, EVResult, EvalInfo::EM_EvaluateForOverflow);
>> >> + Info.InConstantContext = true;
>> >> +
>> >> + bool Result = ::EvaluateAsRValue(Info, this, EVResult.Val);
>> >> (void)Result;
>> >> assert(Result && "Could not evaluate expression");
>> >> - assert(EvalResult.Val.isInt() && "Expression did not evaluate to
>> integer");
>> >> + assert(EVResult.Val.isInt() && "Expression did not evaluate to
>> integer");
>> >>
>> >> - return EvalResult.Val.getInt();
>> >> + return EVResult.Val.getInt();
>> >> }
>> >>
>> >> void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
>> >> bool IsConst;
>> >> - EvalResult EvalResult;
>> >> - if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) {
>> >> - EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow);
>> >> - (void)::EvaluateAsRValue(Info, this, EvalResult.Val);
>> >> + EvalResult EVResult;
>> >> + if (!FastEvaluateAsRValue(this, EVResult, Ctx, IsConst)) {
>> >> + EvalInfo Info(Ctx, EVResult, EvalInfo::EM_EvaluateForOverflow);
>> >> + (void)::EvaluateAsRValue(Info, this, EVResult.Val);
>> >> }
>> >> }
>> >>
>> >> @@ -10959,7 +11001,11 @@ static ICEDiag Worst(ICEDiag A, ICEDiag
>> >>
>> >> static ICEDiag CheckEvalInICE(const Expr* E, const ASTContext &Ctx) {
>> >> Expr::EvalResult EVResult;
>> >> - if (!E->EvaluateAsRValue(EVResult, Ctx) || EVResult.HasSideEffects
>> ||
>> >> + Expr::EvalStatus Status;
>> >> + EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);
>> >> +
>> >> + Info.InConstantContext = true;
>> >> + if (!::EvaluateAsRValue(E, EVResult, Ctx, Info) ||
>> EVResult.HasSideEffects ||
>> >> !EVResult.Val.isInt())
>> >> return ICEDiag(IK_NotICE, E->getBeginLoc());
>> >>
>> >> @@ -11397,12 +11443,20 @@ bool Expr::isIntegerConstantExpr(llvm::A
>> >>
>> >> if (!isIntegerConstantExpr(Ctx, Loc))
>> >> return false;
>> >> +
>> >> // The only possible side-effects here are due to UB discovered in
>> the
>> >> // evaluation (for instance, INT_MAX + 1). In such a case, we are
>> still
>> >> // required to treat the expression as an ICE, so we produce the
>> folded
>> >> // value.
>> >> - if (!EvaluateAsInt(Value, Ctx, SE_AllowSideEffects))
>> >> + EvalResult ExprResult;
>> >> + Expr::EvalStatus Status;
>> >> + EvalInfo Info(Ctx, Status, EvalInfo::EM_IgnoreSideEffects);
>> >> + Info.InConstantContext = true;
>> >> +
>> >> + if (!::EvaluateAsInt(this, ExprResult, Ctx, SE_AllowSideEffects,
>> Info))
>> >> llvm_unreachable("ICE cannot be evaluated!");
>> >> +
>> >> + Value = ExprResult.Val.getInt();
>> >> return true;
>> >> }
>> >>
>> >>
>> >> Modified: cfe/trunk/lib/Analysis/CFG.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Analysis/CFG.cpp (original)
>> >> +++ cfe/trunk/lib/Analysis/CFG.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -1039,12 +1039,14 @@ private:
>> >> if (!areExprTypesCompatible(Expr1, Expr2))
>> >> return {};
>> >>
>> >> - llvm::APSInt L1, L2;
>> >> -
>> >> - if (!Expr1->EvaluateAsInt(L1, *Context) ||
>> >> - !Expr2->EvaluateAsInt(L2, *Context))
>> >> + Expr::EvalResult L1Result, L2Result;
>> >> + if (!Expr1->EvaluateAsInt(L1Result, *Context) ||
>> >> + !Expr2->EvaluateAsInt(L2Result, *Context))
>> >> return {};
>> >>
>> >> + llvm::APSInt L1 = L1Result.Val.getInt();
>> >> + llvm::APSInt L2 = L2Result.Val.getInt();
>> >> +
>> >> // Can't compare signed with unsigned or with different bit width.
>> >> if (L1.isSigned() != L2.isSigned() || L1.getBitWidth() !=
>> L2.getBitWidth())
>> >> return {};
>> >> @@ -1134,13 +1136,16 @@ private:
>> >> case BO_And: {
>> >> // If either operand is zero, we know the value
>> >> // must be false.
>> >> - llvm::APSInt IntVal;
>> >> - if (Bop->getLHS()->EvaluateAsInt(IntVal, *Context)) {
>> >> + Expr::EvalResult LHSResult;
>> >> + if (Bop->getLHS()->EvaluateAsInt(LHSResult, *Context)) {
>> >> + llvm::APSInt IntVal = LHSResult.Val.getInt();
>> >> if (!IntVal.getBoolValue()) {
>> >> return TryResult(false);
>> >> }
>> >> }
>> >> - if (Bop->getRHS()->EvaluateAsInt(IntVal, *Context)) {
>> >> + Expr::EvalResult RHSResult;
>> >> + if (Bop->getRHS()->EvaluateAsInt(RHSResult, *Context)) {
>> >> + llvm::APSInt IntVal = RHSResult.Val.getInt();
>> >> if (!IntVal.getBoolValue()) {
>> >> return TryResult(false);
>> >> }
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -1926,6 +1926,26 @@ RValue CodeGenFunction::EmitBuiltinExpr(
>> >> case Builtin::BI__builtin_rotateright64:
>> >> return emitRotate(E, true);
>> >>
>> >> + case Builtin::BI__builtin_constant_p: {
>> >> + llvm::Type *ResultType = ConvertType(E->getType());
>> >> + if (CGM.getCodeGenOpts().OptimizationLevel == 0)
>> >> + // At -O0, we don't perform inlining, so we don't need to delay
>> the
>> >> + // processing.
>> >> + return RValue::get(ConstantInt::get(ResultType, 0));
>> >> +
>> >> + const Expr *Arg = E->getArg(0);
>> >> + QualType ArgType = Arg->getType();
>> >> + if (!hasScalarEvaluationKind(ArgType))
>> >> + // We can only reason about scalar types.
>> >> + return RValue::get(ConstantInt::get(ResultType, 0));
>> >> +
>> >> + Value *ArgValue = EmitScalarExpr(Arg);
>> >> + Value *F = CGM.getIntrinsic(Intrinsic::is_constant,
>> ConvertType(ArgType));
>> >> + Value *Result = Builder.CreateCall(F, ArgValue);
>> >> + if (Result->getType() != ResultType)
>> >> + Result = Builder.CreateIntCast(Result, ResultType,
>> /*isSigned*/true);
>> >> + return RValue::get(Result);
>> >> + }
>> >> case Builtin::BI__builtin_object_size: {
>> >> unsigned Type =
>> >>
>> E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue();
>> >> @@ -2190,10 +2210,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(
>> >>
>> >> case Builtin::BI__builtin___memcpy_chk: {
>> >> // fold __builtin_memcpy_chk(x, y, cst1, cst2) to memcpy iff
>> cst1<=cst2.
>> >> - llvm::APSInt Size, DstSize;
>> >> - if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||
>> >> - !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))
>> >> + Expr::EvalResult SizeResult, DstSizeResult;
>> >> + if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) ||
>> >> + !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext()))
>> >> break;
>> >> + llvm::APSInt Size = SizeResult.Val.getInt();
>> >> + llvm::APSInt DstSize = DstSizeResult.Val.getInt();
>> >> if (Size.ugt(DstSize))
>> >> break;
>> >> Address Dest = EmitPointerWithAlignment(E->getArg(0));
>> >> @@ -2214,10 +2236,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(
>> >>
>> >> case Builtin::BI__builtin___memmove_chk: {
>> >> // fold __builtin_memmove_chk(x, y, cst1, cst2) to memmove iff
>> cst1<=cst2.
>> >> - llvm::APSInt Size, DstSize;
>> >> - if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||
>> >> - !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))
>> >> + Expr::EvalResult SizeResult, DstSizeResult;
>> >> + if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) ||
>> >> + !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext()))
>> >> break;
>> >> + llvm::APSInt Size = SizeResult.Val.getInt();
>> >> + llvm::APSInt DstSize = DstSizeResult.Val.getInt();
>> >> if (Size.ugt(DstSize))
>> >> break;
>> >> Address Dest = EmitPointerWithAlignment(E->getArg(0));
>> >> @@ -2252,10 +2276,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(
>> >> }
>> >> case Builtin::BI__builtin___memset_chk: {
>> >> // fold __builtin_memset_chk(x, y, cst1, cst2) to memset iff
>> cst1<=cst2.
>> >> - llvm::APSInt Size, DstSize;
>> >> - if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||
>> >> - !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))
>> >> + Expr::EvalResult SizeResult, DstSizeResult;
>> >> + if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) ||
>> >> + !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext()))
>> >> break;
>> >> + llvm::APSInt Size = SizeResult.Val.getInt();
>> >> + llvm::APSInt DstSize = DstSizeResult.Val.getInt();
>> >> if (Size.ugt(DstSize))
>> >> break;
>> >> Address Dest = EmitPointerWithAlignment(E->getArg(0));
>> >> @@ -5769,10 +5795,11 @@ Value *CodeGenFunction::EmitARMBuiltinEx
>> >> llvm::FunctionType *FTy =
>> >> llvm::FunctionType::get(VoidTy, /*Variadic=*/false);
>> >>
>> >> - APSInt Value;
>> >> - if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (!E->getArg(0)->EvaluateAsInt(Result, CGM.getContext()))
>> >> llvm_unreachable("Sema will ensure that the parameter is
>> constant");
>> >>
>> >> + llvm::APSInt Value = Result.Val.getInt();
>> >> uint64_t ZExtValue = Value.zextOrTrunc(IsThumb ? 16 :
>> 32).getZExtValue();
>> >>
>> >> llvm::InlineAsm *Emit =
>> >> @@ -6875,10 +6902,11 @@ Value *CodeGenFunction::EmitAArch64Built
>> >> }
>> >>
>> >> if (BuiltinID == AArch64::BI__getReg) {
>> >> - APSInt Value;
>> >> - if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (!E->getArg(0)->EvaluateAsInt(Result, CGM.getContext()))
>> >> llvm_unreachable("Sema will ensure that the parameter is
>> constant");
>> >>
>> >> + llvm::APSInt Value = Result.Val.getInt();
>> >> LLVMContext &Context = CGM.getLLVMContext();
>> >> std::string Reg = Value == 31 ? "sp" : "x" + Value.toString(10);
>> >>
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -2522,9 +2522,9 @@ llvm::DIType *CGDebugInfo::CreateType(co
>> >> Count = CAT->getSize().getZExtValue();
>> >> else if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
>> >> if (Expr *Size = VAT->getSizeExpr()) {
>> >> - llvm::APSInt V;
>> >> - if (Size->EvaluateAsInt(V, CGM.getContext()))
>> >> - Count = V.getExtValue();
>> >> + Expr::EvalResult Result;
>> >> + if (Size->EvaluateAsInt(Result, CGM.getContext()))
>> >> + Count = Result.Val.getInt().getExtValue();
>> >> }
>> >> }
>> >>
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -1717,8 +1717,9 @@ Value *ScalarExprEmitter::VisitMemberExp
>> >> CGF.EmitIgnoredExpr(E->getBase());
>> >> return CGF.emitScalarConstant(Constant, E);
>> >> } else {
>> >> - llvm::APSInt Value;
>> >> - if (E->EvaluateAsInt(Value, CGF.getContext(),
>> Expr::SE_AllowSideEffects)) {
>> >> + Expr::EvalResult Result;
>> >> + if (E->EvaluateAsInt(Result, CGF.getContext(),
>> Expr::SE_AllowSideEffects)) {
>> >> + llvm::APSInt Value = Result.Val.getInt();
>> >> CGF.EmitIgnoredExpr(E->getBase());
>> >> return Builder.getInt(Value);
>> >> }
>> >> @@ -2597,9 +2598,11 @@ Value *ScalarExprEmitter::VisitUnaryLNot
>> >>
>> >> Value *ScalarExprEmitter::VisitOffsetOfExpr(OffsetOfExpr *E) {
>> >> // Try folding the offsetof to a constant.
>> >> - llvm::APSInt Value;
>> >> - if (E->EvaluateAsInt(Value, CGF.getContext()))
>> >> + Expr::EvalResult EVResult;
>> >> + if (E->EvaluateAsInt(EVResult, CGF.getContext())) {
>> >> + llvm::APSInt Value = EVResult.Val.getInt();
>> >> return Builder.getInt(Value);
>> >> + }
>> >>
>> >> // Loop over the components of the offsetof to compute the value.
>> >> unsigned n = E->getNumComponents();
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -6795,10 +6795,11 @@ private:
>> >> }
>> >>
>> >> // Check if the length evaluates to 1.
>> >> - llvm::APSInt ConstLength;
>> >> - if (!Length->EvaluateAsInt(ConstLength, CGF.getContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (!Length->EvaluateAsInt(Result, CGF.getContext()))
>> >> return true; // Can have more that size 1.
>> >>
>> >> + llvm::APSInt ConstLength = Result.Val.getInt();
>> >> return ConstLength.getSExtValue() != 1;
>> >> }
>> >>
>> >> @@ -9162,8 +9163,8 @@ void CGOpenMPRuntime::emitDeclareSimdFun
>> >> ParamAttrTy &ParamAttr = ParamAttrs[Pos];
>> >> ParamAttr.Kind = Linear;
>> >> if (*SI) {
>> >> - if (!(*SI)->EvaluateAsInt(ParamAttr.StrideOrArg, C,
>> >> - Expr::SE_AllowSideEffects)) {
>> >> + Expr::EvalResult Result;
>> >> + if (!(*SI)->EvaluateAsInt(Result, C,
>> Expr::SE_AllowSideEffects)) {
>> >> if (const auto *DRE =
>> >> cast<DeclRefExpr>((*SI)->IgnoreParenImpCasts())) {
>> >> if (const auto *StridePVD =
>> cast<ParmVarDecl>(DRE->getDecl())) {
>> >> @@ -9172,6 +9173,8 @@ void CGOpenMPRuntime::emitDeclareSimdFun
>> >> ParamPositions[StridePVD->getCanonicalDecl()]);
>> >> }
>> >> }
>> >> + } else {
>> >> + ParamAttr.StrideOrArg = Result.Val.getInt();
>> >> }
>> >> }
>> >> ++SI;
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -1822,9 +1822,9 @@ llvm::Value* CodeGenFunction::EmitAsmInp
>> >> // If this can't be a register or memory, i.e., has to be a constant
>> >> // (immediate or symbolic), try to emit it as such.
>> >> if (!Info.allowsRegister() && !Info.allowsMemory()) {
>> >> - llvm::APSInt Result;
>> >> + Expr::EvalResult Result;
>> >> if (InputExpr->EvaluateAsInt(Result, getContext()))
>> >> - return llvm::ConstantInt::get(getLLVMContext(), Result);
>> >> + return llvm::ConstantInt::get(getLLVMContext(),
>> Result.Val.getInt());
>> >> assert(!Info.requiresImmediateConstant() &&
>> >> "Required-immediate inlineasm arg isn't constant?");
>> >> }
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -2321,9 +2321,11 @@ bool CodeGenFunction::EmitOMPWorksharing
>> >> Chunk = EmitScalarConversion(Chunk, ChunkExpr->getType(),
>> >>
>> S.getIterationVariable()->getType(),
>> >> S.getBeginLoc());
>> >> - llvm::APSInt EvaluatedChunk;
>> >> - if (ChunkExpr->EvaluateAsInt(EvaluatedChunk, getContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (ChunkExpr->EvaluateAsInt(Result, getContext())) {
>> >> + llvm::APSInt EvaluatedChunk = Result.Val.getInt();
>> >> HasChunkSizeOne = (EvaluatedChunk.getLimitedValue() == 1);
>> >> + }
>> >> }
>> >> const unsigned IVSize =
>> getContext().getTypeSize(IVExpr->getType());
>> >> const bool IVSigned =
>> IVExpr->getType()->hasSignedIntegerRepresentation();
>> >>
>> >> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
>> >> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -1513,10 +1513,11 @@ bool CodeGenFunction::ConstantFoldsToSim
>> >> bool AllowLabels) {
>> >> // FIXME: Rename and handle conversion of other evaluatable things
>> >> // to bool.
>> >> - llvm::APSInt Int;
>> >> - if (!Cond->EvaluateAsInt(Int, getContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (!Cond->EvaluateAsInt(Result, getContext()))
>> >> return false; // Not foldable, not integer or not fully
>> evaluatable.
>> >>
>> >> + llvm::APSInt Int = Result.Val.getInt();
>> >> if (!AllowLabels && CodeGenFunction::ContainsLabel(Cond))
>> >> return false; // Contains a label.
>> >>
>> >>
>> >> Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Nov 21 12:44:18
>> 2018
>> >> @@ -1309,11 +1309,10 @@ static bool isInLoop(const ASTContext &C
>> >> case Stmt::ObjCForCollectionStmtClass:
>> >> return true;
>> >> case Stmt::DoStmtClass: {
>> >> - const Expr *Cond = cast<DoStmt>(S)->getCond();
>> >> - llvm::APSInt Val;
>> >> - if (!Cond->EvaluateAsInt(Val, Ctx))
>> >> + Expr::EvalResult Result;
>> >> + if (!cast<DoStmt>(S)->getCond()->EvaluateAsInt(Result, Ctx))
>> >> return true;
>> >> - return Val.getBoolValue();
>> >> + return Result.Val.getInt().getBoolValue();
>> >> }
>> >> default:
>> >> break;
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaCast.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -2554,8 +2554,9 @@ void CastOperation::CheckCStyleCast() {
>> >>
>> >> // OpenCL v2.0 s6.13.10 - Allow casts from '0' to event_t type.
>> >> if (Self.getLangOpts().OpenCL && DestType->isEventT()) {
>> >> - llvm::APSInt CastInt;
>> >> - if (SrcExpr.get()->EvaluateAsInt(CastInt, Self.Context)) {
>> >> + Expr::EvalResult Result;
>> >> + if (SrcExpr.get()->EvaluateAsInt(Result, Self.Context)) {
>> >> + llvm::APSInt CastInt = Result.Val.getInt();
>> >> if (0 == CastInt) {
>> >> Kind = CK_ZeroToOCLOpaqueType;
>> >> return;
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -247,13 +247,16 @@ static void SemaBuiltinMemChkCall(Sema &
>> >> const Expr *SizeArg = TheCall->getArg(SizeIdx);
>> >> const Expr *DstSizeArg = TheCall->getArg(DstSizeIdx);
>> >>
>> >> - llvm::APSInt Size, DstSize;
>> >> + Expr::EvalResult SizeResult, DstSizeResult;
>> >>
>> >> // find out if both sizes are known at compile time
>> >> - if (!SizeArg->EvaluateAsInt(Size, S.Context) ||
>> >> - !DstSizeArg->EvaluateAsInt(DstSize, S.Context))
>> >> + if (!SizeArg->EvaluateAsInt(SizeResult, S.Context) ||
>> >> + !DstSizeArg->EvaluateAsInt(DstSizeResult, S.Context))
>> >> return;
>> >>
>> >> + llvm::APSInt Size = SizeResult.Val.getInt();
>> >> + llvm::APSInt DstSize = DstSizeResult.Val.getInt();
>> >> +
>> >> if (Size.ule(DstSize))
>> >> return;
>> >>
>> >> @@ -6483,13 +6486,12 @@ checkFormatStringExpr(Sema &S, const Exp
>> >> return SLCT_NotALiteral;
>> >> }
>> >> case Stmt::BinaryOperatorClass: {
>> >> - llvm::APSInt LResult;
>> >> - llvm::APSInt RResult;
>> >> -
>> >> const BinaryOperator *BinOp = cast<BinaryOperator>(E);
>> >>
>> >> // A string literal + an int offset is still a string literal.
>> >> if (BinOp->isAdditiveOp()) {
>> >> + Expr::EvalResult LResult, RResult;
>> >> +
>> >> bool LIsInt = BinOp->getLHS()->EvaluateAsInt(LResult,
>> S.Context);
>> >> bool RIsInt = BinOp->getRHS()->EvaluateAsInt(RResult,
>> S.Context);
>> >>
>> >> @@ -6498,12 +6500,12 @@ checkFormatStringExpr(Sema &S, const Exp
>> >>
>> >> if (LIsInt) {
>> >> if (BinOpKind == BO_Add) {
>> >> - sumOffsets(Offset, LResult, BinOpKind, RIsInt);
>> >> + sumOffsets(Offset, LResult.Val.getInt(), BinOpKind,
>> RIsInt);
>> >> E = BinOp->getRHS();
>> >> goto tryAgain;
>> >> }
>> >> } else {
>> >> - sumOffsets(Offset, RResult, BinOpKind, RIsInt);
>> >> + sumOffsets(Offset, RResult.Val.getInt(), BinOpKind, RIsInt);
>> >> E = BinOp->getLHS();
>> >> goto tryAgain;
>> >> }
>> >> @@ -6516,9 +6518,10 @@ checkFormatStringExpr(Sema &S, const Exp
>> >> const UnaryOperator *UnaOp = cast<UnaryOperator>(E);
>> >> auto ASE = dyn_cast<ArraySubscriptExpr>(UnaOp->getSubExpr());
>> >> if (UnaOp->getOpcode() == UO_AddrOf && ASE) {
>> >> - llvm::APSInt IndexResult;
>> >> + Expr::EvalResult IndexResult;
>> >> if (ASE->getRHS()->EvaluateAsInt(IndexResult, S.Context)) {
>> >> - sumOffsets(Offset, IndexResult, BO_Add, /*RHS is int*/ true);
>> >> + sumOffsets(Offset, IndexResult.Val.getInt(), BO_Add,
>> >> + /*RHS is int*/ true);
>> >> E = ASE->getBase();
>> >> goto tryAgain;
>> >> }
>> >> @@ -10263,8 +10266,8 @@ static bool AnalyzeBitFieldAssignment(Se
>> >> Expr *OriginalInit = Init->IgnoreParenImpCasts();
>> >> unsigned FieldWidth = Bitfield->getBitWidthValue(S.Context);
>> >>
>> >> - llvm::APSInt Value;
>> >> - if (!OriginalInit->EvaluateAsInt(Value, S.Context,
>> >> + Expr::EvalResult Result;
>> >> + if (!OriginalInit->EvaluateAsInt(Result, S.Context,
>> >> Expr::SE_AllowSideEffects)) {
>> >> // The RHS is not constant. If the RHS has an enum type, make
>> sure the
>> >> // bitfield is wide enough to hold all the values of the enum
>> without
>> >> @@ -10320,6 +10323,8 @@ static bool AnalyzeBitFieldAssignment(Se
>> >> return false;
>> >> }
>> >>
>> >> + llvm::APSInt Value = Result.Val.getInt();
>> >> +
>> >> unsigned OriginalWidth = Value.getBitWidth();
>> >>
>> >> if (!Value.isSigned() || Value.isNegative())
>> >> @@ -10932,8 +10937,11 @@ CheckImplicitConversion(Sema &S, Expr *E
>> >> if (SourceRange.Width > TargetRange.Width) {
>> >> // If the source is a constant, use a default-on diagnostic.
>> >> // TODO: this should happen for bitfield stores, too.
>> >> - llvm::APSInt Value(32);
>> >> - if (E->EvaluateAsInt(Value, S.Context,
>> Expr::SE_AllowSideEffects)) {
>> >> + Expr::EvalResult Result;
>> >> + if (E->EvaluateAsInt(Result, S.Context,
>> Expr::SE_AllowSideEffects)) {
>> >> + llvm::APSInt Value(32);
>> >> + Value = Result.Val.getInt();
>> >> +
>> >> if (S.SourceMgr.isInSystemMacro(CC))
>> >> return;
>> >>
>> >> @@ -10977,9 +10985,10 @@ CheckImplicitConversion(Sema &S, Expr *E
>> >> // source value is exactly the width of the target type, which
>> will
>> >> // cause a negative value to be stored.
>> >>
>> >> - llvm::APSInt Value;
>> >> - if (E->EvaluateAsInt(Value, S.Context, Expr::SE_AllowSideEffects)
>> &&
>> >> + Expr::EvalResult Result;
>> >> + if (E->EvaluateAsInt(Result, S.Context,
>> Expr::SE_AllowSideEffects) &&
>> >> !S.SourceMgr.isInSystemMacro(CC)) {
>> >> + llvm::APSInt Value = Result.Val.getInt();
>> >> if (isSameWidthConstantConversion(S, E, T, CC)) {
>> >> std::string PrettySourceValue = Value.toString(10);
>> >> std::string PrettyTargetValue = PrettyPrintInRange(Value,
>> TargetRange);
>> >> @@ -12266,9 +12275,11 @@ void Sema::CheckArrayAccess(const Expr *
>> >> if (!ArrayTy)
>> >> return;
>> >>
>> >> - llvm::APSInt index;
>> >> - if (!IndexExpr->EvaluateAsInt(index, Context,
>> Expr::SE_AllowSideEffects))
>> >> + Expr::EvalResult Result;
>> >> + if (!IndexExpr->EvaluateAsInt(Result, Context,
>> Expr::SE_AllowSideEffects))
>> >> return;
>> >> +
>> >> + llvm::APSInt index = Result.Val.getInt();
>> >> if (IndexNegated)
>> >> index = -index;
>> >>
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -5575,11 +5575,13 @@ static QualType TryToFixInvalidVariablyM
>> >> if (VLATy->getElementType()->isVariablyModifiedType())
>> >> return QualType();
>> >>
>> >> - llvm::APSInt Res;
>> >> + Expr::EvalResult Result;
>> >> if (!VLATy->getSizeExpr() ||
>> >> - !VLATy->getSizeExpr()->EvaluateAsInt(Res, Context))
>> >> + !VLATy->getSizeExpr()->EvaluateAsInt(Result, Context))
>> >> return QualType();
>> >>
>> >> + llvm::APSInt Res = Result.Val.getInt();
>> >> +
>> >> // Check whether the array size is negative.
>> >> if (Res.isSigned() && Res.isNegative()) {
>> >> SizeIsNegative = true;
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -13860,6 +13860,8 @@ Decl *Sema::BuildStaticAssertDeclaration
>> >> ExprResult Converted =
>> PerformContextuallyConvertToBool(AssertExpr);
>> >> if (Converted.isInvalid())
>> >> Failed = true;
>> >> + else
>> >> + Converted = ConstantExpr::Create(Context, Converted.get());
>> >>
>> >> llvm::APSInt Cond;
>> >> if (!Failed && VerifyIntegerConstantExpression(Converted.get(),
>> &Cond,
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -4376,10 +4376,11 @@ ExprResult Sema::ActOnOMPArraySectionExp
>> >> return ExprError();
>> >>
>> >> if (LowerBound && !OriginalTy->isAnyPointerType()) {
>> >> - llvm::APSInt LowerBoundValue;
>> >> - if (LowerBound->EvaluateAsInt(LowerBoundValue, Context)) {
>> >> + Expr::EvalResult Result;
>> >> + if (LowerBound->EvaluateAsInt(Result, Context)) {
>> >> // OpenMP 4.5, [2.4 Array Sections]
>> >> // The array section must be a subset of the original array.
>> >> + llvm::APSInt LowerBoundValue = Result.Val.getInt();
>> >> if (LowerBoundValue.isNegative()) {
>> >> Diag(LowerBound->getExprLoc(),
>> diag::err_omp_section_not_subset_of_array)
>> >> << LowerBound->getSourceRange();
>> >> @@ -4389,10 +4390,11 @@ ExprResult Sema::ActOnOMPArraySectionExp
>> >> }
>> >>
>> >> if (Length) {
>> >> - llvm::APSInt LengthValue;
>> >> - if (Length->EvaluateAsInt(LengthValue, Context)) {
>> >> + Expr::EvalResult Result;
>> >> + if (Length->EvaluateAsInt(Result, Context)) {
>> >> // OpenMP 4.5, [2.4 Array Sections]
>> >> // The length must evaluate to non-negative integers.
>> >> + llvm::APSInt LengthValue = Result.Val.getInt();
>> >> if (LengthValue.isNegative()) {
>> >> Diag(Length->getExprLoc(),
>> diag::err_omp_section_length_negative)
>> >> << LengthValue.toString(/*Radix=*/10, /*Signed=*/true)
>> >> @@ -5795,6 +5797,8 @@ Sema::BuildCompoundLiteralExpr(SourceLoc
>> >> ? VK_RValue
>> >> : VK_LValue;
>> >>
>> >> + if (isFileScope)
>> >> + LiteralExpr = ConstantExpr::Create(Context, LiteralExpr);
>> >> Expr *E = new (Context) CompoundLiteralExpr(LParenLoc, TInfo,
>> literalType,
>> >> VK, LiteralExpr,
>> isFileScope);
>> >> if (isFileScope) {
>> >> @@ -5803,7 +5807,6 @@ Sema::BuildCompoundLiteralExpr(SourceLoc
>> >> !literalType->isDependentType()) // C99 6.5.2.5p3
>> >> if (CheckForConstantInitializer(LiteralExpr, literalType))
>> >> return ExprError();
>> >> - E = new (Context) ConstantExpr(E);
>> >> } else if (literalType.getAddressSpace() != LangAS::opencl_private
>> &&
>> >> literalType.getAddressSpace() != LangAS::Default) {
>> >> // Embedded-C extensions to C99 6.5.2.5:
>> >> @@ -8399,8 +8402,8 @@ static bool canConvertIntToOtherIntTy(Se
>> >> // Reject cases where the value of the Int is unknown as that would
>> >> // possibly cause truncation, but accept cases where the scalar can
>> be
>> >> // demoted without loss of precision.
>> >> - llvm::APSInt Result;
>> >> - bool CstInt = Int->get()->EvaluateAsInt(Result, S.Context);
>> >> + Expr::EvalResult EVResult;
>> >> + bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.Context);
>> >> int Order = S.Context.getIntegerTypeOrder(OtherIntTy, IntTy);
>> >> bool IntSigned = IntTy->hasSignedIntegerRepresentation();
>> >> bool OtherIntSigned = OtherIntTy->hasSignedIntegerRepresentation();
>> >> @@ -8408,6 +8411,7 @@ static bool canConvertIntToOtherIntTy(Se
>> >> if (CstInt) {
>> >> // If the scalar is constant and is of a higher order and has
>> more active
>> >> // bits that the vector element type, reject it.
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> unsigned NumBits = IntSigned
>> >> ? (Result.isNegative() ?
>> Result.getMinSignedBits()
>> >> :
>> Result.getActiveBits())
>> >> @@ -8435,8 +8439,9 @@ static bool canConvertIntTyToFloatTy(Sem
>> >>
>> >> // Determine if the integer constant can be expressed as a floating
>> point
>> >> // number of the appropriate type.
>> >> - llvm::APSInt Result;
>> >> - bool CstInt = Int->get()->EvaluateAsInt(Result, S.Context);
>> >> + Expr::EvalResult EVResult;
>> >> + bool CstInt = Int->get()->EvaluateAsInt(EVResult, S.Context);
>> >> +
>> >> uint64_t Bits = 0;
>> >> if (CstInt) {
>> >> // Reject constants that would be truncated if they were
>> converted to
>> >> @@ -8444,6 +8449,7 @@ static bool canConvertIntTyToFloatTy(Sem
>> >> // FIXME: Ideally the conversion to an APFloat and from an APFloat
>> >> // could be avoided if there was a convertFromAPInt method
>> >> // which could signal back if implicit truncation occurred.
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> llvm::APFloat Float(S.Context.getFloatTypeSemantics(FloatTy));
>> >> Float.convertFromAPInt(Result,
>> IntTy->hasSignedIntegerRepresentation(),
>> >> llvm::APFloat::rmTowardZero);
>> >> @@ -8783,9 +8789,10 @@ static void DiagnoseBadDivideOrRemainder
>> >> ExprResult &RHS,
>> >> SourceLocation Loc,
>> bool IsDiv) {
>> >> // Check for division/remainder by zero.
>> >> - llvm::APSInt RHSValue;
>> >> + Expr::EvalResult RHSValue;
>> >> if (!RHS.get()->isValueDependent() &&
>> >> - RHS.get()->EvaluateAsInt(RHSValue, S.Context) && RHSValue == 0)
>> >> + RHS.get()->EvaluateAsInt(RHSValue, S.Context) &&
>> >> + RHSValue.Val.getInt() == 0)
>> >> S.DiagRuntimeBehavior(Loc, RHS.get(),
>> >>
>> S.PDiag(diag::warn_remainder_division_by_zero)
>> >> << IsDiv << RHS.get()->getSourceRange());
>> >> @@ -9027,8 +9034,9 @@ static void diagnoseStringPlusInt(Sema &
>> >> if (!IsStringPlusInt || IndexExpr->isValueDependent())
>> >> return;
>> >>
>> >> - llvm::APSInt index;
>> >> - if (IndexExpr->EvaluateAsInt(index, Self.getASTContext())) {
>> >> + Expr::EvalResult Result;
>> >> + if (IndexExpr->EvaluateAsInt(Result, Self.getASTContext())) {
>> >> + llvm::APSInt index = Result.Val.getInt();
>> >> unsigned StrLenWithNull = StrExpr->getLength() + 1;
>> >> if (index.isNonNegative() &&
>> >> index <= llvm::APSInt(llvm::APInt(index.getBitWidth(),
>> StrLenWithNull),
>> >> @@ -9172,10 +9180,11 @@ QualType Sema::CheckAdditionOperands(Exp
>> >> if (PExp->IgnoreParenCasts()->isNullPointerConstant(
>> >> Context, Expr::NPC_ValueDependentIsNotNull)) {
>> >> // In C++ adding zero to a null pointer is defined.
>> >> - llvm::APSInt KnownVal;
>> >> + Expr::EvalResult KnownVal;
>> >> if (!getLangOpts().CPlusPlus ||
>> >> (!IExp->isValueDependent() &&
>> >> - (!IExp->EvaluateAsInt(KnownVal, Context) || KnownVal != 0)))
>> {
>> >> + (!IExp->EvaluateAsInt(KnownVal, Context) ||
>> >> + KnownVal.Val.getInt() != 0))) {
>> >> // Check the conditions to see if this is the 'p = nullptr + n'
>> idiom.
>> >> bool IsGNUIdiom =
>> BinaryOperator::isNullPointerArithmeticExtension(
>> >> Context, BO_Add, PExp, IExp);
>> >> @@ -9250,10 +9259,11 @@ QualType Sema::CheckSubtractionOperands(
>> >> if
>> (LHS.get()->IgnoreParenCasts()->isNullPointerConstant(Context,
>> >>
>> Expr::NPC_ValueDependentIsNotNull)) {
>> >> // In C++ adding zero to a null pointer is defined.
>> >> - llvm::APSInt KnownVal;
>> >> + Expr::EvalResult KnownVal;
>> >> if (!getLangOpts().CPlusPlus ||
>> >> (!RHS.get()->isValueDependent() &&
>> >> - (!RHS.get()->EvaluateAsInt(KnownVal, Context) ||
>> KnownVal != 0))) {
>> >> + (!RHS.get()->EvaluateAsInt(KnownVal, Context) ||
>> >> + KnownVal.Val.getInt() != 0))) {
>> >> diagnoseArithmeticOnNullPointer(*this, Loc, LHS.get(),
>> false);
>> >> }
>> >> }
>> >> @@ -9329,11 +9339,12 @@ static void DiagnoseBadShiftValues(Sema&
>> >> if (S.getLangOpts().OpenCL)
>> >> return;
>> >>
>> >> - llvm::APSInt Right;
>> >> // Check right/shifter operand
>> >> + Expr::EvalResult RHSResult;
>> >> if (RHS.get()->isValueDependent() ||
>> >> - !RHS.get()->EvaluateAsInt(Right, S.Context))
>> >> + !RHS.get()->EvaluateAsInt(RHSResult, S.Context))
>> >> return;
>> >> + llvm::APSInt Right = RHSResult.Val.getInt();
>> >>
>> >> if (Right.isNegative()) {
>> >> S.DiagRuntimeBehavior(Loc, RHS.get(),
>> >> @@ -9356,11 +9367,12 @@ static void DiagnoseBadShiftValues(Sema&
>> >> // according to C++ has undefined behavior ([expr.shift] 5.8/2).
>> Unsigned
>> >> // integers have defined behavior modulo one more than the maximum
>> value
>> >> // representable in the result type, so never warn for those.
>> >> - llvm::APSInt Left;
>> >> + Expr::EvalResult LHSResult;
>> >> if (LHS.get()->isValueDependent() ||
>> >> LHSType->hasUnsignedIntegerRepresentation() ||
>> >> - !LHS.get()->EvaluateAsInt(Left, S.Context))
>> >> + !LHS.get()->EvaluateAsInt(LHSResult, S.Context))
>> >> return;
>> >> + llvm::APSInt Left = LHSResult.Val.getInt();
>> >>
>> >> // If LHS does not have a signed type and non-negative value
>> >> // then, the behavior is undefined. Warn about it.
>> >> @@ -10730,8 +10742,9 @@ inline QualType Sema::CheckLogicalOperan
>> >> // that isn't 0 or 1 (which indicate a potential logical
>> operation that
>> >> // happened to fold to true/false) then warn.
>> >> // Parens on the RHS are ignored.
>> >> - llvm::APSInt Result;
>> >> - if (RHS.get()->EvaluateAsInt(Result, Context))
>> >> + Expr::EvalResult EVResult;
>> >> + if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> if ((getLangOpts().Bool &&
>> !RHS.get()->getType()->isBooleanType() &&
>> >> !RHS.get()->getExprLoc().isMacroID()) ||
>> >> (Result != 0 && Result != 1)) {
>> >> @@ -10751,6 +10764,7 @@ inline QualType Sema::CheckLogicalOperan
>> >>
>> SourceRange(getLocForEndOfToken(LHS.get()->getEndLoc()),
>> >> RHS.get()->getEndLoc()));
>> >> }
>> >> + }
>> >> }
>> >>
>> >> if (!Context.getLangOpts().CPlusPlus) {
>> >> @@ -14166,12 +14180,15 @@ Sema::VerifyIntegerConstantExpression(Ex
>> >> return ExprError();
>> >> }
>> >>
>> >> + if (!isa<ConstantExpr>(E))
>> >> + E = ConstantExpr::Create(Context, E);
>> >> +
>> >> // Circumvent ICE checking in C++11 to avoid evaluating the
>> expression twice
>> >> // in the non-ICE case.
>> >> if (!getLangOpts().CPlusPlus11 &&
>> E->isIntegerConstantExpr(Context)) {
>> >> if (Result)
>> >> *Result = E->EvaluateKnownConstIntCheckOverflow(Context);
>> >> - return new (Context) ConstantExpr(E);
>> >> + return E;
>> >> }
>> >>
>> >> Expr::EvalResult EvalResult;
>> >> @@ -14189,7 +14206,7 @@ Sema::VerifyIntegerConstantExpression(Ex
>> >> if (Folded && getLangOpts().CPlusPlus11 && Notes.empty()) {
>> >> if (Result)
>> >> *Result = EvalResult.Val.getInt();
>> >> - return new (Context) ConstantExpr(E);
>> >> + return E;
>> >> }
>> >>
>> >> // If our only note is the usual "invalid subexpression" note, just
>> point
>> >> @@ -14217,7 +14234,7 @@ Sema::VerifyIntegerConstantExpression(Ex
>> >>
>> >> if (Result)
>> >> *Result = EvalResult.Val.getInt();
>> >> - return new (Context) ConstantExpr(E);
>> >> + return E;
>> >> }
>> >>
>> >> namespace {
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -8050,8 +8050,9 @@ ExprResult InitializationSequence::Perfo
>> >> break;
>> >> }
>> >>
>> >> - llvm::APSInt Result;
>> >> - Init->EvaluateAsInt(Result, S.Context);
>> >> + Expr::EvalResult EVResult;
>> >> + Init->EvaluateAsInt(EVResult, S.Context);
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> const uint64_t SamplerValue = Result.getLimitedValue();
>> >> // 32-bit value of sampler's initializer is interpreted as
>> >> // bit-field with the following structure:
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -5048,15 +5048,16 @@ checkOpenMPLoop(OpenMPDirectiveKind DKin
>> >> unsigned NestedLoopCount = 1;
>> >> if (CollapseLoopCountExpr) {
>> >> // Found 'collapse' clause - calculate collapse number.
>> >> - llvm::APSInt Result;
>> >> + Expr::EvalResult Result;
>> >> if (CollapseLoopCountExpr->EvaluateAsInt(Result,
>> SemaRef.getASTContext()))
>> >> - NestedLoopCount = Result.getLimitedValue();
>> >> + NestedLoopCount = Result.Val.getInt().getLimitedValue();
>> >> }
>> >> unsigned OrderedLoopCount = 1;
>> >> if (OrderedLoopCountExpr) {
>> >> // Found 'ordered' clause - calculate collapse number.
>> >> - llvm::APSInt Result;
>> >> - if (OrderedLoopCountExpr->EvaluateAsInt(Result,
>> SemaRef.getASTContext())) {
>> >> + Expr::EvalResult EVResult;
>> >> + if (OrderedLoopCountExpr->EvaluateAsInt(EVResult,
>> SemaRef.getASTContext())) {
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> if (Result.getLimitedValue() < NestedLoopCount) {
>> >> SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
>> >> diag::err_omp_wrong_ordered_loop_count)
>> >> @@ -5652,7 +5653,6 @@ static bool checkSimdlenSafelenSpecified
>> >> }
>> >>
>> >> if (Simdlen && Safelen) {
>> >> - llvm::APSInt SimdlenRes, SafelenRes;
>> >> const Expr *SimdlenLength = Simdlen->getSimdlen();
>> >> const Expr *SafelenLength = Safelen->getSafelen();
>> >> if (SimdlenLength->isValueDependent() ||
>> SimdlenLength->isTypeDependent() ||
>> >> @@ -5663,8 +5663,11 @@ static bool checkSimdlenSafelenSpecified
>> >> SafelenLength->isInstantiationDependent() ||
>> >> SafelenLength->containsUnexpandedParameterPack())
>> >> return false;
>> >> - SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context);
>> >> - SafelenLength->EvaluateAsInt(SafelenRes, S.Context);
>> >> + Expr::EvalResult SimdlenResult, SafelenResult;
>> >> + SimdlenLength->EvaluateAsInt(SimdlenResult, S.Context);
>> >> + SafelenLength->EvaluateAsInt(SafelenResult, S.Context);
>> >> + llvm::APSInt SimdlenRes = SimdlenResult.Val.getInt();
>> >> + llvm::APSInt SafelenRes = SafelenResult.Val.getInt();
>> >> // OpenMP 4.5 [2.8.1, simd Construct, Restrictions]
>> >> // If both simdlen and safelen clauses are specified, the value
>> of the
>> >> // simdlen parameter must be less than or equal to the value of
>> the safelen
>> >> @@ -10669,10 +10672,11 @@ static bool checkOMPArraySectionConstant
>> >> SingleElement = true;
>> >> ArraySizes.push_back(llvm::APSInt::get(1));
>> >> } else {
>> >> - llvm::APSInt ConstantLengthValue;
>> >> - if (!Length->EvaluateAsInt(ConstantLengthValue, Context))
>> >> + Expr::EvalResult Result;
>> >> + if (!Length->EvaluateAsInt(Result, Context))
>> >> return false;
>> >>
>> >> + llvm::APSInt ConstantLengthValue = Result.Val.getInt();
>> >> SingleElement = (ConstantLengthValue.getSExtValue() == 1);
>> >> ArraySizes.push_back(ConstantLengthValue);
>> >> }
>> >> @@ -10693,9 +10697,12 @@ static bool checkOMPArraySectionConstant
>> >> // This is an array subscript which has implicit length 1!
>> >> ArraySizes.push_back(llvm::APSInt::get(1));
>> >> } else {
>> >> - llvm::APSInt ConstantLengthValue;
>> >> - if (!Length->EvaluateAsInt(ConstantLengthValue, Context) ||
>> >> - ConstantLengthValue.getSExtValue() != 1)
>> >> + Expr::EvalResult Result;
>> >> + if (!Length->EvaluateAsInt(Result, Context))
>> >> + return false;
>> >> +
>> >> + llvm::APSInt ConstantLengthValue = Result.Val.getInt();
>> >> + if (ConstantLengthValue.getSExtValue() != 1)
>> >> return false;
>> >>
>> >> ArraySizes.push_back(ConstantLengthValue);
>> >> @@ -12218,9 +12225,11 @@ static bool checkArrayExpressionDoesNotR
>> >> // If there is a lower bound that does not evaluates to zero, we
>> are not
>> >> // covering the whole dimension.
>> >> if (LowerBound) {
>> >> - llvm::APSInt ConstLowerBound;
>> >> - if (!LowerBound->EvaluateAsInt(ConstLowerBound,
>> SemaRef.getASTContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (!LowerBound->EvaluateAsInt(Result, SemaRef.getASTContext()))
>> >> return false; // Can't get the integer value as a constant.
>> >> +
>> >> + llvm::APSInt ConstLowerBound = Result.Val.getInt();
>> >> if (ConstLowerBound.getSExtValue())
>> >> return true;
>> >> }
>> >> @@ -12240,10 +12249,11 @@ static bool checkArrayExpressionDoesNotR
>> >> if (!CATy)
>> >> return false;
>> >>
>> >> - llvm::APSInt ConstLength;
>> >> - if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext()))
>> >> return false; // Can't get the integer value as a constant.
>> >>
>> >> + llvm::APSInt ConstLength = Result.Val.getInt();
>> >> return CATy->getSize().getSExtValue() != ConstLength.getSExtValue();
>> >> }
>> >>
>> >> @@ -12274,10 +12284,11 @@ static bool checkArrayExpressionDoesNotR
>> >> }
>> >>
>> >> // Check if the length evaluates to 1.
>> >> - llvm::APSInt ConstLength;
>> >> - if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext()))
>> >> + Expr::EvalResult Result;
>> >> + if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext()))
>> >> return false; // Can't get the integer value as a constant.
>> >>
>> >> + llvm::APSInt ConstLength = Result.Val.getInt();
>> >> return ConstLength.getSExtValue() != 1;
>> >> }
>> >>
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -5469,7 +5469,7 @@ static ExprResult CheckConvertedConstant
>> >>
>> >> if (Notes.empty()) {
>> >> // It's a constant expression.
>> >> - return new (S.Context) ConstantExpr(Result.get());
>> >> + return ConstantExpr::Create(S.Context, Result.get());
>> >> }
>> >> }
>> >>
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -945,8 +945,11 @@ Sema::ActOnFinishSwitchStmt(SourceLocati
>> >> llvm::APSInt ConstantCondValue;
>> >> bool HasConstantCond = false;
>> >> if (!HasDependentValue && !TheDefaultStmt) {
>> >> - HasConstantCond = CondExpr->EvaluateAsInt(ConstantCondValue,
>> Context,
>> >> + Expr::EvalResult Result;
>> >> + HasConstantCond = CondExpr->EvaluateAsInt(Result, Context,
>> >>
>> Expr::SE_AllowSideEffects);
>> >> + if (Result.Val.isInt())
>> >> + ConstantCondValue = Result.Val.getInt();
>> >> assert(!HasConstantCond ||
>> >> (ConstantCondValue.getBitWidth() == CondWidth &&
>> >> ConstantCondValue.isSigned() == CondIsSigned));
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -378,11 +378,12 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL
>> >> << InputExpr->getSourceRange());
>> >> } else if (Info.requiresImmediateConstant() &&
>> !Info.allowsRegister()) {
>> >> if (!InputExpr->isValueDependent()) {
>> >> - llvm::APSInt Result;
>> >> - if (!InputExpr->EvaluateAsInt(Result, Context))
>> >> + Expr::EvalResult EVResult;
>> >> + if (!InputExpr->EvaluateAsInt(EVResult, Context))
>> >> return StmtError(
>> >> Diag(InputExpr->getBeginLoc(),
>> diag::err_asm_immediate_expected)
>> >> << Info.getConstraintStr() <<
>> InputExpr->getSourceRange());
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> if (!Info.isValidAsmImmediate(Result))
>> >> return StmtError(Diag(InputExpr->getBeginLoc(),
>> >>
>> diag::err_invalid_asm_value_for_constraint)
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Nov 21 12:44:18
>> 2018
>> >> @@ -178,6 +178,8 @@ getDeducedParameterFromExpr(TemplateDedu
>> >> while (true) {
>> >> if (ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(E))
>> >> E = IC->getSubExpr();
>> >> + else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E))
>> >> + E = CE->getSubExpr();
>> >> else if (SubstNonTypeTemplateParmExpr *Subst =
>> >> dyn_cast<SubstNonTypeTemplateParmExpr>(E))
>> >> E = Subst->getReplacement();
>> >> @@ -5225,6 +5227,8 @@ MarkUsedTemplateParameters(ASTContext &C
>> >> while (true) {
>> >> if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
>> >> E = ICE->getSubExpr();
>> >> + else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(E))
>> >> + E = CE->getSubExpr();
>> >> else if (const SubstNonTypeTemplateParmExpr *Subst =
>> >> dyn_cast<SubstNonTypeTemplateParmExpr>(E))
>> >> E = Subst->getReplacement();
>> >>
>> >> Modified: cfe/trunk/lib/Sema/SemaType.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
>> >> +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov 21 12:44:18 2018
>> >> @@ -2233,10 +2233,6 @@ QualType Sema::BuildArrayType(QualType T
>> >> T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
>> >> }
>> >>
>> >> - if (ArraySize && !CurContext->isFunctionOrMethod())
>> >> - // A file-scoped array must have a constant array size.
>> >> - ArraySize = new (Context) ConstantExpr(ArraySize);
>> >> -
>> >> // OpenCL v1.2 s6.9.d: variable length arrays are not supported.
>> >> if (getLangOpts().OpenCL && T->isVariableArrayType()) {
>> >> Diag(Loc, diag::err_opencl_vla);
>> >>
>> >> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
>> (original)
>> >> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
>> Wed Nov 21 12:44:18 2018
>> >> @@ -101,9 +101,10 @@ bool BuiltinFunctionChecker::evalCall(co
>> >> // This must be resolvable at compile time, so we defer to the
>> constant
>> >> // evaluator for a value.
>> >> SVal V = UnknownVal();
>> >> - llvm::APSInt Result;
>> >> - if (CE->EvaluateAsInt(Result, C.getASTContext(),
>> Expr::SE_NoSideEffects)) {
>> >> + Expr::EvalResult EVResult;
>> >> + if (CE->EvaluateAsInt(EVResult, C.getASTContext(),
>> Expr::SE_NoSideEffects)) {
>> >> // Make sure the result has the correct type.
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> SValBuilder &SVB = C.getSValBuilder();
>> >> BasicValueFactory &BVF = SVB.getBasicValueFactory();
>> >> BVF.getAPSIntType(CE->getType()).apply(Result);
>> >>
>> >> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
>> (original)
>> >> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
>> Wed Nov 21 12:44:18 2018
>> >> @@ -597,9 +597,10 @@ void WalkAST::checkCall_mkstemp(const Ca
>> >> unsigned suffix = 0;
>> >> if (ArgSuffix.second >= 0) {
>> >> const Expr *suffixEx = CE->getArg((unsigned)ArgSuffix.second);
>> >> - llvm::APSInt Result;
>> >> - if (!suffixEx->EvaluateAsInt(Result, BR.getContext()))
>> >> + Expr::EvalResult EVResult;
>> >> + if (!suffixEx->EvaluateAsInt(EVResult, BR.getContext()))
>> >> return;
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> // FIXME: Issue a warning.
>> >> if (Result.isNegative())
>> >> return;
>> >>
>> >> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> ---
>> cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp
>> (original)
>> >> +++
>> cfe/trunk/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp Wed
>> Nov 21 12:44:18 2018
>> >> @@ -135,9 +135,9 @@ private:
>> >> bool isIntZeroExpr(const Expr *E) const {
>> >> if (!E->getType()->isIntegralOrEnumerationType())
>> >> return false;
>> >> - llvm::APSInt Result;
>> >> + Expr::EvalResult Result;
>> >> if (E->EvaluateAsInt(Result, Context))
>> >> - return Result == 0;
>> >> + return Result.Val.getInt() == 0;
>> >> return false;
>> >> }
>> >>
>> >> @@ -191,8 +191,11 @@ private:
>> >> if (const BinaryOperator *BOp = dyn_cast<BinaryOperator>(rhse))
>> {
>> >> if (BOp->getOpcode() == BO_Div) {
>> >> const Expr *denom = BOp->getRHS()->IgnoreParenImpCasts();
>> >> - if (denom->EvaluateAsInt(denomVal, Context))
>> >> + Expr::EvalResult Result;
>> >> + if (denom->EvaluateAsInt(Result, Context)) {
>> >> + denomVal = Result.Val.getInt();
>> >> denomKnown = true;
>> >> + }
>> >> const Expr *numerator =
>> BOp->getLHS()->IgnoreParenImpCasts();
>> >> if (numerator->isEvaluatable(Context))
>> >> numeratorKnown = true;
>> >>
>> >> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> ---
>> cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
>> (original)
>> >> +++
>> cfe/trunk/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp Wed
>> Nov 21 12:44:18 2018
>> >> @@ -87,9 +87,10 @@ void Callback::run(const MatchFinder::Ma
>> >> MacroIndicatesWeShouldSkipTheCheck = true;
>> >> }
>> >> if (!MacroIndicatesWeShouldSkipTheCheck) {
>> >> - llvm::APSInt Result;
>> >> + Expr::EvalResult EVResult;
>> >> if (CheckIfNull->IgnoreParenCasts()->EvaluateAsInt(
>> >> - Result, ACtx, Expr::SE_AllowSideEffects)) {
>> >> + EVResult, ACtx, Expr::SE_AllowSideEffects)) {
>> >> + llvm::APSInt Result = EVResult.Val.getInt();
>> >> if (Result == 0) {
>> >> if (!C->Pedantic)
>> >> return;
>> >>
>> >> Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
>> >> +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Nov 21
>> 12:44:18 2018
>> >> @@ -1283,9 +1283,6 @@ void ExprEngine::Visit(const Stmt *S, Ex
>> >> break;
>> >>
>> >> case Expr::ConstantExprClass:
>> >> - // Handled due to it being a wrapper class.
>> >> - break;
>> >> -
>> >> case Stmt::ExprWithCleanupsClass:
>> >> // Handled due to fully linearised CFG.
>> >> break;
>> >>
>> >> Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
>> >> +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Wed Nov 21
>> 12:44:18 2018
>> >> @@ -810,8 +810,9 @@ void ExprEngine::
>> >> VisitOffsetOfExpr(const OffsetOfExpr *OOE,
>> >> ExplodedNode *Pred, ExplodedNodeSet &Dst) {
>> >> StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
>> >> - APSInt IV;
>> >> - if (OOE->EvaluateAsInt(IV, getContext())) {
>> >> + Expr::EvalResult Result;
>> >> + if (OOE->EvaluateAsInt(Result, getContext())) {
>> >> + APSInt IV = Result.Val.getInt();
>> >> assert(IV.getBitWidth() ==
>> getContext().getTypeSize(OOE->getType()));
>> >> assert(OOE->getType()->isBuiltinType());
>> >> assert(OOE->getType()->getAs<BuiltinType>()->isInteger());
>> >>
>> >> Modified: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)
>> >> +++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp Wed Nov 21
>> 12:44:18 2018
>> >> @@ -362,9 +362,9 @@ Optional<SVal> SValBuilder::getConstantV
>> >> return None;
>> >>
>> >> ASTContext &Ctx = getContext();
>> >> - llvm::APSInt Result;
>> >> + Expr::EvalResult Result;
>> >> if (E->EvaluateAsInt(Result, Ctx))
>> >> - return makeIntVal(Result);
>> >> + return makeIntVal(Result.Val.getInt());
>> >>
>> >> if (Loc::isLocType(E->getType()))
>> >> if (E->isNullPointerConstant(Ctx,
>> Expr::NPC_ValueDependentIsNotNull))
>> >>
>> >> Modified: cfe/trunk/test/Analysis/builtin-functions.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-functions.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/test/Analysis/builtin-functions.cpp (original)
>> >> +++ cfe/trunk/test/Analysis/builtin-functions.cpp Wed Nov 21 12:44:18
>> 2018
>> >> @@ -70,14 +70,14 @@ void test_constant_p() {
>> >> const int j = 2;
>> >> constexpr int k = 3;
>> >> clang_analyzer_eval(__builtin_constant_p(42) == 1); //
>> expected-warning {{TRUE}}
>> >> - clang_analyzer_eval(__builtin_constant_p(i) == 0); //
>> expected-warning {{TRUE}}
>> >> + clang_analyzer_eval(__builtin_constant_p(i) == 0); //
>> expected-warning {{UNKNOWN}}
>> >> clang_analyzer_eval(__builtin_constant_p(j) == 1); //
>> expected-warning {{TRUE}}
>> >> clang_analyzer_eval(__builtin_constant_p(k) == 1); //
>> expected-warning {{TRUE}}
>> >> - clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); //
>> expected-warning {{TRUE}}
>> >> + clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); //
>> expected-warning {{UNKNOWN}}
>> >> clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); //
>> expected-warning {{TRUE}}
>> >> clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); //
>> expected-warning {{TRUE}}
>> >> clang_analyzer_eval(__builtin_constant_p(" ") == 1); //
>> expected-warning {{TRUE}}
>> >> - clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); //
>> expected-warning {{TRUE}}
>> >> + clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); //
>> expected-warning {{UNKNOWN}}
>> >> clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); //
>> expected-warning {{FALSE}}
>> >> clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); //
>> expected-warning {{TRUE}}
>> >> }
>> >>
>> >> Added: cfe/trunk/test/CodeGenCXX/builtin-constant-p.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtin-constant-p.cpp?rev=347417&view=auto
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/test/CodeGenCXX/builtin-constant-p.cpp (added)
>> >> +++ cfe/trunk/test/CodeGenCXX/builtin-constant-p.cpp Wed Nov 21
>> 12:44:18 2018
>> >> @@ -0,0 +1,24 @@
>> >> +// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s
>> >> +
>> >> +// Don't crash if the argument to __builtin_constant_p isn't scalar.
>> >> +template <typename T>
>> >> +constexpr bool is_constant(const T v) {
>> >> + return __builtin_constant_p(v);
>> >> +}
>> >> +
>> >> +template <typename T>
>> >> +class numeric {
>> >> + public:
>> >> + using type = T;
>> >> +
>> >> + template <typename S>
>> >> + constexpr numeric(S value)
>> >> + : value_(static_cast<T>(value)) {}
>> >> +
>> >> + private:
>> >> + const T value_;
>> >> +};
>> >> +
>> >> +bool bcp() {
>> >> + return is_constant(numeric<int>(1));
>> >> +}
>> >>
>> >> Modified: cfe/trunk/test/Sema/builtins.c
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/test/Sema/builtins.c (original)
>> >> +++ cfe/trunk/test/Sema/builtins.c Wed Nov 21 12:44:18 2018
>> >> @@ -122,6 +122,14 @@ int test16() {
>> >> __builtin_constant_p(1, 2); // expected-error {{too many
>> arguments}}
>> >> }
>> >>
>> >> +// __builtin_constant_p cannot resolve non-constants as a file scoped
>> array.
>> >> +int expr;
>> >> +char y[__builtin_constant_p(expr) ? -1 : 1]; // no warning, the
>> builtin is false.
>> >> +
>> >> +// no warning, the builtin is false.
>> >> +struct foo { int a; };
>> >> +struct foo x = (struct foo) { __builtin_constant_p(42) ? 37 : 927 };
>> >> +
>> >> const int test17_n = 0;
>> >> const char test17_c[] = {1, 2, 3, 0};
>> >> const char test17_d[] = {1, 2, 3, 4};
>> >> @@ -161,6 +169,7 @@ void test17() {
>> >> F(&test17_d);
>> >> F((struct Aggregate){0, 1});
>> >> F((IntVector){0, 1, 2, 3});
>> >> + F(test17);
>> >>
>> >> // Ensure that a technique used in glibc is handled correctly.
>> >> #define OPT(...) (__builtin_constant_p(__VA_ARGS__) &&
>> strlen(__VA_ARGS__) < 4)
>> >>
>> >> Modified: cfe/trunk/test/SemaCXX/compound-literal.cpp
>> >> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compound-literal.cpp?rev=347417&r1=347416&r2=347417&view=diff
>> >>
>> ==============================================================================
>> >> --- cfe/trunk/test/SemaCXX/compound-literal.cpp (original)
>> >> +++ cfe/trunk/test/SemaCXX/compound-literal.cpp Wed Nov 21 12:44:18
>> 2018
>> >> @@ -36,8 +36,8 @@ namespace brace_initializers {
>> >>
>> >> POD p = (POD){1, 2};
>> >> // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::POD'
>> >> - // CHECK: ConstantExpr {{.*}} 'brace_initializers::POD'
>> >> - // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'brace_initializers::POD'
>> >> + // CHECK: CompoundLiteralExpr {{.*}} 'brace_initializers::POD'
>> >> + // CHECK-NEXT: ConstantExpr {{.*}} 'brace_initializers::POD'
>> >> // CHECK-NEXT: InitListExpr {{.*}} 'brace_initializers::POD'
>> >> // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
>> >> // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
>> >>
>> >>
>> >> _______________________________________________
>> >> cfe-commits mailing list
>> >> cfe-commits at lists.llvm.org
>> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181127/82a2f6ad/attachment-0001.html>
More information about the cfe-commits
mailing list