aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-01-15 23:41:32 +0000
committerDevang Patel <dpatel@apple.com>2009-01-15 23:41:32 +0000
commitcf3a4487c0627d15d03fb6fedc10b58f6e2c9ebe (patch)
treeb99fd06b4586d9db5e2df2549e1d6f9ec64707bd /lib/CodeGen/AsmPrinter/DwarfWriter.cpp
parentfa9c5eac33bef67e2faef166c902e3bb16efa30f (diff)
Validate dbg_* intrinsics before lowering them.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/AsmPrinter/DwarfWriter.cpp')
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfWriter.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
index 02f27d181a..f3ad9aa9d4 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<GlobalVariable>(V)) {
+ return GV;
+ } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
+ if (CE->getOpcode() == Instruction::BitCast) {
+ return dyn_cast<GlobalVariable>(CE->getOperand(0));
+ } else if (CE->getOpcode() == Instruction::GetElementPtr) {
+ for (unsigned int i=1; i<CE->getNumOperands(); i++) {
+ if (!CE->getOperand(i)->isNullValue())
+ return NULL;
+ }
+ return dyn_cast<GlobalVariable>(CE->getOperand(0));
+ }
+ }
+ return NULL;
+}
+
//===----------------------------------------------------------------------===//
/// DWLabel - Labels are used to track locations in the assembler file.
/// Labels appear in the form @verbatim <prefix><Tag><Number> @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.