diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-11-27 14:01:40 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-11-27 14:01:40 +0000 |
commit | 8c79706e89dd2792bcc7b1e44d8f5db6abaf1617 (patch) | |
tree | b1ebe35d9001f44880de2719abd98aeaa260270a /clang/lib/CodeGen/CGBuiltin.cpp | |
parent | 032f3e7fd8a12ceab800b0d9c3aca0f769f7b7cc (diff) | |
download | bcm5719-llvm-8c79706e89dd2792bcc7b1e44d8f5db6abaf1617.tar.gz bcm5719-llvm-8c79706e89dd2792bcc7b1e44d8f5db6abaf1617.zip |
Revert r347417 "Re-Reinstate 347294 with a fix for the failures."
This caused a miscompile in Chrome (see crbug.com/908372) that's
illustrated by this small reduction:
static bool f(int *a, int *b) {
return !__builtin_constant_p(b - a) || (!(b - a));
}
int arr[] = {1,2,3};
bool g() {
return f(arr, arr + 3);
}
$ clang -O2 -S -emit-llvm a.cc -o -
g() should return true, but after r347417 it became false for some reason.
This also reverts the follow-up commits.
r347417:
> Re-Reinstate 347294 with a fix for the failures.
>
> Don't try to emit a scalar expression for a non-scalar argument to
> __builtin_constant_p().
>
> Third time's a charm!
r347446:
> The result of is.constant() is unsigned.
r347480:
> A __builtin_constant_p() returns 0 with a function type.
r347512:
> isEvaluatable() implies a constant context.
>
> Assume that we're in a constant context if we're asking if the expression can
> be compiled into a constant initializer. This fixes the issue where a
> __builtin_constant_p() in a compound literal was diagnosed as not being
> constant, even though it's always possible to convert the builtin into a
> constant.
r347531:
> A "constexpr" is evaluated in a constant context. Make sure this is reflected
> if a __builtin_constant_p() is a part of a constexpr.
llvm-svn: 347656
Diffstat (limited to 'clang/lib/CodeGen/CGBuiltin.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 54 |
1 files changed, 13 insertions, 41 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index cb15f19224e..cf7c0b0c288 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -1896,26 +1896,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI_rotr64: 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) || ArgType->isFunctionType()) - // 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*/false); - return RValue::get(Result); - } case Builtin::BI__builtin_object_size: { unsigned Type = E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue(); @@ -2180,12 +2160,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin___memcpy_chk: { // fold __builtin_memcpy_chk(x, y, cst1, cst2) to memcpy iff cst1<=cst2. - Expr::EvalResult SizeResult, DstSizeResult; - if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) || - !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext())) + llvm::APSInt Size, DstSize; + if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || + !E->getArg(3)->EvaluateAsInt(DstSize, 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)); @@ -2206,12 +2184,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin___memmove_chk: { // fold __builtin_memmove_chk(x, y, cst1, cst2) to memmove iff cst1<=cst2. - Expr::EvalResult SizeResult, DstSizeResult; - if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) || - !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext())) + llvm::APSInt Size, DstSize; + if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || + !E->getArg(3)->EvaluateAsInt(DstSize, 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)); @@ -2246,12 +2222,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, } case Builtin::BI__builtin___memset_chk: { // fold __builtin_memset_chk(x, y, cst1, cst2) to memset iff cst1<=cst2. - Expr::EvalResult SizeResult, DstSizeResult; - if (!E->getArg(2)->EvaluateAsInt(SizeResult, CGM.getContext()) || - !E->getArg(3)->EvaluateAsInt(DstSizeResult, CGM.getContext())) + llvm::APSInt Size, DstSize; + if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || + !E->getArg(3)->EvaluateAsInt(DstSize, 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)); @@ -5765,11 +5739,10 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, /*Variadic=*/false); - Expr::EvalResult Result; - if (!E->getArg(0)->EvaluateAsInt(Result, CGM.getContext())) + APSInt Value; + if (!E->getArg(0)->EvaluateAsInt(Value, 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 = @@ -6872,11 +6845,10 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, } if (BuiltinID == AArch64::BI__getReg) { - Expr::EvalResult Result; - if (!E->getArg(0)->EvaluateAsInt(Result, CGM.getContext())) + APSInt Value; + if (!E->getArg(0)->EvaluateAsInt(Value, 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); |