<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Devang,<div><br></div><div>Is this the right fix or just a work around? Should llvm-gcc be generating these invalid declare intrinsics in the first place? It seems like this will increase compile time. It could be noticeable when it's in fastisel mode, no?</div><div><br></div><div><span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 11px; ">+    DIDescriptor DI(GV);<br>+    // Check current version. Allow Version6 for now.<br>+    unsigned Version = DI.getVersion();<br>+    if (Version != DIDescriptor::Version7 && Version != DIDescriptor::Version6)<br>+      return false;</span></div><div><font class="Apple-style-span" face="-webkit-monospace" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="-webkit-monospace" size="3"><span class="Apple-style-span" style="font-size: 11px;">I know DIDescriptor is light weight. But is it necessary to create the descriptor just to check the version number? Can you add a helper function to DebugInfo that examines GV and returns its corresponding version?</span></font></div><div><br></div><div>Also</div><div><span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 11px; ">+    if (DW && SPI->getContext() && DW->ValidDebugInfo(SPI->getContext())) {</span></div><div><font class="Apple-style-span" face="-webkit-monospace" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div><font class="Apple-style-span" face="-webkit-monospace" size="3"><span class="Apple-style-span" style="font-size: 11px;">You might as well fold the "SPI->getContext()" check into ValidDebugInfo.</span></font></div><div><br></div><div>Evan</div><div><br></div><div><br><div><div>On Jan 15, 2009, at 3:41 PM, Devang Patel wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Author: dpatel<br>Date: Thu Jan 15 17:41:32 2009<br>New Revision: 62286<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=62286&view=rev">http://llvm.org/viewvc/llvm-project?rev=62286&view=rev</a><br>Log:<br><br>Validate dbg_* intrinsics before lowering them.<br><br><br>Added:<br>    llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll<br>Modified:<br>    llvm/trunk/include/llvm/CodeGen/DwarfWriter.h<br>    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp<br>    llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp<br>    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp<br><br>Modified: llvm/trunk/include/llvm/CodeGen/DwarfWriter.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DwarfWriter.h?rev=62286&r1=62285&r2=62286&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DwarfWriter.h?rev=62286&r1=62285&r2=62286&view=diff</a><br><br>==============================================================================<br>--- llvm/trunk/include/llvm/CodeGen/DwarfWriter.h (original)<br>+++ llvm/trunk/include/llvm/CodeGen/DwarfWriter.h Thu Jan 15 17:41:32 2009<br>@@ -29,6 +29,7 @@<br> class DwarfException;<br> class MachineModuleInfo;<br> class MachineFunction;<br>+class Value;<br> class Module;<br> class GlobalVariable;<br> class TargetAsmInfo;<br>@@ -75,6 +76,8 @@<br>   ///<br>   void EndFunction(MachineFunction *MF);<br><br>+  /// ValidDebugInfo - Return true if V represents valid debug info value.<br>+  bool ValidDebugInfo(Value *V);<br><br>   /// label. Returns a unique label ID used to generate a label and provide<br>   /// correspondence to the source line list.<br><br>Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=62286&r1=62285&r2=62286&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=62286&r1=62285&r2=62286&view=diff</a><br><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Thu Jan 15 17:41:32 2009<br>@@ -19,6 +19,7 @@<br> #include "llvm/ADT/UniqueVector.h"<br> #include "llvm/Module.h"<br> #include "llvm/DerivedTypes.h"<br>+#include "llvm/Constants.h"<br> #include "llvm/CodeGen/AsmPrinter.h"<br> #include "llvm/CodeGen/MachineModuleInfo.h"<br> #include "llvm/CodeGen/MachineFrameInfo.h"<br>@@ -100,6 +101,25 @@<br>     getGlobalVariablesUsing(UseRoot, Result);<br> }<br><br>+/// getGlobalVariable - Return either a direct or cast Global value.<br>+///<br>+static GlobalVariable *getGlobalVariable(Value *V) {<br>+  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {<br>+    return GV;<br>+  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {<br>+    if (CE->getOpcode() == Instruction::BitCast) {<br>+      return dyn_cast<GlobalVariable>(CE->getOperand(0));<br>+    } else if (CE->getOpcode() == Instruction::GetElementPtr) {<br>+      for (unsigned int i=1; i<CE->getNumOperands(); i++) {<br>+        if (!CE->getOperand(i)->isNullValue())<br>+          return NULL;<br>+      }<br>+      return dyn_cast<GlobalVariable>(CE->getOperand(0));<br>+    }<br>+  }<br>+  return NULL;<br>+}<br>+<br> //===----------------------------------------------------------------------===//<br> /// DWLabel - Labels are used to track locations in the assembler file.<br> /// Labels appear in the form @verbatim <prefix><Tag><Number> @endverbatim,<br>@@ -3056,6 +3076,26 @@<br><br> public:<br><br>+  /// ValidDebugInfo - Return true if V represents valid debug info value.<br>+  bool ValidDebugInfo(Value *V) {<br>+    GlobalVariable *GV = getGlobalVariable(V);<br>+    if (!GV)<br>+      return false;<br>+    <br>+    if (GV->getLinkage() != GlobalValue::InternalLinkage<br>+        && GV->getLinkage() != GlobalValue::LinkOnceLinkage)<br>+      return false;<br>+<br>+    DIDescriptor DI(GV);<br>+    // Check current version. Allow Version6 for now.<br>+    unsigned Version = DI.getVersion();<br>+    if (Version != DIDescriptor::Version7 && Version != DIDescriptor::Version6)<br>+      return false;<br>+<br>+    //FIXME - Check individual descriptors.<br>+    return true;<br>+  }<br>+<br>   /// RecordSourceLine - Records location information and associates it with a <br>   /// label. Returns a unique label ID used to generate a label and provide<br>   /// correspondence to the source line list.<br>@@ -4221,6 +4261,11 @@<br>     MMI->EndFunction();<br> }<br><br>+/// ValidDebugInfo - Return true if V represents valid debug info value.<br>+bool DwarfWriter::ValidDebugInfo(Value *V) {<br>+  return DD->ValidDebugInfo(V);<br>+}<br>+<br> /// RecordSourceLine - Records location information and associates it with a <br> /// label. Returns a unique label ID used to generate a label and provide<br> /// correspondence to the source line list.<br><br>Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp?rev=62286&r1=62285&r2=62286&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp?rev=62286&r1=62285&r2=62286&view=diff</a><br><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp Thu Jan 15 17:41:32 2009<br>@@ -317,7 +317,7 @@<br>   default: break;<br>   case Intrinsic::dbg_stoppoint: {<br>     DbgStopPointInst *SPI = cast<DbgStopPointInst>(I);<br>-    if (DW && SPI->getContext()) {<br>+    if (DW && SPI->getContext() && DW->ValidDebugInfo(SPI->getContext())) {<br>       DICompileUnit CU(cast<GlobalVariable>(SPI->getContext()));<br>       unsigned SrcFile = DW->RecordSource(CU.getDirectory(),<br>                                           CU.getFilename());<br>@@ -331,7 +331,7 @@<br>   }<br>   case Intrinsic::dbg_region_start: {<br>     DbgRegionStartInst *RSI = cast<DbgRegionStartInst>(I);<br>-    if (DW && RSI->getContext()) {<br>+    if (DW && RSI->getContext() && DW->ValidDebugInfo(RSI->getContext())) {<br>       unsigned ID = <br>         DW->RecordRegionStart(cast<GlobalVariable>(RSI->getContext()));<br>       const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);<br>@@ -341,7 +341,7 @@<br>   }<br>   case Intrinsic::dbg_region_end: {<br>     DbgRegionEndInst *REI = cast<DbgRegionEndInst>(I);<br>-    if (DW && REI->getContext()) {<br>+    if (DW && REI->getContext() && DW->ValidDebugInfo(REI->getContext())) {<br>       unsigned ID = <br>         DW->RecordRegionEnd(cast<GlobalVariable>(REI->getContext()));<br>       const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);<br>@@ -353,7 +353,7 @@<br>     if (!DW) return true;<br>     DbgFuncStartInst *FSI = cast<DbgFuncStartInst>(I);<br>     Value *SP = FSI->getSubprogram();<br>-    if (SP) {<br>+    if (SP && DW->ValidDebugInfo(SP)) {<br>       // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is<br>       // what (most?) gdb expects.<br>       DISubprogram Subprogram(cast<GlobalVariable>(SP));<br>@@ -375,7 +375,7 @@<br>   case Intrinsic::dbg_declare: {<br>     DbgDeclareInst *DI = cast<DbgDeclareInst>(I);<br>     Value *Variable = DI->getVariable();<br>-    if (DW && Variable) {<br>+    if (DW && Variable && DW->ValidDebugInfo(Variable)) {<br>       // Determine the address of the declared object.<br>       Value *Address = DI->getAddress();<br>       if (BitCastInst *BCI = dyn_cast<BitCastInst>(Address))<br><br>Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=62286&r1=62285&r2=62286&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=62286&r1=62285&r2=62286&view=diff</a><br><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Thu Jan 15 17:41:32 2009<br>@@ -3746,7 +3746,7 @@<br>   case Intrinsic::dbg_stoppoint: {<br>     DwarfWriter *DW = DAG.getDwarfWriter();<br>     DbgStopPointInst &SPI = cast<DbgStopPointInst>(I);<br>-    if (DW && SPI.getContext())<br>+    if (DW && SPI.getContext() && DW->ValidDebugInfo(SPI.getContext()))<br>       DAG.setRoot(DAG.getDbgStopPoint(getRoot(),<br>                                       SPI.getLine(),<br>                                       SPI.getColumn(),<br>@@ -3756,7 +3756,7 @@<br>   case Intrinsic::dbg_region_start: {<br>     DwarfWriter *DW = DAG.getDwarfWriter();<br>     DbgRegionStartInst &RSI = cast<DbgRegionStartInst>(I);<br>-    if (DW && RSI.getContext()) {<br>+    if (DW && RSI.getContext() && DW->ValidDebugInfo(RSI.getContext())) {<br>       unsigned LabelID = <br>         DW->RecordRegionStart(cast<GlobalVariable>(RSI.getContext()));<br>       DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID));<br>@@ -3767,7 +3767,7 @@<br>   case Intrinsic::dbg_region_end: {<br>     DwarfWriter *DW = DAG.getDwarfWriter();<br>     DbgRegionEndInst &REI = cast<DbgRegionEndInst>(I);<br>-    if (DW && REI.getContext()) {<br>+    if (DW && REI.getContext() && DW->ValidDebugInfo(REI.getContext())) {<br>       unsigned LabelID = <br>         DW->RecordRegionEnd(cast<GlobalVariable>(REI.getContext()));<br>       DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID));<br>@@ -3780,7 +3780,7 @@<br>     if (!DW) return 0;<br>     DbgFuncStartInst &FSI = cast<DbgFuncStartInst>(I);<br>     Value *SP = FSI.getSubprogram();<br>-    if (SP) {<br>+    if (SP && DW->ValidDebugInfo(SP)) {<br>       // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is<br>       // what (most?) gdb expects.<br>       DISubprogram Subprogram(cast<GlobalVariable>(SP));<br>@@ -3802,7 +3802,7 @@<br>     DwarfWriter *DW = DAG.getDwarfWriter();<br>     DbgDeclareInst &DI = cast<DbgDeclareInst>(I);<br>     Value *Variable = DI.getVariable();<br>-    if (DW && Variable)<br>+    if (DW && Variable && DW->ValidDebugInfo(Variable))<br>       DAG.setRoot(DAG.getNode(ISD::DECLARE, MVT::Other, getRoot(),<br>                               getValue(DI.getAddress()), getValue(Variable)));<br>     return 0;<br><br>Added: llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll?rev=62286&view=auto">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll?rev=62286&view=auto</a><br><br>==============================================================================<br>--- llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll (added)<br>+++ llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll Thu Jan 15 17:41:32 2009<br>@@ -0,0 +1,15 @@<br>+<br>+; RUN: llvm-as < %s | llc -f -o /dev/null<br>+target triple = "powerpc-apple-darwin9.5"<br>+        %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }*, i8*, i8* }<br><a href="mailto:+@llvm.dbg.variable24">+@llvm.dbg.variable24</a> = external constant %llvm.dbg.variable.type                ; <%llvm.dbg.variable.type*> [#uses=1]<br>+<br>+declare void @llvm.dbg.declare({ }*, { }*) nounwind<br>+<br>+define i32 @isascii(i32 %_c) nounwind {<br>+entry:<br>+        call void @llvm.dbg.declare({ }* null, { }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable24 to { }*))<br>+        unreachable<br>+}<br>+<br>+<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></div></blockquote></div><br></div></body></html>