Skip to content

Commit f043a48

Browse files
authored
Merge pull request #34400 from apple/thinlto-fixes
Add an end-to-end test for ThinLTO (-lto=llvm-thin flag), fix compiler crashes
2 parents 660929d + 4271edd commit f043a48

21 files changed

+87
-51
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5166,7 +5166,9 @@ llvm::Constant *IRGenModule::getAddrOfGlobalString(StringRef data,
51665166
return entry.second;
51675167
}
51685168

5169-
entry = createStringConstant(data, willBeRelativelyAddressed);
5169+
entry = createStringConstant(data, willBeRelativelyAddressed,
5170+
/*sectionName*/ "",
5171+
".str" /* match how Clang creates strings */);
51705172
return entry.second;
51715173
}
51725174

@@ -5195,9 +5197,9 @@ llvm::Constant *IRGenModule::getAddrOfGlobalUTF16String(StringRef utf8) {
51955197
ArrayRef<llvm::UTF16> utf16(&buffer[0], utf16Length + 1);
51965198

51975199
auto init = llvm::ConstantDataArray::get(getLLVMContext(), utf16);
5198-
auto global = new llvm::GlobalVariable(Module, init->getType(), true,
5199-
llvm::GlobalValue::PrivateLinkage,
5200-
init);
5200+
auto global = new llvm::GlobalVariable(
5201+
Module, init->getType(), true, llvm::GlobalValue::PrivateLinkage, init,
5202+
".str" /* match how Clang creates strings */);
52015203
global->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
52025204

52035205
// Drill down to make an i16*.

lib/IRGen/IRGenModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,13 +995,13 @@ void IRGenModule::registerRuntimeEffect(ArrayRef<RuntimeEffect> effect,
995995
#include "swift/Runtime/RuntimeFunctions.def"
996996

997997
std::pair<llvm::GlobalVariable *, llvm::Constant *>
998-
IRGenModule::createStringConstant(StringRef Str,
999-
bool willBeRelativelyAddressed, StringRef sectionName) {
998+
IRGenModule::createStringConstant(StringRef Str, bool willBeRelativelyAddressed,
999+
StringRef sectionName, StringRef name) {
10001000
// If not, create it. This implicitly adds a trailing null.
10011001
auto init = llvm::ConstantDataArray::getString(getLLVMContext(), Str);
10021002
auto global = new llvm::GlobalVariable(Module, init->getType(), true,
10031003
llvm::GlobalValue::PrivateLinkage,
1004-
init);
1004+
init, name);
10051005
// FIXME: ld64 crashes resolving relative references to coalesceable symbols.
10061006
// rdar://problem/22674524
10071007
// If we intend to relatively address this string, don't mark it with

lib/IRGen/IRGenModule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,9 @@ class IRGenModule {
10081008

10091009
//--- Globals ---------------------------------------------------------------
10101010
public:
1011-
std::pair<llvm::GlobalVariable *, llvm::Constant *>
1012-
createStringConstant(StringRef Str, bool willBeRelativelyAddressed = false,
1013-
StringRef sectionName = "");
1011+
std::pair<llvm::GlobalVariable *, llvm::Constant *> createStringConstant(
1012+
StringRef Str, bool willBeRelativelyAddressed = false,
1013+
StringRef sectionName = "", StringRef name = "");
10141014
llvm::Constant *getAddrOfGlobalString(StringRef utf8,
10151015
bool willBeRelativelyAddressed = false);
10161016
llvm::Constant *getAddrOfGlobalUTF16String(StringRef utf8);

test/IRGen/UseObjCMethod.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ testDemo()
2323

2424
// Make sure the clang importer puts the selectors and co into the llvm.compiler used variable.
2525

26-
// CHECK: @llvm.compiler.used = appending global [{{.*}} x i8*] [{{.*}} @"OBJC_CLASSLIST_REFERENCES_$_"{{.*}}@OBJC_METH_VAR_NAME_{{.*}}@OBJC_SELECTOR_REFERENCES_{{.*}}@OBJC_METH_VAR_NAME_.1{{.*}}@OBJC_SELECTOR_REFERENCES_.2{{.*}}]
26+
// CHECK: @llvm.compiler.used = appending global [{{.*}} x i8*] [{{.*}} @"OBJC_CLASSLIST_REFERENCES_$_"{{.*}}@OBJC_METH_VAR_NAME_{{.*}}@OBJC_SELECTOR_REFERENCES_{{.*}}@OBJC_METH_VAR_NAME_.1{{.*}}@OBJC_SELECTOR_REFERENCES_.{{.*}}]
2727

test/IRGen/anonymous_context_descriptors.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Blah<T: P> {
1212

1313
// Mangled name of the anonymous descriptor
1414
// CHECK-NOT: private constant [84 x i8] c"$s29anonymous_context_descriptors4BlahC5Inner33_4F495173994818481DD703D65EB08308LLV\00"
15-
// CHECK-MANGLED: [[INNER_MANGLED:@[0-9]+]] = private constant [84 x i8] c"$s29anonymous_context_descriptors4BlahC5Inner33_4F495173994818481DD703D65EB08308LLV\00"
15+
// CHECK-MANGLED: [[INNER_MANGLED:@.str.[0-9]+]] = private constant [84 x i8] c"$s29anonymous_context_descriptors4BlahC5Inner33_4F495173994818481DD703D65EB08308LLV\00"
1616

1717
// Anonymous descriptor
1818
// CHECK: @"$s29anonymous_context_descriptors4BlahC5Inner33{{.*}}MXX" =

test/IRGen/builtins_objc.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import Swift
77
import Foundation
88
import CoreGraphics
99

10-
// CHECK: [[INT32:@[0-9]+]] = {{.*}} c"i\00"
11-
// CHECK: [[OBJECT:@[0-9]+]] = {{.*}} c"@\00"
10+
// CHECK: [[INT32:@.str.[0-9]+]] = {{.*}} c"i\00"
11+
// CHECK: [[OBJECT:@.str.[0-9]+]] = {{.*}} c"@\00"
1212

1313
@objc enum ObjCEnum: Int32 { case X }
1414
@objc class ObjCClass: NSObject {}
@@ -22,9 +22,9 @@ func getObjCTypeEncoding<T>(_: T) {
2222
use(Builtin.getObjCTypeEncoding(Int32.self))
2323
// CHECK: call swiftcc void @use({{.* i8]\*}} [[INT32]]
2424
use(Builtin.getObjCTypeEncoding(ObjCEnum.self))
25-
// CHECK: call swiftcc void @use({{.* i8]\*}} [[CGRECT:@[0-9]+]],
25+
// CHECK: call swiftcc void @use({{.* i8]\*}} [[CGRECT:@.str.[0-9]+]],
2626
use(Builtin.getObjCTypeEncoding(CGRect.self))
27-
// CHECK: call swiftcc void @use({{.* i8]\*}} [[NSRANGE:@[0-9]+]],
27+
// CHECK: call swiftcc void @use({{.* i8]\*}} [[NSRANGE:@.str.[0-9]+]],
2828
use(Builtin.getObjCTypeEncoding(NSRange.self))
2929
// CHECK: call swiftcc void @use({{.* i8]\*}} [[OBJECT]]
3030
use(Builtin.getObjCTypeEncoding(AnyObject.self))

test/IRGen/class_update_callback_with_stub.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import resilient_objc_class
2323
// -- parent
2424
// CHECK-SAME: @"$s31class_update_callback_with_stubMXM"
2525
// -- name
26-
// CHECK-SAME: @1
26+
// CHECK-SAME: @.str.1
2727
// -- access function
2828
// CHECK-SAME: @"$s31class_update_callback_with_stub17ResilientSubclassCMa"
2929
// -- field descriptor

test/IRGen/closure.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
// REQUIRES: PTRSIZE=64
66

7-
// CHECK-DAG: [[FILENAME:@[0-9]+]] = {{.*}} c"{{.*}}closure.swift\00"
8-
// OPT: [[FILENAME:@[0-9]+]] = {{.*}} [1 x i8] zeroinitializer
7+
// CHECK-DAG: [[FILENAME:@.str]] = {{.*}} c"{{.*}}closure.swift\00"
8+
// OPT: [[FILENAME:@.str]] = {{.*}} [1 x i8] zeroinitializer
99

1010
// -- partial_apply context metadata
1111

test/IRGen/expressions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import Swift
88
// CHECK: private unnamed_addr constant [22 x i8] c"this is just a\0A\0A test\00"
99

1010
// CHECK: define hidden [[stringLayout:[^@]*]] @"$s11expressions17TestStringLiteralSSyF"() {{.*}} {
11-
// CHECK: call [[stringLayout]] @{{.*}}_builtinStringLiteral{{.*}}(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @0, i64 0, i64 0), i64 21, i1 true)
11+
// CHECK: call [[stringLayout]] @{{.*}}_builtinStringLiteral{{.*}}(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 21, i1 true)
1212

1313
func TestStringLiteral() -> String {
1414
return "this is just a\n\u{0a} test"
1515
}
1616

1717
// CHECK: define hidden [[stringLayout]] @"$s11expressions18TestStringLiteral2SSyF"() {{.*}} {
18-
// CHECK: call [[stringLayout]] @{{.*}}_builtinStringLiteral{{.*}}(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @1, i64 0, i64 0), i64 19, i1 false)
18+
// CHECK: call [[stringLayout]] @{{.*}}_builtinStringLiteral{{.*}}(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 19, i1 false)
1919
func TestStringLiteral2() -> String {
2020
return "non-ASCII string \u{00B5}"
2121
}

test/IRGen/objc_attr_NSManaged.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sil_vtable X {}
1919
// The getter/setter should not show up in the Objective-C metadata.
2020
// CHECK: @_INSTANCE_METHODS__TtC19objc_attr_NSManaged10SwiftGizmo = internal constant { i32, i32, [2 x { i8*, i8*, i8* }] } { i32 24, i32 2, {{.*}} @"\01L_selector_data(initWithBellsOn:)", {{.*}} @"\01L_selector_data(init)",
2121

22-
// CHECK: [[X:@[0-9]+]] = private unnamed_addr constant [2 x i8] c"x\00"
22+
// CHECK: [[X:@.str.[0-9]+]] = private unnamed_addr constant [2 x i8] c"x\00"
2323

2424
// The property 'x' should show up in the Objective-C metadata.
2525
// CHECK: @_PROPERTIES__TtC19objc_attr_NSManaged10SwiftGizmo = internal constant { {{.*}}i32, i32, [1 x { i8*, i8* }] } { i32 16, i32 1, [1 x { i8*, i8* }] [{ i8*, i8* } { i8* getelementptr inbounds ([2 x i8], [2 x i8]* [[X]], i64 0, i64 0),

0 commit comments

Comments
 (0)