Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.
/ swift-llvm Public archive

Commit 266994f

Browse files
committed
Merge remote-tracking branch 'origin/swift-4.1-branch' into stable
2 parents 6c622bf + 15d5238 commit 266994f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+254
-185
lines changed

include/llvm/AsmParser/Parser.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ class Type;
3636
/// \param Context Context in which to allocate globals info.
3737
/// \param Slots The optional slot mapping that will be initialized during
3838
/// parsing.
39-
std::unique_ptr<Module> parseAssemblyFile(StringRef Filename,
40-
SMDiagnostic &Error,
41-
LLVMContext &Context,
42-
SlotMapping *Slots = nullptr);
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!
42+
std::unique_ptr<Module>
43+
parseAssemblyFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
44+
SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true);
4345

4446
/// The function is a secondary interface to the LLVM Assembly Parser. It parses
4547
/// an ASCII string that (presumably) contains LLVM Assembly code. It returns a
@@ -52,20 +54,28 @@ std::unique_ptr<Module> parseAssemblyFile(StringRef Filename,
5254
/// \param Context Context in which to allocate globals info.
5355
/// \param Slots The optional slot mapping that will be initialized during
5456
/// parsing.
57+
/// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
58+
/// This option should only be set to false by llvm-as
59+
/// for use inside the LLVM testuite!
5560
std::unique_ptr<Module> parseAssemblyString(StringRef AsmString,
5661
SMDiagnostic &Error,
5762
LLVMContext &Context,
58-
SlotMapping *Slots = nullptr);
63+
SlotMapping *Slots = nullptr,
64+
bool UpgradeDebugInfo = true);
5965

6066
/// parseAssemblyFile and parseAssemblyString are wrappers around this function.
6167
/// \brief Parse LLVM Assembly from a MemoryBuffer.
6268
/// \param F The MemoryBuffer containing assembly
6369
/// \param Err Error result info.
6470
/// \param Slots The optional slot mapping that will be initialized during
6571
/// parsing.
72+
/// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
73+
/// This option should only be set to false by llvm-as
74+
/// for use inside the LLVM testuite!
6675
std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
6776
LLVMContext &Context,
68-
SlotMapping *Slots = nullptr);
77+
SlotMapping *Slots = nullptr,
78+
bool UpgradeDebugInfo = true);
6979

7080
/// This function is the low-level interface to the LLVM Assembly Parser.
7181
/// This is kept as an independent function instead of being inlined into
@@ -78,8 +88,12 @@ std::unique_ptr<Module> parseAssembly(MemoryBufferRef F, SMDiagnostic &Err,
7888
/// \param Slots The optional slot mapping that will be initialized during
7989
/// parsing.
8090
/// \return true on error.
91+
/// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
92+
/// This option should only be set to false by llvm-as
93+
/// for use inside the LLVM testuite!
8194
bool parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
82-
SlotMapping *Slots = nullptr);
95+
SlotMapping *Slots = nullptr,
96+
bool UpgradeDebugInfo = true);
8397

8498
/// Parse a type and a constant value in the given string.
8599
///

include/llvm/DebugInfo/DIContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct DIDumpOptions {
141141
unsigned RecurseDepth = -1U;
142142
bool ShowChildren = false;
143143
bool ShowParents = false;
144+
bool ShowForm = false;
144145
bool SummarizeTypes = false;
145146
bool Verbose = false;
146147

include/llvm/IRReader/IRReader.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,22 @@ getLazyIRFileModule(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context,
3737
/// If the given MemoryBuffer holds a bitcode image, return a Module
3838
/// for it. Otherwise, attempt to parse it as LLVM Assembly and return
3939
/// a Module for it.
40+
/// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
41+
/// This option should only be set to false by llvm-as
42+
/// for use inside the LLVM testuite!
4043
std::unique_ptr<Module> parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
41-
LLVMContext &Context);
44+
LLVMContext &Context,
45+
bool UpgradeDebugInfo = true);
4246

4347
/// If the given file holds a bitcode image, return a Module for it.
4448
/// Otherwise, attempt to parse it as LLVM Assembly and return a Module
4549
/// for it.
50+
/// \param UpgradeDebugInfo Run UpgradeDebugInfo, which runs the Verifier.
51+
/// This option should only be set to false by llvm-as
52+
/// for use inside the LLVM testuite!
4653
std::unique_ptr<Module> parseIRFile(StringRef Filename, SMDiagnostic &Err,
47-
LLVMContext &Context);
54+
LLVMContext &Context,
55+
bool UpgradeDebugInfo = true);
4856
}
4957

5058
#endif

lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ bool LLParser::ValidateEndOfModule() {
237237
}
238238
}
239239

240-
UpgradeDebugInfo(*M);
240+
if (UpgradeDebugInfo)
241+
llvm::UpgradeDebugInfo(*M);
241242

242243
UpgradeModuleFlags(*M);
243244

lib/AsmParser/LLParser.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,16 @@ namespace llvm {
139139
std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
140140
std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
141141

142+
/// Only the llvm-as tool may set this to false to bypass
143+
/// UpgradeDebuginfo so it can generate broken bitcode.
144+
bool UpgradeDebugInfo;
145+
142146
public:
143147
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M,
144-
SlotMapping *Slots = nullptr)
148+
SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true)
145149
: Context(M->getContext()), Lex(F, SM, Err, M->getContext()), M(M),
146-
Slots(Slots), BlockAddressPFS(nullptr) {}
150+
Slots(Slots), BlockAddressPFS(nullptr),
151+
UpgradeDebugInfo(UpgradeDebugInfo) {}
147152
bool Run();
148153

149154
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);

lib/AsmParser/Parser.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,21 @@
2323
using namespace llvm;
2424

2525
bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
26-
SlotMapping *Slots) {
26+
SlotMapping *Slots, bool UpgradeDebugInfo) {
2727
SourceMgr SM;
2828
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
2929
SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
3030

31-
return LLParser(F.getBuffer(), SM, Err, &M, Slots).Run();
31+
return LLParser(F.getBuffer(), SM, Err, &M, Slots, UpgradeDebugInfo).Run();
3232
}
3333

34-
std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
35-
SMDiagnostic &Err,
36-
LLVMContext &Context,
37-
SlotMapping *Slots) {
34+
std::unique_ptr<Module>
35+
llvm::parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context,
36+
SlotMapping *Slots, bool UpgradeDebugInfo) {
3837
std::unique_ptr<Module> M =
3938
make_unique<Module>(F.getBufferIdentifier(), Context);
4039

41-
if (parseAssemblyInto(F, *M, Err, Slots))
40+
if (parseAssemblyInto(F, *M, Err, Slots, UpgradeDebugInfo))
4241
return nullptr;
4342

4443
return M;
@@ -47,7 +46,8 @@ std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
4746
std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
4847
SMDiagnostic &Err,
4948
LLVMContext &Context,
50-
SlotMapping *Slots) {
49+
SlotMapping *Slots,
50+
bool UpgradeDebugInfo) {
5151
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
5252
MemoryBuffer::getFileOrSTDIN(Filename);
5353
if (std::error_code EC = FileOrErr.getError()) {
@@ -56,15 +56,17 @@ std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
5656
return nullptr;
5757
}
5858

59-
return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots);
59+
return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots,
60+
UpgradeDebugInfo);
6061
}
6162

6263
std::unique_ptr<Module> llvm::parseAssemblyString(StringRef AsmString,
6364
SMDiagnostic &Err,
6465
LLVMContext &Context,
65-
SlotMapping *Slots) {
66+
SlotMapping *Slots,
67+
bool UpgradeDebugInfo) {
6668
MemoryBufferRef F(AsmString, "<string>");
67-
return parseAssembly(F, Err, Context, Slots);
69+
return parseAssembly(F, Err, Context, Slots, UpgradeDebugInfo);
6870
}
6971

7072
Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err,

lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
139139
else
140140
WithColor(OS, syntax::Attribute).get() << format("DW_AT_Unknown_%x", Attr);
141141

142-
if (DumpOpts.Verbose) {
142+
if (DumpOpts.Verbose || DumpOpts.ShowForm) {
143143
auto formString = FormEncodingString(Form);
144144
if (!formString.empty())
145145
OS << " [" << formString << ']';

lib/IR/AutoUpgrade.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/IR/IntrinsicInst.h"
2828
#include "llvm/IR/LLVMContext.h"
2929
#include "llvm/IR/Module.h"
30+
#include "llvm/IR/Verifier.h"
3031
#include "llvm/Support/ErrorHandling.h"
3132
#include "llvm/Support/Regex.h"
3233
#include <cstring>
@@ -2249,15 +2250,26 @@ Value *llvm::UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy) {
22492250
/// info. Return true if module is modified.
22502251
bool llvm::UpgradeDebugInfo(Module &M) {
22512252
unsigned Version = getDebugMetadataVersionFromModule(M);
2252-
if (Version == DEBUG_METADATA_VERSION)
2253-
return false;
2254-
2255-
bool RetCode = StripDebugInfo(M);
2256-
if (RetCode) {
2253+
if (Version == DEBUG_METADATA_VERSION) {
2254+
bool BrokenDebugInfo = false;
2255+
if (verifyModule(M, &llvm::errs(), &BrokenDebugInfo))
2256+
report_fatal_error("Broken module found, compilation aborted!");
2257+
if (!BrokenDebugInfo)
2258+
// Everything is ok.
2259+
return false;
2260+
else {
2261+
// Diagnose malformed debug info.
2262+
DiagnosticInfoIgnoringInvalidDebugMetadata Diag(M);
2263+
M.getContext().diagnose(Diag);
2264+
}
2265+
}
2266+
bool Modified = StripDebugInfo(M);
2267+
if (Modified && Version != DEBUG_METADATA_VERSION) {
2268+
// Diagnose a version mismatch.
22572269
DiagnosticInfoDebugMetadataVersion DiagVersion(M, Version);
22582270
M.getContext().diagnose(DiagVersion);
22592271
}
2260-
return RetCode;
2272+
return Modified;
22612273
}
22622274

22632275
bool llvm::UpgradeModuleFlags(Module &M) {

lib/IR/DebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static MDNode *stripDebugLocFromLoopID(MDNode *N) {
290290

291291
bool llvm::stripDebugInfo(Function &F) {
292292
bool Changed = false;
293-
if (F.getSubprogram()) {
293+
if (F.getMetadata(LLVMContext::MD_dbg)) {
294294
Changed = true;
295295
F.setSubprogram(nullptr);
296296
}

lib/IR/Metadata.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,6 @@ void GlobalObject::setMetadata(StringRef Kind, MDNode *N) {
14311431
MDNode *GlobalObject::getMetadata(unsigned KindID) const {
14321432
SmallVector<MDNode *, 1> MDs;
14331433
getMetadata(KindID, MDs);
1434-
assert(MDs.size() <= 1 && "Expected at most one metadata attachment");
14351434
if (MDs.empty())
14361435
return nullptr;
14371436
return MDs[0];

lib/IR/Verifier.cpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,6 @@ void Verifier::visitDITemplateValueParameter(
11461146
void Verifier::visitDIVariable(const DIVariable &N) {
11471147
if (auto *S = N.getRawScope())
11481148
AssertDI(isa<DIScope>(S), "invalid scope", &N, S);
1149-
AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
11501149
if (auto *F = N.getRawFile())
11511150
AssertDI(isa<DIFile>(F), "invalid file", &N, F);
11521151
}
@@ -1169,6 +1168,7 @@ void Verifier::visitDILocalVariable(const DILocalVariable &N) {
11691168
// Checks common to all variables.
11701169
visitDIVariable(N);
11711170

1171+
AssertDI(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
11721172
AssertDI(N.getTag() == dwarf::DW_TAG_variable, "invalid tag", &N);
11731173
AssertDI(N.getRawScope() && isa<DILocalScope>(N.getRawScope()),
11741174
"local variable requires a valid scope", &N, N.getRawScope());
@@ -1181,6 +1181,8 @@ void Verifier::visitDIExpression(const DIExpression &N) {
11811181
void Verifier::visitDIGlobalVariableExpression(
11821182
const DIGlobalVariableExpression &GVE) {
11831183
AssertDI(GVE.getVariable(), "missing variable");
1184+
if (auto *Var = GVE.getVariable())
1185+
visitDIGlobalVariable(*Var);
11841186
if (auto *Expr = GVE.getExpression()) {
11851187
visitDIExpression(*Expr);
11861188
if (auto Fragment = Expr->getFragmentInfo())
@@ -4676,19 +4678,8 @@ struct VerifierLegacyPass : public FunctionPass {
46764678
HasErrors |= !V->verify(F);
46774679

46784680
HasErrors |= !V->verify();
4679-
if (FatalErrors) {
4680-
if (HasErrors)
4681-
report_fatal_error("Broken module found, compilation aborted!");
4682-
assert(!V->hasBrokenDebugInfo() && "Module contains invalid debug info");
4683-
}
4684-
4685-
// Strip broken debug info.
4686-
if (V->hasBrokenDebugInfo()) {
4687-
DiagnosticInfoIgnoringInvalidDebugMetadata DiagInvalid(M);
4688-
M.getContext().diagnose(DiagInvalid);
4689-
if (!StripDebugInfo(M))
4690-
report_fatal_error("Failed to strip malformed debug info");
4691-
}
4681+
if (FatalErrors && (HasErrors || V->hasBrokenDebugInfo()))
4682+
report_fatal_error("Broken module found, compilation aborted!");
46924683
return false;
46934684
}
46944685

@@ -4991,19 +4982,9 @@ VerifierAnalysis::Result VerifierAnalysis::run(Function &F,
49914982

49924983
PreservedAnalyses VerifierPass::run(Module &M, ModuleAnalysisManager &AM) {
49934984
auto Res = AM.getResult<VerifierAnalysis>(M);
4994-
if (FatalErrors) {
4995-
if (Res.IRBroken)
4996-
report_fatal_error("Broken module found, compilation aborted!");
4997-
assert(!Res.DebugInfoBroken && "Module contains invalid debug info");
4998-
}
4985+
if (FatalErrors && (Res.IRBroken || Res.DebugInfoBroken))
4986+
report_fatal_error("Broken module found, compilation aborted!");
49994987

5000-
// Strip broken debug info.
5001-
if (Res.DebugInfoBroken) {
5002-
DiagnosticInfoIgnoringInvalidDebugMetadata DiagInvalid(M);
5003-
M.getContext().diagnose(DiagInvalid);
5004-
if (!StripDebugInfo(M))
5005-
report_fatal_error("Failed to strip malformed debug info");
5006-
}
50074988
return PreservedAnalyses::all();
50084989
}
50094990

lib/IRReader/IRReader.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ std::unique_ptr<Module> llvm::getLazyIRFileModule(StringRef Filename,
6868
}
6969

7070
std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
71-
LLVMContext &Context) {
71+
LLVMContext &Context,
72+
bool UpgradeDebugInfo) {
7273
NamedRegionTimer T(TimeIRParsingName, TimeIRParsingDescription,
7374
TimeIRParsingGroupName, TimeIRParsingGroupDescription,
7475
TimePassesIsEnabled);
@@ -86,11 +87,12 @@ std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err,
8687
return std::move(ModuleOrErr.get());
8788
}
8889

89-
return parseAssembly(Buffer, Err, Context);
90+
return parseAssembly(Buffer, Err, Context, nullptr, UpgradeDebugInfo);
9091
}
9192

9293
std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err,
93-
LLVMContext &Context) {
94+
LLVMContext &Context,
95+
bool UpgradeDebugInfo) {
9496
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
9597
MemoryBuffer::getFileOrSTDIN(Filename);
9698
if (std::error_code EC = FileOrErr.getError()) {
@@ -99,7 +101,8 @@ std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err,
99101
return nullptr;
100102
}
101103

102-
return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context);
104+
return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context,
105+
UpgradeDebugInfo);
103106
}
104107

105108
//===----------------------------------------------------------------------===//

lib/LTO/LTOCodeGenerator.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ cl::opt<bool> LTODiscardValueNames(
8383
#endif
8484
cl::Hidden);
8585

86-
cl::opt<bool> LTOStripInvalidDebugInfo(
87-
"lto-strip-invalid-debug-info",
88-
cl::desc("Strip invalid debug info metadata during LTO instead of aborting."),
89-
#ifdef NDEBUG
90-
cl::init(true),
91-
#else
92-
cl::init(false),
93-
#endif
94-
cl::Hidden);
95-
9686
cl::opt<std::string>
9787
LTORemarksFilename("lto-pass-remarks-output",
9888
cl::desc("Output filename for pass remarks"),
@@ -496,8 +486,7 @@ void LTOCodeGenerator::verifyMergedModuleOnce() {
496486
HasVerifiedInput = true;
497487

498488
bool BrokenDebugInfo = false;
499-
if (verifyModule(*MergedModule, &dbgs(),
500-
LTOStripInvalidDebugInfo ? &BrokenDebugInfo : nullptr))
489+
if (verifyModule(*MergedModule, &dbgs(), &BrokenDebugInfo))
501490
report_fatal_error("Broken module found, compilation aborted!");
502491
if (BrokenDebugInfo) {
503492
emitWarning("Invalid debug info found, debug info will be stripped");

lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ namespace llvm {
6363
extern cl::opt<bool> LTODiscardValueNames;
6464
extern cl::opt<std::string> LTORemarksFilename;
6565
extern cl::opt<bool> LTOPassRemarksWithHotness;
66-
extern cl::opt<bool> LTOStripInvalidDebugInfo;
6766
}
6867

6968
namespace {
@@ -158,8 +157,7 @@ class ThinLTODiagnosticInfo : public DiagnosticInfo {
158157
/// Verify the module and strip broken debug info.
159158
static void verifyLoadedModule(Module &TheModule) {
160159
bool BrokenDebugInfo = false;
161-
if (verifyModule(TheModule, &dbgs(),
162-
LTOStripInvalidDebugInfo ? &BrokenDebugInfo : nullptr))
160+
if (verifyModule(TheModule, &dbgs(), &BrokenDebugInfo))
163161
report_fatal_error("Broken module found, compilation aborted!");
164162
if (BrokenDebugInfo) {
165163
TheModule.getContext().diagnose(ThinLTODiagnosticInfo(

0 commit comments

Comments
 (0)