<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Oh, I suppose so. :-)<div><br></div><div>-bw</div><div><br><div><div>On Jan 5, 2014, at 9:46 PM, Alp Toker <<a href="mailto:alp@nuanti.com">alp@nuanti.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>On 06/01/2014 00:49, Bill Wendling wrote:<br><blockquote type="cite">Done. Thanks!<br></blockquote><br>That's much better, thanks.<br><br>Could you back out the LLVMContext.h includes as well when you get a chance?<br><br>Cheers<br>Alp.<br><br><br><blockquote type="cite"><br>-bw<br><br>On Jan 4, 2014, at 6:18 PM, Alp Toker <<a href="mailto:alp@nuanti.com">alp@nuanti.com</a>> wrote:<br><br><blockquote type="cite">Hi Bill,<br><br>I wonder if the eight copies of the below can be factored into a bool checkConstant() function or similar?<br><br>+  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br><br><br>That'll at least avoid the strings drifting apart over time.<br><br>I'm aware we're still getting to know Quentin's diag system so maybe there's a better solution on the way..<br><br>(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.)<br><br>Alp.<br><br><br>On 05/01/2014 01:47, Bill Wendling wrote:<br><blockquote type="cite">Author: void<br>Date: Sat Jan  4 19:47:20 2014<br>New Revision: 198531<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=198531&view=rev">http://llvm.org/viewvc/llvm-project?rev=198531&view=rev</a><br>Log:<br>Emit an error message if the value passed to __builtin_returnaddress isn't a constant<br><br>__builtin_returnaddress requires that the value passed into is be a constant.<br>However, at -O0 even a constant expression may not be converted to a constant.<br>Emit an error message intead of crashing.<br><br>Added:<br>    llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll<br>Modified:<br>    llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp<br>    llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp<br>    llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp<br>    llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp<br>    llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp<br>    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp<br>    llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp<br>    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br><br>Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -26,6 +26,7 @@<br> #include "llvm/CodeGen/MachineRegisterInfo.h"<br> #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"<br> #include "llvm/IR/CallingConv.h"<br>+#include "llvm/IR/LLVMContext.h"<br>   using namespace llvm;<br> @@ -2131,6 +2132,12 @@ SDValue AArch64TargetLowering::LowerRETU<br>   MachineFrameInfo *MFI = MF.getFrameInfo();<br>   MFI->setReturnAddressIsTaken(true);<br> +  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   EVT VT = Op.getValueType();<br>   SDLoc dl(Op);<br>   unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();<br><br>Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -41,6 +41,7 @@<br> #include "llvm/IR/Instruction.h"<br> #include "llvm/IR/Instructions.h"<br> #include "llvm/IR/Intrinsics.h"<br>+#include "llvm/IR/LLVMContext.h"<br> #include "llvm/IR/Type.h"<br> #include "llvm/MC/MCSectionMachO.h"<br> #include "llvm/Support/CommandLine.h"<br>@@ -3752,6 +3753,12 @@ SDValue ARMTargetLowering::LowerRETURNAD<br>   MachineFrameInfo *MFI = MF.getFrameInfo();<br>   MFI->setReturnAddressIsTaken(true);<br> +  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   EVT VT = Op.getValueType();<br>   SDLoc dl(Op);<br>   unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();<br><br>Modified: llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -32,6 +32,7 @@<br> #include "llvm/IR/GlobalVariable.h"<br> #include "llvm/IR/InlineAsm.h"<br> #include "llvm/IR/Intrinsics.h"<br>+#include "llvm/IR/LLVMContext.h"<br> #include "llvm/Support/CommandLine.h"<br> #include "llvm/Support/Debug.h"<br> #include "llvm/Support/ErrorHandling.h"<br>@@ -981,6 +982,12 @@ HexagonTargetLowering::LowerRETURNADDR(S<br>   MachineFrameInfo *MFI = MF.getFrameInfo();<br>   MFI->setReturnAddressIsTaken(true);<br> +  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   EVT VT = Op.getValueType();<br>   SDLoc dl(Op);<br>   unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();<br><br>Modified: llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/MSP430/MSP430ISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -32,6 +32,7 @@<br> #include "llvm/IR/GlobalAlias.h"<br> #include "llvm/IR/GlobalVariable.h"<br> #include "llvm/IR/Intrinsics.h"<br>+#include "llvm/IR/LLVMContext.h"<br> #include "llvm/Support/CommandLine.h"<br> #include "llvm/Support/Debug.h"<br> #include "llvm/Support/ErrorHandling.h"<br>@@ -1047,6 +1048,12 @@ SDValue MSP430TargetLowering::LowerRETUR<br>   MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();<br>   MFI->setReturnAddressIsTaken(true);<br> +  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();<br>   SDLoc dl(Op);<br> Modified: llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/Mips/MipsISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -31,6 +31,7 @@<br> #include "llvm/IR/CallingConv.h"<br> #include "llvm/IR/DerivedTypes.h"<br> #include "llvm/IR/GlobalVariable.h"<br>+#include "llvm/IR/LLVMContext.h"<br> #include "llvm/Support/CommandLine.h"<br> #include "llvm/Support/Debug.h"<br> #include "llvm/Support/ErrorHandling.h"<br>@@ -1844,6 +1845,12 @@ lowerFRAMEADDR(SDValue Op, SelectionDAG<br>   SDValue MipsTargetLowering::lowerRETURNADDR(SDValue Op,<br>                                             SelectionDAG &DAG) const {<br>+  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   // check the depth<br>   assert((cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() == 0) &&<br>          "Return address can be determined only for current frame.");<br><br>Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -30,6 +30,7 @@<br> #include "llvm/IR/DerivedTypes.h"<br> #include "llvm/IR/Function.h"<br> #include "llvm/IR/Intrinsics.h"<br>+#include "llvm/IR/LLVMContext.h"<br> #include "llvm/Support/CommandLine.h"<br> #include "llvm/Support/ErrorHandling.h"<br> #include "llvm/Support/MathExtras.h"<br>@@ -7795,6 +7796,12 @@ SDValue PPCTargetLowering::LowerRETURNAD<br>   MachineFrameInfo *MFI = MF.getFrameInfo();<br>   MFI->setReturnAddressIsTaken(true);<br> +  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   SDLoc dl(Op);<br>   unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();<br> Modified: llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/Sparc/SparcISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -26,6 +26,7 @@<br> #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"<br> #include "llvm/IR/DerivedTypes.h"<br> #include "llvm/IR/Function.h"<br>+#include "llvm/IR/LLVMContext.h"<br> #include "llvm/IR/Module.h"<br> #include "llvm/Support/ErrorHandling.h"<br> using namespace llvm;<br>@@ -2470,6 +2471,12 @@ static SDValue LowerRETURNADDR(SDValue O<br>   MachineFrameInfo *MFI = MF.getFrameInfo();<br>   MFI->setReturnAddressIsTaken(true);<br> +  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   EVT VT = Op.getValueType();<br>   SDLoc dl(Op);<br>   uint64_t depth = Op.getConstantOperandVal(0);<br><br>Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=198531&r1=198530&r2=198531&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)<br>+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sat Jan  4 19:47:20 2014<br>@@ -12180,6 +12180,12 @@ SDValue X86TargetLowering::LowerRETURNAD<br>   MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();<br>   MFI->setReturnAddressIsTaken(true);<br> +  if (!isa<ConstantSDNode>(Op.getOperand(0))) {<br>+    DAG.getContext()->emitError("argument to '__builtin_return_address' must "<br>+                                "be a constant integer");<br>+    return SDValue();<br>+  }<br>+<br>   unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();<br>   SDLoc dl(Op);<br>   EVT PtrVT = getPointerTy();<br><br>Added: llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll?rev=198531&view=auto">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll?rev=198531&view=auto</a><br>==============================================================================<br>--- llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll (added)<br>+++ llvm/trunk/test/CodeGen/Generic/builtin-returnaddress-error.ll Sat Jan  4 19:47:20 2014<br>@@ -0,0 +1,27 @@<br>+; RUN: not llc < %s -O0 2> %t1<br>+; RUN: FileCheck %s < %t1<br>+<br>+; CHECK: argument to '__builtin_return_address' must be a constant integer<br>+<br>+define i32* @foo() {<br>+entry:<br>+  %t1 = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 0, i32 0)<br>+  %t2 = extractvalue { i32, i1 } %t1, 0<br>+  %t3 = extractvalue { i32, i1 } %t1, 1<br>+  br i1 %t3, label %cont, label %trap<br>+<br>+trap:<br>+  call void @llvm.trap()<br>+  unreachable<br>+<br>+cont:<br>+  %t5 = call i8* @llvm.returnaddress(i32 %t2)<br>+  %t6 = bitcast i8* %t5 to i32*<br>+  ret i32* %t6<br>+}<br>+<br>+declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32)<br>+<br>+declare void @llvm.trap()<br>+<br>+declare i8* @llvm.returnaddress(i32)<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote>--<span class="Apple-converted-space"> </span><br><a href="http://www.nuanti.com">http://www.nuanti.com</a><br>the browser experts<br><br></blockquote></blockquote><br>--<span class="Apple-converted-space"> </span><br><a href="http://www.nuanti.com/">http://www.nuanti.com</a><br>the browser experts</div></blockquote></div><br></div></body></html>