[llvm] r198531 - Emit an error message if the value passed to __builtin_returnaddress isn't a constant
Bill Wendling
isanbard at gmail.com
Sun Jan 5 22:04:53 PST 2014
Oh, I suppose so. :-)
-bw
On Jan 5, 2014, at 9:46 PM, Alp Toker <alp at nuanti.com> wrote:
>
> On 06/01/2014 00:49, Bill Wendling wrote:
>> Done. Thanks!
>
> That's much better, thanks.
>
> Could you back out the LLVMContext.h includes as well when you get a chance?
>
> Cheers
> Alp.
>
>
>>
>> -bw
>>
>> On Jan 4, 2014, at 6:18 PM, Alp Toker <alp at nuanti.com> wrote:
>>
>>> Hi Bill,
>>>
>>> I wonder if the eight copies of the below can be factored into a bool checkConstant() function or similar?
>>>
>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>> + "be a constant integer");
>>> + return SDValue();
>>> + }
>>>
>>>
>>> That'll at least avoid the strings drifting apart over time.
>>>
>>> I'm aware we're still getting to know Quentin's diag system so maybe there's a better solution on the way..
>>>
>>> (Of course the winner would be if there's a central place to check this alongside other any other diags, but I'm guessing there wasn't.)
>>>
>>> Alp.
>>>
>>>
>>> On 05/01/2014 01:47, Bill Wendling wrote:
>>>> Author: void
>>>> Date: Sat Jan 4 19:47:20 2014
>>>> New Revision: 198531
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=198531&view=rev
>>>> Log:
>>>> Emit an error message if the value passed to __builtin_returnaddress isn't a constant
>>>>
>>>> __builtin_returnaddress requires that the value passed into is be a constant.
>>>> However, at -O0 even a constant expression may not be converted to a constant.
>>>> Emit an error message intead of crashing.
>>>>
>>>> Added:
>>>> llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll
>>>> Modified:
>>>> llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
>>>> llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
>>>> llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp
>>>> llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp
>>>> llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
>>>> llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
>>>> llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp
>>>> llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
>>>>
>>>> Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -26,6 +26,7 @@
>>>> #include "llvm/CodeGen/MachineRegisterInfo.h"
>>>> #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
>>>> #include "llvm/IR/CallingConv.h"
>>>> +#include "llvm/IR/LLVMContext.h"
>>>> using namespace llvm;
>>>> @@ -2131,6 +2132,12 @@ SDValue AArch64TargetLowering::LowerRETU
>>>> MachineFrameInfo *MFI = MF.getFrameInfo();
>>>> MFI->setReturnAddressIsTaken(true);
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> EVT VT = Op.getValueType();
>>>> SDLoc dl(Op);
>>>> unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
>>>>
>>>> Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -41,6 +41,7 @@
>>>> #include "llvm/IR/Instruction.h"
>>>> #include "llvm/IR/Instructions.h"
>>>> #include "llvm/IR/Intrinsics.h"
>>>> +#include "llvm/IR/LLVMContext.h"
>>>> #include "llvm/IR/Type.h"
>>>> #include "llvm/MC/MCSectionMachO.h"
>>>> #include "llvm/Support/CommandLine.h"
>>>> @@ -3752,6 +3753,12 @@ SDValue ARMTargetLowering::LowerRETURNAD
>>>> MachineFrameInfo *MFI = MF.getFrameInfo();
>>>> MFI->setReturnAddressIsTaken(true);
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> EVT VT = Op.getValueType();
>>>> SDLoc dl(Op);
>>>> unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
>>>>
>>>> Modified: llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -32,6 +32,7 @@
>>>> #include "llvm/IR/GlobalVariable.h"
>>>> #include "llvm/IR/InlineAsm.h"
>>>> #include "llvm/IR/Intrinsics.h"
>>>> +#include "llvm/IR/LLVMContext.h"
>>>> #include "llvm/Support/CommandLine.h"
>>>> #include "llvm/Support/Debug.h"
>>>> #include "llvm/Support/ErrorHandling.h"
>>>> @@ -981,6 +982,12 @@ HexagonTargetLowering::LowerRETURNADDR(S
>>>> MachineFrameInfo *MFI = MF.getFrameInfo();
>>>> MFI->setReturnAddressIsTaken(true);
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> EVT VT = Op.getValueType();
>>>> SDLoc dl(Op);
>>>> unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
>>>>
>>>> Modified: llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -32,6 +32,7 @@
>>>> #include "llvm/IR/GlobalAlias.h"
>>>> #include "llvm/IR/GlobalVariable.h"
>>>> #include "llvm/IR/Intrinsics.h"
>>>> +#include "llvm/IR/LLVMContext.h"
>>>> #include "llvm/Support/CommandLine.h"
>>>> #include "llvm/Support/Debug.h"
>>>> #include "llvm/Support/ErrorHandling.h"
>>>> @@ -1047,6 +1048,12 @@ SDValue MSP430TargetLowering::LowerRETUR
>>>> MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
>>>> MFI->setReturnAddressIsTaken(true);
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
>>>> SDLoc dl(Op);
>>>> Modified: llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -31,6 +31,7 @@
>>>> #include "llvm/IR/CallingConv.h"
>>>> #include "llvm/IR/DerivedTypes.h"
>>>> #include "llvm/IR/GlobalVariable.h"
>>>> +#include "llvm/IR/LLVMContext.h"
>>>> #include "llvm/Support/CommandLine.h"
>>>> #include "llvm/Support/Debug.h"
>>>> #include "llvm/Support/ErrorHandling.h"
>>>> @@ -1844,6 +1845,12 @@ lowerFRAMEADDR(SDValue Op, SelectionDAG
>>>> SDValue MipsTargetLowering::lowerRETURNADDR(SDValue Op,
>>>> SelectionDAG &DAG) const {
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> // check the depth
>>>> assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) &&
>>>> "Return address can be determined only for current frame.");
>>>>
>>>> Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -30,6 +30,7 @@
>>>> #include "llvm/IR/DerivedTypes.h"
>>>> #include "llvm/IR/Function.h"
>>>> #include "llvm/IR/Intrinsics.h"
>>>> +#include "llvm/IR/LLVMContext.h"
>>>> #include "llvm/Support/CommandLine.h"
>>>> #include "llvm/Support/ErrorHandling.h"
>>>> #include "llvm/Support/MathExtras.h"
>>>> @@ -7795,6 +7796,12 @@ SDValue PPCTargetLowering::LowerRETURNAD
>>>> MachineFrameInfo *MFI = MF.getFrameInfo();
>>>> MFI->setReturnAddressIsTaken(true);
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> SDLoc dl(Op);
>>>> unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
>>>> Modified: llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -26,6 +26,7 @@
>>>> #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
>>>> #include "llvm/IR/DerivedTypes.h"
>>>> #include "llvm/IR/Function.h"
>>>> +#include "llvm/IR/LLVMContext.h"
>>>> #include "llvm/IR/Module.h"
>>>> #include "llvm/Support/ErrorHandling.h"
>>>> using namespace llvm;
>>>> @@ -2470,6 +2471,12 @@ static SDValue LowerRETURNADDR(SDValue O
>>>> MachineFrameInfo *MFI = MF.getFrameInfo();
>>>> MFI->setReturnAddressIsTaken(true);
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> EVT VT = Op.getValueType();
>>>> SDLoc dl(Op);
>>>> uint64_t depth = Op.getConstantOperandVal(0);
>>>>
>>>> Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
>>>> +++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sat Jan 4 19:47:20 2014
>>>> @@ -12180,6 +12180,12 @@ SDValue X86TargetLowering::LowerRETURNAD
>>>> MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
>>>> MFI->setReturnAddressIsTaken(true);
>>>> + if (!isa<ConstantSDNode>(Op.getOperand(0))) {
>>>> + DAG.getContext()->emitError("argument to '__builtin_return_address' must "
>>>> + "be a constant integer");
>>>> + return SDValue();
>>>> + }
>>>> +
>>>> unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
>>>> SDLoc dl(Op);
>>>> EVT PtrVT = getPointerTy();
>>>>
>>>> Added: llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll?rev=198531&view=auto
>>>> ==============================================================================
>>>> --- llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll (added)
>>>> +++ llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll Sat Jan 4 19:47:20 2014
>>>> @@ -0,0 +1,27 @@
>>>> +; RUN: not llc < %s -O0 2> %t1
>>>> +; RUN: FileCheck %s < %t1
>>>> +
>>>> +; CHECK: argument to '__builtin_return_address' must be a constant integer
>>>> +
>>>> +define i32* @foo() {
>>>> +entry:
>>>> + %t1 = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 0, i32 0)
>>>> + %t2 = extractvalue { i32, i1 } %t1, 0
>>>> + %t3 = extractvalue { i32, i1 } %t1, 1
>>>> + br i1 %t3, label %cont, label %trap
>>>> +
>>>> +trap:
>>>> + call void @llvm.trap()
>>>> + unreachable
>>>> +
>>>> +cont:
>>>> + %t5 = call i8* @llvm.returnaddress(i32 %t2)
>>>> + %t6 = bitcast i8* %t5 to i32*
>>>> + ret i32* %t6
>>>> +}
>>>> +
>>>> +declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32)
>>>> +
>>>> +declare void @llvm.trap()
>>>> +
>>>> +declare i8* @llvm.returnaddress(i32)
>>>>
>>>>
>>>> _______________________________________________
>>>> llvm-commits mailing list
>>>> llvm-commits at cs.uiuc.edu
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>> --
>>> http://www.nuanti.com
>>> the browser experts
>>>
>
> --
> http://www.nuanti.com
> the browser experts
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140105/2d6ef421/attachment.html>
More information about the llvm-commits
mailing list