aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2014-04-17 22:33:50 +0000
committerDiego Novillo <dnovillo@google.com>2014-04-17 22:33:50 +0000
commit0915c047c2e8d94eb9c8e726e10e2d1ef63db29c (patch)
tree3dbea92edbbe7dccd491690c6c7cc56a0548f660 /llvm/lib
parent9ced19abe89a248963b629528ff3e0fee930ed98 (diff)
downloadllvm-0915c047c2e8d94eb9c8e726e10e2d1ef63db29c.zip
llvm-0915c047c2e8d94eb9c8e726e10e2d1ef63db29c.tar.gz
llvm-0915c047c2e8d94eb9c8e726e10e2d1ef63db29c.tar.bz2
Fix bug 19437 - Only add discriminators for DWARF 4 and above.
Summary: This prevents the discriminator generation pass from triggering if the DWARF version being used in the module is prior to 4. Reviewers: echristo, dblaikie CC: llvm-commits Differential Revision: http://reviews.llvm.org/D3413 llvm-svn: 206507
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp10
-rw-r--r--llvm/lib/IR/Module.cpp8
-rw-r--r--llvm/lib/Transforms/Utils/AddDiscriminators.cpp9
3 files changed, 16 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index d5c8a0a..3b32639 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -168,14 +168,6 @@ DIType DbgVariable::getType() const {
} // end llvm namespace
-/// Return Dwarf Version by checking module flags.
-static unsigned getDwarfVersionFromModule(const Module *M) {
- Value *Val = M->getModuleFlag("Dwarf Version");
- if (!Val)
- return dwarf::DWARF_VERSION;
- return cast<ConstantInt>(Val)->getZExtValue();
-}
-
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
: Asm(A), MMI(Asm->MMI), FirstCU(0), PrevLabel(NULL), GlobalRangeCount(0),
InfoHolder(A, "info_string", DIEValueAllocator),
@@ -211,7 +203,7 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
DwarfVersion = DwarfVersionNumber
? DwarfVersionNumber
- : getDwarfVersionFromModule(MMI->getModule());
+ : MMI->getModule()->getDwarfVersion();
{
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 43f42bc..5dbed69c 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -23,6 +23,7 @@
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LeakDetector.h"
+#include "llvm/Support/Dwarf.h"
#include <algorithm>
#include <cstdarg>
#include <cstdlib>
@@ -429,3 +430,10 @@ void Module::dropAllReferences() {
for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I)
I->dropAllReferences();
}
+
+unsigned Module::getDwarfVersion() const {
+ Value *Val = getModuleFlag("Dwarf Version");
+ if (!Val)
+ return dwarf::DWARF_VERSION;
+ return cast<ConstantInt>(Val)->getZExtValue();
+}
diff --git a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp
index f42635e..a4d8138 100644
--- a/llvm/lib/Transforms/Utils/AddDiscriminators.cpp
+++ b/llvm/lib/Transforms/Utils/AddDiscriminators.cpp
@@ -154,10 +154,15 @@ static bool hasDebugInfo(const Function &F) {
/// file and line location as I2. This new lexical block will have a
/// different discriminator number than I1.
bool AddDiscriminators::runOnFunction(Function &F) {
- // No need to do anything if there is no debug info for this function.
// If the function has debug information, but the user has disabled
// discriminators, do nothing.
- if (!hasDebugInfo(F) || NoDiscriminators) return false;
+ // Simlarly, if the function has no debug info, do nothing.
+ // Finally, if this module is built with dwarf versions earlier than 4,
+ // do nothing (discriminator support is a DWARF 4 feature).
+ if (NoDiscriminators ||
+ !hasDebugInfo(F) ||
+ F.getParent()->getDwarfVersion() < 4)
+ return false;
bool Changed = false;
Module *M = F.getParent();