Skip to content

Commit 0898e01

Browse files
authored
Merge pull request #20569 from mikeash/record-swift-major-minor-versions
[IRGen] Record the Swift major/minor version in the top two bytes of the objc_image_info flags field.
2 parents 9cc9a94 + 0262f1d commit 0898e01

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/IRGen/IRGenModule.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,19 +1089,23 @@ void IRGenModule::cleanupClangCodeGenMetadata() {
10891089
// arbitrary keys to put in the image info.
10901090

10911091
const char *ObjectiveCGarbageCollection = "Objective-C Garbage Collection";
1092+
uint8_t Major, Minor;
1093+
std::tie(Major, Minor) = version::getSwiftNumericVersion();
1094+
uint32_t Value = (Major << 24) | (Minor << 16) | (swiftVersion << 8);
1095+
10921096
if (Module.getModuleFlag(ObjectiveCGarbageCollection)) {
10931097
bool FoundOldEntry = replaceModuleFlagsEntry(
10941098
Module.getContext(), Module, ObjectiveCGarbageCollection,
10951099
llvm::Module::Override,
10961100
llvm::ConstantAsMetadata::get(
1097-
llvm::ConstantInt::get(Int32Ty, (uint32_t)(swiftVersion << 8))));
1101+
llvm::ConstantInt::get(Int32Ty, Value)));
10981102

10991103
(void)FoundOldEntry;
11001104
assert(FoundOldEntry && "Could not replace old module flag entry?");
11011105
} else
11021106
Module.addModuleFlag(llvm::Module::Override,
11031107
ObjectiveCGarbageCollection,
1104-
(uint32_t)(swiftVersion << 8));
1108+
Value);
11051109
}
11061110

11071111
bool IRGenModule::finalize() {

test/IRGen/objc.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class WeakObjC {
147147
// CHECK: i32 1, !"Objective-C Version", i32 2}
148148
// CHECK: i32 1, !"Objective-C Image Info Version", i32 0}
149149
// CHECK: i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
150-
// 1536 == (6 << 8). 6 is the Swift ABI version.
151-
// CHECK: i32 4, !"Objective-C Garbage Collection", i32 1536}
150+
// 67241472 == (4 << 24) | (2 << 16) | (6 << 8).
151+
// 4 and 2 is the current major.minor version. 6 is the Swift ABI version.
152+
// CHECK: i32 4, !"Objective-C Garbage Collection", i32 67241472}
152153
// CHECK: i32 1, !"Swift Version", i32 6}

0 commit comments

Comments
 (0)