Skip to content

[IRGen] Record the Swift major/minor version in the top two bytes of the objc_image_info flags field. #20569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,19 +1089,23 @@ void IRGenModule::cleanupClangCodeGenMetadata() {
// arbitrary keys to put in the image info.

const char *ObjectiveCGarbageCollection = "Objective-C Garbage Collection";
uint8_t Major, Minor;
std::tie(Major, Minor) = version::getSwiftNumericVersion();
uint32_t Value = (Major << 24) | (Minor << 16) | (swiftVersion << 8);

if (Module.getModuleFlag(ObjectiveCGarbageCollection)) {
bool FoundOldEntry = replaceModuleFlagsEntry(
Module.getContext(), Module, ObjectiveCGarbageCollection,
llvm::Module::Override,
llvm::ConstantAsMetadata::get(
llvm::ConstantInt::get(Int32Ty, (uint32_t)(swiftVersion << 8))));
llvm::ConstantInt::get(Int32Ty, Value)));

(void)FoundOldEntry;
assert(FoundOldEntry && "Could not replace old module flag entry?");
} else
Module.addModuleFlag(llvm::Module::Override,
ObjectiveCGarbageCollection,
(uint32_t)(swiftVersion << 8));
Value);
}

bool IRGenModule::finalize() {
Expand Down
5 changes: 3 additions & 2 deletions test/IRGen/objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class WeakObjC {
// CHECK: i32 1, !"Objective-C Version", i32 2}
// CHECK: i32 1, !"Objective-C Image Info Version", i32 0}
// CHECK: i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
// 1536 == (6 << 8). 6 is the Swift ABI version.
// CHECK: i32 4, !"Objective-C Garbage Collection", i32 1536}
// 67241472 == (4 << 24) | (2 << 16) | (6 << 8).
// 4 and 2 is the current major.minor version. 6 is the Swift ABI version.
// CHECK: i32 4, !"Objective-C Garbage Collection", i32 67241472}
// CHECK: i32 1, !"Swift Version", i32 6}