Skip to content

Commit 1a2daa7

Browse files
committed
Force LLVM to preserve value names in the same situations where we emit them in the first place.
Fixes IRGen test failures that only arise in non-asserts builds that we've apparently been working around in less principled ways for the last few months.
1 parent 279726f commit 1a2daa7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ class IRGenOptions {
197197
Hash = (Hash << 1) | DisableLLVMARCOpts;
198198
return Hash;
199199
}
200+
201+
/// Should LLVM IR value names be emitted and preserved?
202+
bool shouldProvideValueNames() const {
203+
// If the command line contains an explicit request about whether to add
204+
// LLVM value names, honor it. Otherwise, add value names only if the
205+
// final result is textual LLVM assembly.
206+
if (HasValueNamesSetting) {
207+
return ValueNames;
208+
} else {
209+
return OutputKind == IRGenOutputKind::LLVMAssembly;
210+
}
211+
}
200212
};
201213

202214
} // end namespace swift

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
8585
auto &CGO = Importer->getClangCodeGenOpts();
8686
CGO.OptimizationLevel = Opts.Optimize ? 3 : 0;
8787
CGO.DisableFPElim = Opts.DisableFPElim;
88+
CGO.DiscardValueNames = !Opts.shouldProvideValueNames();
8889
switch (Opts.DebugInfoKind) {
8990
case IRGenDebugInfoKind::None:
9091
CGO.setDebugInfo(clang::codegenoptions::DebugInfoKind::NoDebugInfo);
@@ -140,14 +141,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
140141

141142
auto &opts = irgen.Opts;
142143

143-
// If the command line contains an explicit request about whether to add
144-
// LLVM value names, honor it. Otherwise, add value names only if the
145-
// final result is textual LLVM assembly.
146-
if (opts.HasValueNamesSetting) {
147-
EnableValueNames = opts.ValueNames;
148-
} else {
149-
EnableValueNames = (opts.OutputKind == IRGenOutputKind::LLVMAssembly);
150-
}
144+
EnableValueNames = opts.shouldProvideValueNames();
151145

152146
VoidTy = llvm::Type::getVoidTy(getLLVMContext());
153147
Int1Ty = llvm::Type::getInt1Ty(getLLVMContext());

0 commit comments

Comments
 (0)