From: Devang Patel Date: Thu, 15 Jan 2009 23:41:32 +0000 (+0000) Subject: Validate dbg_* intrinsics before lowering them. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=cf3a4487c0627d15d03fb6fedc10b58f6e2c9ebe;p=oota-llvm.git Validate dbg_* intrinsics before lowering them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62286 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/DwarfWriter.h b/include/llvm/CodeGen/DwarfWriter.h index 7c9ada8305d..1616dfa4e90 100644 --- a/include/llvm/CodeGen/DwarfWriter.h +++ b/include/llvm/CodeGen/DwarfWriter.h @@ -29,6 +29,7 @@ class DwarfDebug; class DwarfException; class MachineModuleInfo; class MachineFunction; +class Value; class Module; class GlobalVariable; class TargetAsmInfo; @@ -75,6 +76,8 @@ public: /// void EndFunction(MachineFunction *MF); + /// ValidDebugInfo - Return true if V represents valid debug info value. + bool ValidDebugInfo(Value *V); /// label. Returns a unique label ID used to generate a label and provide /// correspondence to the source line list. diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 02f27d181a9..f3ad9aa9d4f 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/UniqueVector.h" #include "llvm/Module.h" #include "llvm/DerivedTypes.h" +#include "llvm/Constants.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineFrameInfo.h" @@ -100,6 +101,25 @@ getGlobalVariablesUsing(Module &M, const std::string &RootName, getGlobalVariablesUsing(UseRoot, Result); } +/// getGlobalVariable - Return either a direct or cast Global value. +/// +static GlobalVariable *getGlobalVariable(Value *V) { + if (GlobalVariable *GV = dyn_cast(V)) { + return GV; + } else if (ConstantExpr *CE = dyn_cast(V)) { + if (CE->getOpcode() == Instruction::BitCast) { + return dyn_cast(CE->getOperand(0)); + } else if (CE->getOpcode() == Instruction::GetElementPtr) { + for (unsigned int i=1; igetNumOperands(); i++) { + if (!CE->getOperand(i)->isNullValue()) + return NULL; + } + return dyn_cast(CE->getOperand(0)); + } + } + return NULL; +} + //===----------------------------------------------------------------------===// /// DWLabel - Labels are used to track locations in the assembler file. /// Labels appear in the form @verbatim @endverbatim, @@ -3056,6 +3076,26 @@ public: public: + /// ValidDebugInfo - Return true if V represents valid debug info value. + bool ValidDebugInfo(Value *V) { + GlobalVariable *GV = getGlobalVariable(V); + if (!GV) + return false; + + if (GV->getLinkage() != GlobalValue::InternalLinkage + && GV->getLinkage() != GlobalValue::LinkOnceLinkage) + return false; + + DIDescriptor DI(GV); + // Check current version. Allow Version6 for now. + unsigned Version = DI.getVersion(); + if (Version != DIDescriptor::Version7 && Version != DIDescriptor::Version6) + return false; + + //FIXME - Check individual descriptors. + return true; + } + /// RecordSourceLine - Records location information and associates it with a /// label. Returns a unique label ID used to generate a label and provide /// correspondence to the source line list. @@ -4221,6 +4261,11 @@ void DwarfWriter::EndFunction(MachineFunction *MF) { MMI->EndFunction(); } +/// ValidDebugInfo - Return true if V represents valid debug info value. +bool DwarfWriter::ValidDebugInfo(Value *V) { + return DD->ValidDebugInfo(V); +} + /// RecordSourceLine - Records location information and associates it with a /// label. Returns a unique label ID used to generate a label and provide /// correspondence to the source line list. diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index 5dd0afbae6f..d797d909c86 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -317,7 +317,7 @@ bool FastISel::SelectCall(User *I) { default: break; case Intrinsic::dbg_stoppoint: { DbgStopPointInst *SPI = cast(I); - if (DW && SPI->getContext()) { + if (DW && SPI->getContext() && DW->ValidDebugInfo(SPI->getContext())) { DICompileUnit CU(cast(SPI->getContext())); unsigned SrcFile = DW->RecordSource(CU.getDirectory(), CU.getFilename()); @@ -331,7 +331,7 @@ bool FastISel::SelectCall(User *I) { } case Intrinsic::dbg_region_start: { DbgRegionStartInst *RSI = cast(I); - if (DW && RSI->getContext()) { + if (DW && RSI->getContext() && DW->ValidDebugInfo(RSI->getContext())) { unsigned ID = DW->RecordRegionStart(cast(RSI->getContext())); const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); @@ -341,7 +341,7 @@ bool FastISel::SelectCall(User *I) { } case Intrinsic::dbg_region_end: { DbgRegionEndInst *REI = cast(I); - if (DW && REI->getContext()) { + if (DW && REI->getContext() && DW->ValidDebugInfo(REI->getContext())) { unsigned ID = DW->RecordRegionEnd(cast(REI->getContext())); const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL); @@ -353,7 +353,7 @@ bool FastISel::SelectCall(User *I) { if (!DW) return true; DbgFuncStartInst *FSI = cast(I); Value *SP = FSI->getSubprogram(); - if (SP) { + if (SP && DW->ValidDebugInfo(SP)) { // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is // what (most?) gdb expects. DISubprogram Subprogram(cast(SP)); @@ -375,7 +375,7 @@ bool FastISel::SelectCall(User *I) { case Intrinsic::dbg_declare: { DbgDeclareInst *DI = cast(I); Value *Variable = DI->getVariable(); - if (DW && Variable) { + if (DW && Variable && DW->ValidDebugInfo(Variable)) { // Determine the address of the declared object. Value *Address = DI->getAddress(); if (BitCastInst *BCI = dyn_cast(Address)) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 49b7ad80a28..241ad00e568 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -3746,7 +3746,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { case Intrinsic::dbg_stoppoint: { DwarfWriter *DW = DAG.getDwarfWriter(); DbgStopPointInst &SPI = cast(I); - if (DW && SPI.getContext()) + if (DW && SPI.getContext() && DW->ValidDebugInfo(SPI.getContext())) DAG.setRoot(DAG.getDbgStopPoint(getRoot(), SPI.getLine(), SPI.getColumn(), @@ -3756,7 +3756,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { case Intrinsic::dbg_region_start: { DwarfWriter *DW = DAG.getDwarfWriter(); DbgRegionStartInst &RSI = cast(I); - if (DW && RSI.getContext()) { + if (DW && RSI.getContext() && DW->ValidDebugInfo(RSI.getContext())) { unsigned LabelID = DW->RecordRegionStart(cast(RSI.getContext())); DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID)); @@ -3767,7 +3767,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { case Intrinsic::dbg_region_end: { DwarfWriter *DW = DAG.getDwarfWriter(); DbgRegionEndInst &REI = cast(I); - if (DW && REI.getContext()) { + if (DW && REI.getContext() && DW->ValidDebugInfo(REI.getContext())) { unsigned LabelID = DW->RecordRegionEnd(cast(REI.getContext())); DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID)); @@ -3780,7 +3780,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { if (!DW) return 0; DbgFuncStartInst &FSI = cast(I); Value *SP = FSI.getSubprogram(); - if (SP) { + if (SP && DW->ValidDebugInfo(SP)) { // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is // what (most?) gdb expects. DISubprogram Subprogram(cast(SP)); @@ -3802,7 +3802,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { DwarfWriter *DW = DAG.getDwarfWriter(); DbgDeclareInst &DI = cast(I); Value *Variable = DI.getVariable(); - if (DW && Variable) + if (DW && Variable && DW->ValidDebugInfo(Variable)) DAG.setRoot(DAG.getNode(ISD::DECLARE, MVT::Other, getRoot(), getValue(DI.getAddress()), getValue(Variable))); return 0; diff --git a/test/DebugInfo/2009-01-15-dbg_declare.ll b/test/DebugInfo/2009-01-15-dbg_declare.ll new file mode 100644 index 00000000000..475949a14e3 --- /dev/null +++ b/test/DebugInfo/2009-01-15-dbg_declare.ll @@ -0,0 +1,15 @@ + +; RUN: llvm-as < %s | llc -f -o /dev/null +target triple = "powerpc-apple-darwin9.5" + %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }*, i8*, i8* } +@llvm.dbg.variable24 = external constant %llvm.dbg.variable.type ; <%llvm.dbg.variable.type*> [#uses=1] + +declare void @llvm.dbg.declare({ }*, { }*) nounwind + +define i32 @isascii(i32 %_c) nounwind { +entry: + call void @llvm.dbg.declare({ }* null, { }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable24 to { }*)) + unreachable +} + +