llvm.org GIT mirror llvm / 733fe2f
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 Adrian Prantl 1 year, 11 months ago
46 changed file(s) with 156 addition(s) and 177 deletion(s). Raw diff Collapse all Expand all
3535 /// \param Context Context in which to allocate globals info.
3636 /// \param Slots The optional slot mapping that will be initialized during
3737 /// parsing.
38 std::unique_ptr parseAssemblyFile(StringRef Filename,
39 SMDiagnostic &Error,
40 LLVMContext &Context,
41 SlotMapping *Slots = nullptr);
38 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
39 /// This option should only be set to false by llvm-as
40 /// for use inside the LLVM testuite!
41 std::unique_ptr
42 parseAssemblyFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
43 SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true);
4244
4345 /// The function is a secondary interface to the LLVM Assembly Parser. It parses
4446 /// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
5153 /// \param Context Context in which to allocate globals info.
5254 /// \param Slots The optional slot mapping that will be initialized during
5355 /// parsing.
56 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
57 /// This option should only be set to false by llvm-as
58 /// for use inside the LLVM testuite!
5459 std::unique_ptr parseAssemblyString(StringRef AsmString,
5560 SMDiagnostic &Error,
5661 LLVMContext &Context,
57 SlotMapping *Slots = nullptr);
62 SlotMapping *Slots = nullptr,
63 bool UpgradeDebugInfo = true);
5864
5965 /// parseAssemblyFile and parseAssemblyString are wrappers around this function.
6066 /// \brief Parse LLVM Assembly from a MemoryBuffer.
6268 /// \param Err Error result info.
6369 /// \param Slots The optional slot mapping that will be initialized during
6470 /// parsing.
71 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
72 /// This option should only be set to false by llvm-as
73 /// for use inside the LLVM testuite!
6574 std::unique_ptr parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
6675 LLVMContext &Context,
67 SlotMapping *Slots = nullptr);
76 SlotMapping *Slots = nullptr,
77 bool UpgradeDebugInfo = true);
6878
6979 /// This function is the low-level interface to the LLVM Assembly Parser.
7080 /// This is kept as an independent function instead of being inlined into
7787 /// \param Slots The optional slot mapping that will be initialized during
7888 /// parsing.
7989 /// \return true on error.
90 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
91 /// This option should only be set to false by llvm-as
92 /// for use inside the LLVM testuite!
8093 bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
81 SlotMapping *Slots = nullptr);
94 SlotMapping *Slots = nullptr,
95 bool UpgradeDebugInfo = true);
8296
8397 /// Parse a type and a constant value in the given string.
8498 ///
3636 /// If the given MemoryBuffer holds a bitcode image, return a Module
3737 /// for it. Otherwise, attempt to parse it as LLVM Assembly and return
3838 /// a Module for it.
39 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
40 /// This option should only be set to false by llvm-as
41 /// for use inside the LLVM testuite!
3942 std::unique_ptr parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
40 LLVMContext &Context);
43 LLVMContext &Context,
44 bool UpgradeDebugInfo = true);
4145
4246 /// If the given file holds a bitcode image, return a Module for it.
4347 /// Otherwise, attempt to parse it as LLVM Assembly and return a Module
4448 /// for it.
49 /// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
50 /// This option should only be set to false by llvm-as
51 /// for use inside the LLVM testuite!
4552 std::unique_ptr parseIRFile(StringRef Filename, SMDiagnostic &Err,
46 LLVMContext &Context);
53 LLVMContext &Context,
54 bool UpgradeDebugInfo = true);
4755 }
4856
4957 #endif
236236 }
237237 }
238238
239 UpgradeDebugInfo(*M);
239 if (UpgradeDebugInfo)
240 llvm::UpgradeDebugInfo(*M);
240241
241242 UpgradeModuleFlags(*M);
242243
138138 std::map > ForwardRefAttrGroups;
139139 std::map NumberedAttrBuilders;
140140
141 /// Only the llvm-as tool may set this to false to bypass
142 /// UpgradeDebuginfo so it can generate broken bitcode.
143 bool UpgradeDebugInfo;
144
141145 public:
142146 LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M,
143 SlotMapping *Slots = nullptr)
147 SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true)
144148 : Context(M->getContext()), Lex(F, SM, Err, M->getContext()), M(M),
145 Slots(Slots), BlockAddressPFS(nullptr) {}
149 Slots(Slots), BlockAddressPFS(nullptr),
150 UpgradeDebugInfo(UpgradeDebugInfo) {}
146151 bool Run();
147152
148153 bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);
2222 using namespace llvm;
2323
2424 bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
25 SlotMapping *Slots) {
25 SlotMapping *Slots, bool UpgradeDebugInfo) {
2626 SourceMgr SM;
2727 std::unique_ptr Buf = MemoryBuffer::getMemBuffer(F);
2828 SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
2929
30 return LLParser(F.getBuffer(), SM, Err, &M, Slots).Run();
30 return LLParser(F.getBuffer(), SM, Err, &M, Slots, UpgradeDebugInfo).Run();
3131 }
3232
33 std::unique_ptr llvm::parseAssembly(MemoryBufferRef F,
34 SMDiagnostic &Err,
35 LLVMContext &Context,
36 SlotMapping *Slots) {
33 std::unique_ptr
34 llvm::parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context,
35 SlotMapping *Slots, bool UpgradeDebugInfo) {
3736 std::unique_ptr M =
3837 make_unique(F.getBufferIdentifier(), Context);
3938
40 if (parseAssemblyInto(F, *M, Err, Slots))
39 if (parseAssemblyInto(F, *M, Err, Slots, UpgradeDebugInfo))
4140 return nullptr;
4241
4342 return M;
4645 std::unique_ptr llvm::parseAssemblyFile(StringRef Filename,
4746 SMDiagnostic &Err,
4847 LLVMContext &Context,
49 SlotMapping *Slots) {
48 SlotMapping *Slots,
49 bool UpgradeDebugInfo) {
5050 ErrorOr> FileOrErr =
5151 MemoryBuffer::getFileOrSTDIN(Filename);
5252 if (std::error_code EC = FileOrErr.getError()) {
5555 return nullptr;
5656 }
5757
58 return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots);
58 return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots,
59 UpgradeDebugInfo);
5960 }
6061
6162 std::unique_ptr llvm::parseAssemblyString(StringRef AsmString,
6263 SMDiagnostic &Err,
6364 LLVMContext &Context,
64 SlotMapping *Slots) {
65 SlotMapping *Slots,
66 bool UpgradeDebugInfo) {
6567 MemoryBufferRef F(AsmString, "");
66 return parseAssembly(F, Err, Context, Slots);
68 return parseAssembly(F, Err, Context, Slots, UpgradeDebugInfo);
6769 }
6870
6971 Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err,
2626 #include "llvm/IR/IntrinsicInst.h"
2727 #include "llvm/IR/LLVMContext.h"
2828 #include "llvm/IR/Module.h"
29 #include "llvm/IR/Verifier.h"
2930 #include "llvm/Support/ErrorHandling.h"
3031 #include "llvm/Support/Regex.h"
3132 #include
23572358 /// info. Return true if module is modified.
23582359 bool llvm::UpgradeDebugInfo(Module &M) {
23592360 unsigned Version = getDebugMetadataVersionFromModule(M);
2360 if (Version == DEBUG_METADATA_VERSION)
2361 return false;
2362
2363 bool RetCode = StripDebugInfo(M);
2364 if (RetCode) {
2361 if (Version == DEBUG_METADATA_VERSION) {
2362 bool BrokenDebugInfo = false;
2363 if (verifyModule(M, &llvm::errs(), &BrokenDebugInfo))
2364 report_fatal_error("Broken module found, compilation aborted!");
2365 if (!BrokenDebugInfo)
2366 // Everything is ok.
2367 return false;
2368 else {
2369 // Diagnose malformed debug info.
2370 DiagnosticInfoIgnoringInvalidDebugMetadata Diag(M);
2371 M.getContext().diagnose(Diag);
2372 }
2373 }
2374 bool Modified = StripDebugInfo(M);
2375 if (Modified && Version != DEBUG_METADATA_VERSION) {
2376 // Diagnose a version mismatch.
23652377 DiagnosticInfoDebugMetadataVersion DiagVersion(M, Version);
23662378 M.getContext().diagnose(DiagVersion);
23672379 }
2368 return RetCode;
2380 return Modified;
23692381 }
23702382
23712383 bool llvm::UpgradeModuleFlags(Module &M) {
289289
290290 bool llvm::stripDebugInfo(Function &F) {
291291 bool Changed = false;
292 if (F.getSubprogram()) {
292 if (F.getMetadata(LLVMContext::MD_dbg)) {
293293 Changed = true;
294294 F.setSubprogram(nullptr);
295295 }
14301430 MDNode *GlobalObject::getMetadata(unsigned KindID) const {
14311431 SmallVector MDs;
14321432 getMetadata(KindID, MDs);
1433 assert(MDs.size() <= 1 && "Expected at most one metadata attachment");
14341433 if (MDs.empty())
14351434 return nullptr;
14361435 return MDs[0];
46834683 HasErrors |= !V->verify(F);
46844684
46854685 HasErrors |= !V->verify();
4686 if (FatalErrors) {
4687 if (HasErrors)
4688 report_fatal_error("Broken module found, compilation aborted!");
4689 assert(!V->hasBrokenDebugInfo() && "Module contains invalid debug info");
4690 }
4691
4692 // Strip broken debug info.
4693 if (V->hasBrokenDebugInfo()) {
4694 DiagnosticInfoIgnoringInvalidDebugMetadata DiagInvalid(M);
4695 M.getContext().diagnose(DiagInvalid);
4696 if (!StripDebugInfo(M))
4697 report_fatal_error("Failed to strip malformed debug info");
4698 }
4686 if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo()))
4687 report_fatal_error("Broken module found, compilation aborted!");
46994688 return false;
47004689 }
47014690
49984987
49994988 PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) {
50004989 auto Res = AM.getResult(M);
5001 if (FatalErrors) {
5002 if (Res.IRBroken)
5003 report_fatal_error("Broken module found, compilation aborted!");
5004 assert(!Res.DebugInfoBroken && "Module contains invalid debug info");
5005 }
5006
5007 // Strip broken debug info.
5008 if (Res.DebugInfoBroken) {
5009 DiagnosticInfoIgnoringInvalidDebugMetadata DiagInvalid(M);
5010 M.getContext().diagnose(DiagInvalid);
5011 if (!StripDebugInfo(M))
5012 report_fatal_error("Failed to strip malformed debug info");
5013 }
4990 if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
4991 report_fatal_error("Broken module found, compilation aborted!");
4992
50144993 return PreservedAnalyses::all();
50154994 }
50164995
6767 }
6868
6969 std::unique_ptr llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
70 LLVMContext &Context) {
70 LLVMContext &Context,
71 bool UpgradeDebugInfo) {
7172 NamedRegionTimer T(TimeIRParsingName, TimeIRParsingDescription,
7273 TimeIRParsingGroupName, TimeIRParsingGroupDescription,
7374 TimePassesIsEnabled);
8586 return std::move(ModuleOrErr.get());
8687 }
8788
88 return parseAssembly(Buffer, Err, Context);
89 return parseAssembly(Buffer, Err, Context, nullptr, UpgradeDebugInfo);
8990 }
9091
9192 std::unique_ptr llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err,
92 LLVMContext &Context) {
93 LLVMContext &Context,
94 bool UpgradeDebugInfo) {
9395 ErrorOr> FileOrErr =
9496 MemoryBuffer::getFileOrSTDIN(Filename);
9597 if (std::error_code EC = FileOrErr.getError()) {
98100 return nullptr;
99101 }
100102
101 return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context);
103 return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context,
104 UpgradeDebugInfo);
102105 }
103106
104107 //===----------------------------------------------------------------------===//
8282 #endif
8383 cl::Hidden);
8484
85 cl::opt LTOStripInvalidDebugInfo(
86 "lto-strip-invalid-debug-info",
87 cl::desc("Strip invalid debug info metadata during LTO instead of aborting."),
88 #ifdef NDEBUG
89 cl::init(true),
90 #else
91 cl::init(false),
92 #endif
93 cl::Hidden);
94
9585 cl::opt
9686 LTORemarksFilename("lto-pass-remarks-output",
9787 cl::desc("Output filename for pass remarks"),
494484 HasVerifiedInput = true;
495485
496486 bool BrokenDebugInfo = false;
497 if (verifyModule(*MergedModule, &dbgs(),
498 LTOStripInvalidDebugInfo ? &BrokenDebugInfo : nullptr))
487 if (verifyModule(*MergedModule, &dbgs(), &BrokenDebugInfo))
499488 report_fatal_error("Broken module found, compilation aborted!");
500489 if (BrokenDebugInfo) {
501490 emitWarning("Invalid debug info found, debug info will be stripped");
6262 extern cl::opt LTODiscardValueNames;
6363 extern cl::opt LTORemarksFilename;
6464 extern cl::opt LTOPassRemarksWithHotness;
65 extern cl::opt LTOStripInvalidDebugInfo;
6665 }
6766
6867 namespace {
157156 /// Verify the module and strip broken debug info.
158157 static void verifyLoadedModule(Module &TheModule) {
159158 bool BrokenDebugInfo = false;
160 if (verifyModule(TheModule, &dbgs(),
161 LTOStripInvalidDebugInfo ? &BrokenDebugInfo : nullptr))
159 if (verifyModule(TheModule, &dbgs(), &BrokenDebugInfo))
162160 report_fatal_error("Broken module found, compilation aborted!");
163161 if (BrokenDebugInfo) {
164162 TheModule.getContext().diagnose(ThinLTODiagnosticInfo(
None ; RUN: opt < %s -basicaa -globals-aa -gvn -S | FileCheck %s
0 ; RUN: opt < %s -basicaa -globals-aa -gvn -S -disable-verify | FileCheck %s
11
22 declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
33 define void @foo(i8* %x, i8* %y) {
None ; RUN: not opt -verify %s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output %s 2>&1 | FileCheck %s
11
22 ; Make sure we emit this diagnostic only once (which means we don't visit the
33 ; same DISubprogram twice.
55 ; CHECK-NEXT: !3 = distinct !DISubprogram(name: "patatino", scope: null, isLocal: false, isDefinition: true, isOptimized: false)
66 ; CHECK-NOT: subprogram definitions must have a compile unit
77 ; CHECK-NOT: !3 = distinct !DISubprogram(name: "patatino", scope: null, isLocal: false, isDefinition: true, isOptimized: false)
8 ; CHECK: warning: ignoring invalid debug info
89
910 define void @tinkywinky() !dbg !3 { ret void }
1011
None ; RUN: not llvm-as -disable-output -verify-debug-info < %s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output -verify-debug-info -o - < %s 2>&1 | FileCheck %s
11 ; ModuleID = 'test.c'
22 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
33 target triple = "x86_64-apple-macosx10.10.0"
2929 ; An old-style DILocation should not pass verify.
3030 ; CHECK: invalid !dbg metadata attachment
3131 !13 = !{i32 2, i32 2, !4, null}
32 ; CHECK: warning: ignoring invalid debug info
None ; RUN: not llvm-as -disable-output < %s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output < %s 2>&1 | FileCheck %s
11 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
22 target triple = "x86_64-apple-macosx10.9.0"
33
5252 ; CHECK-NEXT: !DIExpression({{[0-9]+}}, 64, 32, {{[0-9]+}})
5353 ; CHECK-NOT: invalid expression
5454 !27 = !DIExpression(DW_OP_LLVM_fragment, 64, 32, DW_OP_deref)
55 ; CHECK: warning: ignoring invalid debug info
44 ; alternative is that of keeping a map of visited GVs, which has non trivial
55 ; memory usage consequences on large testcases, or when LTO is the mode of
66 ; operation.
7 ; RUN: not llc %s 2>&1 | FileCheck %s
7 ; RUN: llvm-as -disable-output %s -o - 2>&1 | FileCheck %s
88 ; CHECK: missing global variable type
99 ; CHECK: missing global variable type
10 ; CHECK-NOT: missing global variable type
11 ; CHECK: warning: ignoring invalid debug info
1012
1113 !llvm.dbg.cu = !{!2}
1214 !llvm.module.flags = !{!63, !64}
None ; RUN: not opt -verify %s 2>&1 | FileCheck %s
0 ; RUN: opt -verify %s 2>&1 | FileCheck %s
11 ; CHECK: invalid type ref
22 ; CHECK-NOT: invalid type ref
33
0 ; RUN: llvm-as %s -disable-verify -o %t.bc
1 ; RUN: llvm-lto -lto-strip-invalid-debug-info=true \
2 ; RUN: -exported-symbol f -exported-symbol _f \
1 ; RUN: llvm-lto -exported-symbol f -exported-symbol _f \
32 ; RUN: -o %t.o %t.bc 2>&1 | \
43 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
54 ; RUN: llvm-nm %t.o | FileCheck %s
76 ; Check that missing debug locations on inlinable calls are a
87 ; recoverable error.
98
10 ; CHECK-WARN: Invalid debug info found, debug info will be stripped
9 ; CHECK-WARN: warning{{.*}} ignoring invalid debug info
1110 ; CHECK: {{f$}}
1211 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
1312 target triple = "x86_64-apple-macosx"
0 ; RUN: llvm-as -disable-verify %s -o %t.bc
11 ; ---- Full LTO ---------------------------------------------
2 ; RUN: not llvm-lto -lto-strip-invalid-debug-info=false \
3 ; RUN: -o %t.o %t.bc 2>&1 | \
4 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
5 ; RUN: llvm-lto -lto-strip-invalid-debug-info=true \
2 ; RUN: llvm-lto \
63 ; RUN: -exported-symbol foo -exported-symbol _foo \
74 ; RUN: -o %t.o %t.bc 2>&1 | \
85 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
96 ; RUN: llvm-nm %t.o | FileCheck %s
107 ; ---- Thin LTO (codegen only) ------------------------------
11 ; RUN: not llvm-lto -thinlto -thinlto-action=codegen \
12 ; RUN: -lto-strip-invalid-debug-info=false \
13 ; RUN: %t.bc -disable-verify 2>&1 | \
14 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
158 ; RUN: llvm-lto -thinlto -thinlto-action=codegen \
16 ; RUN: -lto-strip-invalid-debug-info=true \
179 ; RUN: %t.bc -disable-verify 2>&1 | \
1810 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
1911 ; ---- Thin LTO (optimize, strip main file) -----------------
2012 ; RUN: opt -disable-verify -module-summary %s -o %t.bc
2113 ; RUN: opt -disable-verify -module-summary %S/Inputs/strip-debug-info-bar.ll \
2214 ; RUN: -o %t2.bc
23 ; RUN: not llvm-lto -thinlto -thinlto-action=run \
24 ; RUN: -lto-strip-invalid-debug-info=false \
25 ; RUN: %t.bc -disable-verify 2>&1 | \
26 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
2715 ; RUN: llvm-lto -thinlto -thinlto-action=run \
28 ; RUN: -lto-strip-invalid-debug-info=true \
2916 ; RUN: %t.bc -disable-verify 2>&1 | \
3017 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
3118 ; ---- Thin LTO (optimize, strip imported file) -------------
3219 ; RUN: opt -disable-verify -strip-debug -module-summary %t.bc -o %t-stripped.bc
3320 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t-stripped.bc %t2.bc
34 ; RUN: not llvm-lto -thinlto -thinlto-action=import \
35 ; RUN: -thinlto-index=%t.index.bc \
36 ; RUN: -lto-strip-invalid-debug-info=false \
37 ; RUN: -exported-symbol foo -exported-symbol _foo \
38 ; RUN: %t-stripped.bc -disable-verify 2>&1 | \
39 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-ERR
4021 ; RUN: llvm-lto -thinlto -thinlto-action=import \
41 ; RUN: -lto-strip-invalid-debug-info=true \
4222 ; RUN: -thinlto-index=%t.index.bc \
4323 ; RUN: -exported-symbol foo -exported-symbol _foo \
4424 ; RUN: %t-stripped.bc -disable-verify 2>&1 | \
4525 ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN
4626
4727 ; CHECK-ERR: Broken module found, compilation aborted
48 ; CHECK-WARN: Invalid debug info found, debug info will be stripped
28 ; CHECK-WARN: warning{{.*}} ignoring invalid debug info
4929 ; CHECK-WARN-NOT: Broken module found
5030 ; CHECK: foo
5131 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
None ; RUN: not llvm-as %s -o - 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output %s -o - 2>&1 | FileCheck %s
11 source_filename = "t.c"
22 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
33 target triple = "x86_64-apple-macosx10.12.0"
1616 ret void, !dbg !9
1717 }
1818
19 ; CHECK: warning: ignoring invalid debug info
20
1921 !llvm.dbg.cu = !{!0}
2022 !llvm.module.flags = !{!2, !3}
2123
None ; RUN: not opt -S <%s 2>&1| FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1| FileCheck %s
11
22 define void @f() !dbg !14 {
33 ret void
1111 !8 = distinct !DICompileUnit(language: DW_LANG_Swift, producer: "clang",
1212 file: !2, emissionKind: 2)
1313 ; CHECK: invalid thrown type
14 ; CHECK: warning: ignoring invalid debug info
1415 !13 = !{!14}
1516 !14 = distinct !DISubprogram(name: "f", scope: !1,
1617 file: !2, line: 1, type: !3, isLocal: true,
None ; RUN: not llvm-as %s -o %t 2>&1 | FileCheck %s
0 ; RUN: llvm-as %s -o %t 2>&1 | FileCheck %s
11 ; Created and then edited from
22 ; extern void i();
33 ; void h() { i(); }
3838
3939 attributes #0 = { nounwind ssp uwtable }
4040
41 ; CHECK: warning: ignoring invalid debug info
42
4143 !llvm.dbg.cu = !{!0}
4244 !llvm.module.flags = !{!3, !4, !5}
4345 !llvm.ident = !{!6}
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: assembly parsed, but does not verify
2 ; CHECK-NEXT: invalid file
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: invalid file
2 ; CHECK: warning: ignoring invalid debug info
33
44 define void @blah() !dbg !3 {
55 ret void
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: assembly parsed, but does not verify
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: warning: ignoring invalid debug info
22
33 !llvm.module.flags = !{!0}
44 !llvm.dbg.cu = !{!1}
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: assembly parsed, but does not verify
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: warning: ignoring invalid debug info
22
33 !llvm.module.flags = !{!0}
44 !llvm.dbg.the_dbg_namespace_is_reserved = !{}
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: assembly parsed, but does not verify
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: warning: ignoring invalid debug info
22
33 !llvm.dbg.cu = !{!0}
44 !llvm.module.flags = !{!3}
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: assembly parsed, but does not verify
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
21 ; CHECK: line specified with no file
2 ; CHECK: warning: ignoring invalid debug info
33
44 define void @foo() !dbg !3 {
55 ret void
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: assembly parsed, but does not verify
2 ; CHECK-NEXT: invalid retained type
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
1 ; CHECK: invalid retained type
2 ; CHECK: warning: ignoring invalid debug info
33
44 !llvm.module.flags = !{!0}
55 !0 = !{i32 2, !"Debug Info Version", i32 3}
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
11
22 define void @foo() {
33 entry:
1313 ; CHECK-NEXT: ![[LOC]] = !{}
1414 }
1515
16 ; CHECK: warning: ignoring invalid debug info
1617 !llvm.module.flags = !{!0}
1718 !0 = !{i32 2, !"Debug Info Version", i32 3}
1819 !1 = distinct !DISubprogram()
None ; RUN: not opt -S <%s 2>&1| FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1| FileCheck %s
11
22 ; CHECK: !dbg attachment of global variable must be a DIGlobalVariableExpression
33 @g = common global i32 0, align 4, !dbg !0
1111 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
1212 !6 = !{i32 2, !"Dwarf Version", i32 4}
1313 !7 = !{i32 2, !"Debug Info Version", i32 3}
14 ; CHECK: warning: ignoring invalid debug info
None ; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output < %s -o /dev/null 2>&1 | FileCheck %s
11
22 declare void @llvm.dbg.declare(metadata, metadata, metadata)
33 declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
1111 ret void, !dbg !6
1212 }
1313
14 ; CHECK: warning: ignoring invalid debug info
15
1416 !llvm.dbg.cu = !{!0}
1517 !llvm.module.flags = !{!7, !8}
1618
None ; RUN: not opt -S <%s 2>&1| FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1| FileCheck %s
11
22 ; CHECK: fragment is larger than or outside of variable
33 ; CHECK: !DIGlobalVariableExpression(var: ![[VAR:[0-9]+]],
44 ; CHECK-SAME: expr: !DIExpression(DW_OP_LLVM_fragment, 0, 64))
55 ; CHECK: ![[VAR]] = !DIGlobalVariable(name: "g"
6 ; CHECK: warning: ignoring invalid debug info
67
78 @g = common global i32 0, align 4, !dbg !0
89
None ; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output < %s -o /dev/null 2>&1 | FileCheck %s
11
22 define i32 @foo() !dbg !4 {
33 entry:
1010 ret i32 0, !dbg !6
1111 }
1212
13 ; CHECK: warning: ignoring invalid debug info
1314 !llvm.dbg.cu = !{!0}
1415 !llvm.module.flags = !{!7, !8}
1516
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
11 ; CHECK: invalid llvm.dbg.declare intrinsic address/value
22 ; CHECK-NEXT: call void @llvm.dbg.declare({{.*}})
33 ; CHECK-NEXT: !""
4 ; CHECK: warning: ignoring invalid debug info
45
56 define void @foo(i32 %a) {
67 entry:
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
11 ; CHECK: invalid llvm.dbg.declare intrinsic expression
22 ; CHECK-NEXT: call void @llvm.dbg.declare({{.*}})
33 ; CHECK-NEXT: !""
4 ; CHECK: warning: ignoring invalid debug info
45
56 define void @foo(i32 %a) {
67 entry:
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
11 ; CHECK: invalid llvm.dbg.declare intrinsic variable
22 ; CHECK-NEXT: call void @llvm.dbg.declare({{.*}})
33 ; CHECK-NEXT: !""
4 ; CHECK: warning: ignoring invalid debug info
45
56 define void @foo(i32 %a) {
67 entry:
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
11 ; CHECK: invalid llvm.dbg.value intrinsic expression
22 ; CHECK-NEXT: call void @llvm.dbg.value({{.*}})
33 ; CHECK-NEXT: !""
4 ; CHECK: warning: ignoring invalid debug info
45
56 define void @foo(i32 %a) {
67 entry:
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
11 ; CHECK: invalid llvm.dbg.value intrinsic address/value
22 ; CHECK-NEXT: call void @llvm.dbg.value({{.*}})
33 ; CHECK-NEXT: !""
4 ; CHECK: warning: ignoring invalid debug info
45
56 define void @foo(i32 %a) {
67 entry:
None ; RUN: not llvm-as -disable-output <%s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output <%s 2>&1 | FileCheck %s
11 ; CHECK: invalid llvm.dbg.value intrinsic variable
22 ; CHECK-NEXT: call void @llvm.dbg.value({{.*}})
33 ; CHECK-NEXT: !""
4 ; CHECK: warning: ignoring invalid debug info
45
56 define void @foo(i32 %a) {
67 entry:
None ; RUN: not llvm-as %s -disable-output 2>&1 | FileCheck %s
0 ; RUN: llvm-as %s -disable-output 2>&1 | FileCheck %s
11
22 ; CHECK: function declaration may not have a !dbg attachment
33 declare !dbg !4 void @f1()
2525 unreachable
2626 }
2727
28 ; CHECK: warning: ignoring invalid debug info
2829 !llvm.module.flags = !{!0}
2930 !0 = !{i32 2, !"Debug Info Version", i32 3}
3031
None ; RUN: not opt -verify %s 2>&1 | FileCheck %s
0 ; RUN: llvm-as -disable-output %s 2>&1 | FileCheck %s
11
22 ; CHECK: invalid type ref
3 ; CHECK: warning: ignoring invalid debug info
34
45 @bar = global i64 0, align 8, !dbg !0
56
0 ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
1 ; RUN: llvm-as -disable-verify < %s 2>&1 | opt -verify -S | FileCheck %s --check-prefix=STRIP
1 ; RUN: llvm-as -disable-verify < %s | opt -verify -S | FileCheck %s --check-prefix=STRIP
22
33 ; STRIP-NOT: tbaa
44 ; STRIP: @f_0
9696
9797 // Parse the file now...
9898 SMDiagnostic Err;
99 std::unique_ptr M = parseAssemblyFile(InputFilename, Err, Context);
99 std::unique_ptr M =
100 parseAssemblyFile(InputFilename, Err, Context, nullptr, !DisableVerify);
100101 if (!M.get()) {
101102 Err.print(argv[0], errs());
102103 return 1;
443443 }
444444
445445 // Load the input module...
446 std::unique_ptr M = parseIRFile(InputFilename, Err, Context);
446 std::unique_ptr M =
447 parseIRFile(InputFilename, Err, Context, !NoVerify);
447448
448449 if (!M) {
449450 Err.print(argv[0], errs());
1616 #include "llvm/IR/IRBuilder.h"
1717 #include "llvm/IR/Instructions.h"
1818 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/IR/LegacyPassManager.h"
2019 #include "llvm/IR/Module.h"
2120 #include "gtest/gtest.h"
2221
148147 "have external or weak linkage!"));
149148 }
150149
151 TEST(VerifierTest, StripInvalidDebugInfo) {
150 TEST(VerifierTest, DetectInvalidDebugInfo) {
152151 {
153152 LLVMContext C;
154153 Module M("M", C);
163162 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
164163 NMD->addOperand(File);
165164 EXPECT_TRUE(verifyModule(M));
166
167 ModulePassManager MPM(true);
168 MPM.addPass(VerifierPass(false));
169 ModuleAnalysisManager MAM(true);
170 MAM.registerPass([&] { return VerifierAnalysis(); });
171 MPM.run(M, MAM);
172 EXPECT_FALSE(verifyModule(M));
173165 }
174166 {
175167 LLVMContext C;
194186 // Now break it by not listing the CU at all.
195187 M.eraseNamedMetadata(M.getOrInsertNamedMetadata("llvm.dbg.cu"));
196188 EXPECT_TRUE(verifyModule(M));
197
198 ModulePassManager MPM(true);
199 MPM.addPass(VerifierPass(false));
200 ModuleAnalysisManager MAM(true);
201 MAM.registerPass([&] { return VerifierAnalysis(); });
202 MPM.run(M, MAM);
203 EXPECT_FALSE(verifyModule(M));
204189 }
205 }
206
207 TEST(VerifierTest, StripInvalidDebugInfoLegacy) {
208 LLVMContext C;
209 Module M("M", C);
210 DIBuilder DIB(M);
211 DIB.createCompileUnit(dwarf::DW_LANG_C89, DIB.createFile("broken.c", "/"),
212 "unittest", false, "", 0);
213 DIB.finalize();
214 EXPECT_FALSE(verifyModule(M));
215
216 // Now break it.
217 auto *File = DIB.createFile("not-a-CU.f", ".");
218 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
219 NMD->addOperand(File);
220 EXPECT_TRUE(verifyModule(M));
221
222 legacy::PassManager Passes;
223 Passes.add(createVerifierPass(false));
224 Passes.run(M);
225 EXPECT_FALSE(verifyModule(M));
226190 }
227191
228192 } // end anonymous namespace