Skip to content

Commit ccd534d

Browse files
author
Harlan Haskins
authored
[TBD] Ensure swift-abi-version is kept in sync with IRGen (#27347)
The TAPI_SWIFT_ABI_VERSION macro was never updated in sync with IRGen::swiftVersion, so just expose that value through irgen::getSwiftABIVersion() and use it in TBDGen. Fixes rdar://55643763
1 parent 80e6466 commit ccd534d

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

include/swift/IRGen/IRGenPublic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
3636
/// Delete the IRGenModule and IRGenerator obtained by the above call.
3737
void deleteIRGenModule(std::pair<IRGenerator *, IRGenModule *> &Module);
3838

39+
/// Gets the ABI version number that'll be set as a flag in the module.
40+
uint32_t getSwiftABIVersion();
41+
3942
} // end namespace irgen
4043
} // end namespace swift
4144

include/swift/TBDGen/TBDGen.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ namespace swift {
2424
class FileUnit;
2525
class ModuleDecl;
2626

27-
/// The current ABI version of Swift, as tapi labels it.
28-
const uint8_t TAPI_SWIFT_ABI_VERSION = 5;
29-
3027
/// Options for controlling the exact set of symbols included in the TBD
3128
/// output.
3229
struct TBDGenOptions {

lib/IRGen/IRGenModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Basic/Dwarf.h"
2323
#include "swift/Demangling/ManglingMacros.h"
2424
#include "swift/ClangImporter/ClangImporter.h"
25+
#include "swift/IRGen/IRGenPublic.h"
2526
#include "swift/IRGen/Linking.h"
2627
#include "swift/Runtime/RuntimeFnWrappersGen.h"
2728
#include "swift/Runtime/Config.h"
@@ -1355,6 +1356,10 @@ IRGenModule *IRGenerator::getGenModule(SILFunction *f) {
13551356
return getPrimaryIGM();
13561357
}
13571358

1359+
uint32_t swift::irgen::getSwiftABIVersion() {
1360+
return IRGenModule::swiftVersion;
1361+
}
1362+
13581363
llvm::Triple IRGenerator::getEffectiveClangTriple() {
13591364
auto CI = static_cast<ClangImporter *>(
13601365
&*SIL.getASTContext().getClangModuleLoader());

lib/TBDGen/TBDGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/Module.h"
2323
#include "swift/AST/ParameterList.h"
2424
#include "swift/Basic/LLVM.h"
25+
#include "swift/IRGen/IRGenPublic.h"
2526
#include "swift/IRGen/Linking.h"
2627
#include "swift/SIL/FormalLinkage.h"
2728
#include "swift/SIL/SILDeclRef.h"
@@ -609,7 +610,7 @@ static void enumeratePublicSymbolsAndWrite(ModuleDecl *M, FileUnit *singleFile,
609610
file.setCurrentVersion(convertToPacked(opts.CurrentVersion));
610611
file.setCompatibilityVersion(convertToPacked(opts.CompatibilityVersion));
611612
file.setTwoLevelNamespace();
612-
file.setSwiftABIVersion(TAPI_SWIFT_ABI_VERSION);
613+
file.setSwiftABIVersion(irgen::getSwiftABIVersion());
613614
file.setPlatform(tapi::internal::mapToSinglePlatform(target));
614615
auto arch = tapi::internal::getArchType(target.getArchName());
615616
file.setArch(arch);

test/TBD/abi-version.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// This test ensures that we see the same Swift ABI Version flag in the LLVM IR
4+
// and in the TBD.
5+
6+
// 1. Emit IR and a TBD for this file
7+
8+
// RUN: %target-swift-frontend -emit-ir -o %t/test.ll %s -emit-tbd-path %t/test.tbd
9+
10+
// 2. Concatenate them and FileCheck them both in the same file, so we can capture
11+
// the ABI version in a variable.
12+
13+
// RUN: cat %t/test.ll %t/test.tbd | %FileCheck %s
14+
15+
// 3. Look in the IR for the Swift Version flag
16+
17+
// CHECK: !"Swift Version", i32 [[VERSION:[0-9]+]]
18+
19+
// 4. Look in the TBD for the same version listed
20+
21+
// CHECK: swift-abi-version: [[VERSION]]

0 commit comments

Comments
 (0)