Skip to content

Commit 2416881

Browse files
committed
Fix TBDGen datalayout
This patch fixes the call to get the datalayout from the clang module. Clang no longer holds onto the DataLayout object, so we have to do that if we want to keep it around. Rather than instanciating it early, we can just hold onto the string description, which clang does keep around, and only construct the actual DataLayout once we need it.
1 parent fa96aae commit 2416881

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

include/swift/AST/TBDGenRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TBDGenDescriptor final {
7070
const TBDGenOptions &getOptions() const { return Opts; }
7171
TBDGenOptions &getOptions() { return Opts; }
7272

73-
const llvm::DataLayout &getDataLayout() const;
73+
const StringRef getDataLayoutString() const;
7474
const llvm::Triple &getTarget() const;
7575

7676
bool operator==(const TBDGenDescriptor &other) const;

lib/TBDGen/TBDGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static bool isGlobalOrStaticVar(VarDecl *VD) {
6868

6969
TBDGenVisitor::TBDGenVisitor(const TBDGenDescriptor &desc,
7070
APIRecorder &recorder)
71-
: TBDGenVisitor(desc.getTarget(), desc.getDataLayout(),
71+
: TBDGenVisitor(desc.getTarget(), desc.getDataLayoutString(),
7272
desc.getParentModule(), desc.getOptions(), recorder) {}
7373

7474
void TBDGenVisitor::addSymbolInternal(StringRef name, SymbolKind kind,
@@ -390,7 +390,9 @@ void TBDGenVisitor::addSymbol(StringRef name, SymbolSource source,
390390
if (kind == SymbolKind::ObjectiveCClass) {
391391
mangled = name;
392392
} else {
393-
llvm::Mangler::getNameWithPrefix(mangled, name, DataLayout);
393+
if (!DataLayout)
394+
DataLayout = llvm::DataLayout(DataLayoutDescription);
395+
llvm::Mangler::getNameWithPrefix(mangled, name, *DataLayout);
394396
}
395397

396398
addSymbolInternal(mangled, kind, source);

lib/TBDGen/TBDGenRequests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ ModuleDecl *TBDGenDescriptor::getParentModule() const {
4848
return Input.get<FileUnit *>()->getParentModule();
4949
}
5050

51-
const llvm::DataLayout &TBDGenDescriptor::getDataLayout() const {
51+
const StringRef TBDGenDescriptor::getDataLayoutString() const {
5252
auto &ctx = getParentModule()->getASTContext();
5353
auto *clang = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
54-
return clang->getTargetInfo().getDataLayout();
54+
return llvm::StringRef(clang->getTargetInfo().getDataLayoutString());
5555
}
5656

5757
const llvm::Triple &TBDGenDescriptor::getTarget() const {

lib/TBDGen/TBDGenVisitor.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9292
llvm::StringSet<> DuplicateSymbolChecker;
9393
#endif
9494

95-
const llvm::DataLayout &DataLayout;
95+
Optional<llvm::DataLayout> DataLayout = None;
96+
const StringRef DataLayoutDescription;
97+
9698
UniversalLinkageInfo UniversalLinkInfo;
9799
ModuleDecl *SwiftModule;
98100
const TBDGenOptions &Opts;
@@ -167,10 +169,10 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
167169
const AutoDiffConfig &config);
168170

169171
public:
170-
TBDGenVisitor(const llvm::Triple &target, const llvm::DataLayout &dataLayout,
172+
TBDGenVisitor(const llvm::Triple &target, const StringRef dataLayoutString,
171173
ModuleDecl *swiftModule, const TBDGenOptions &opts,
172174
APIRecorder &recorder)
173-
: DataLayout(dataLayout),
175+
: DataLayoutDescription(dataLayoutString),
174176
UniversalLinkInfo(target, opts.HasMultipleIGMs, /*forcePublic*/ false),
175177
SwiftModule(swiftModule), Opts(opts), recorder(recorder),
176178
previousInstallNameMap(parsePreviousModuleInstallNameMap()) {}

0 commit comments

Comments
 (0)