summaryrefslogtreecommitdiff
path: root/lib/AsmParser
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2017-10-02 18:31:29 +0000
committerAdrian Prantl <aprantl@apple.com>2017-10-02 18:31:29 +0000
commit733fe2f23133cccdd7bac660abd76577b0589081 (patch)
tree001487e93e5b65a1aa873a535b50696fed02eea9 /lib/AsmParser
parentfc20547ae6d3528a850caf7438d4c276ab47b3be (diff)
Move the stripping of invalid debug info from the Verifier to AutoUpgrade.
This came out of a recent discussion on llvm-dev (https://reviews.llvm.org/D38042). Currently the Verifier will strip the debug info metadata from a module if it finds the dbeug info to be malformed. This feature is very valuable since it allows us to improve the Verifier by making it stricter without breaking bcompatibility, but arguable the Verifier pass should not be modifying the IR. This patch moves the stripping of broken debug info into AutoUpgrade (UpgradeDebugInfo to be precise), which is a much better location for this since the stripping of malformed (i.e., produced by older, buggy versions of Clang) is a (harsh) form of AutoUpgrade. This change is mostly NFC in nature, the one big difference is the behavior when LLVM module passes are introducing malformed debug info. Prior to this patch, a NoAsserts build would have printed a warning and stripped the debug info, after this patch the Verifier will report a fatal error. I believe this behavior is actually more desirable anyway. Differential Revision: https://reviews.llvm.org/D38184 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314699 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r--lib/AsmParser/LLParser.cpp3
-rw-r--r--lib/AsmParser/LLParser.h9
-rw-r--r--lib/AsmParser/Parser.cpp24
3 files changed, 22 insertions, 14 deletions
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 9ae5ff1f6ef..4dc5d81cd08 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -237,7 +237,8 @@ bool LLParser::ValidateEndOfModule() {
}
}
- UpgradeDebugInfo(*M);
+ if (UpgradeDebugInfo)
+ llvm::UpgradeDebugInfo(*M);
UpgradeModuleFlags(*M);
diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h
index d5b059355c4..5dadf521538 100644
--- a/lib/AsmParser/LLParser.h
+++ b/lib/AsmParser/LLParser.h
@@ -139,11 +139,16 @@ namespace llvm {
std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
+ /// Only the llvm-as tool may set this to false to bypass
+ /// UpgradeDebuginfo so it can generate broken bitcode.
+ bool UpgradeDebugInfo;
+
public:
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M,
- SlotMapping *Slots = nullptr)
+ SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true)
: Context(M->getContext()), Lex(F, SM, Err, M->getContext()), M(M),
- Slots(Slots), BlockAddressPFS(nullptr) {}
+ Slots(Slots), BlockAddressPFS(nullptr),
+ UpgradeDebugInfo(UpgradeDebugInfo) {}
bool Run();
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);
diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp
index bee07ad9e0a..a43ae2b5577 100644
--- a/lib/AsmParser/Parser.cpp
+++ b/lib/AsmParser/Parser.cpp
@@ -23,22 +23,21 @@
using namespace llvm;
bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
- SlotMapping *Slots) {
+ SlotMapping *Slots, bool UpgradeDebugInfo) {
SourceMgr SM;
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
- return LLParser(F.getBuffer(), SM, Err, &M, Slots).Run();
+ return LLParser(F.getBuffer(), SM, Err, &M, Slots, UpgradeDebugInfo).Run();
}
-std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
- SMDiagnostic &Err,
- LLVMContext &Context,
- SlotMapping *Slots) {
+std::unique_ptr<Module>
+llvm::parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context,
+ SlotMapping *Slots, bool UpgradeDebugInfo) {
std::unique_ptr<Module> M =
make_unique<Module>(F.getBufferIdentifier(), Context);
- if (parseAssemblyInto(F, *M, Err, Slots))
+ if (parseAssemblyInto(F, *M, Err, Slots, UpgradeDebugInfo))
return nullptr;
return M;
@@ -47,7 +46,8 @@ std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
SMDiagnostic &Err,
LLVMContext &Context,
- SlotMapping *Slots) {
+ SlotMapping *Slots,
+ bool UpgradeDebugInfo) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Filename);
if (std::error_code EC = FileOrErr.getError()) {
@@ -56,15 +56,17 @@ std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
return nullptr;
}
- return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots);
+ return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots,
+ UpgradeDebugInfo);
}
std::unique_ptr<Module> llvm::parseAssemblyString(StringRef AsmString,
SMDiagnostic &Err,
LLVMContext &Context,
- SlotMapping *Slots) {
+ SlotMapping *Slots,
+ bool UpgradeDebugInfo) {
MemoryBufferRef F(AsmString, "<string>");
- return parseAssembly(F, Err, Context, Slots);
+ return parseAssembly(F, Err, Context, Slots, UpgradeDebugInfo);
}
Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err,