Skip to content

Commit 82e08e0

Browse files
authored
Merge pull request #13390 from eeckstein/fix-attrs-4.1
Fix the IR attributes of swift_getObjectType.
2 parents 1cb2f33 + 70aeb71 commit 82e08e0

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,14 +1049,10 @@ FUNCTION(LookUpClass, objc_lookUpClass, C_CC,
10491049
ATTRS(NoUnwind, ReadNone))
10501050

10511051
// Metadata *swift_getObjectType(id object);
1052-
//
1053-
// Since this is intended to look through dynamic subclasses, it's
1054-
// invariant across reasonable isa-rewriting schemes and therefore can
1055-
// be readnone.
10561052
FUNCTION(GetObjectType, swift_getObjectType, DefaultCC,
10571053
RETURNS(TypeMetadataPtrTy),
10581054
ARGS(ObjCPtrTy),
1059-
ATTRS(NoUnwind, ReadNone))
1055+
ATTRS(NoUnwind, ReadOnly))
10601056

10611057
// Metadata *swift_getDynamicType(opaque_t *obj, Metadata *self);
10621058
FUNCTION(GetDynamicType, swift_getDynamicType, DefaultCC,

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4230,7 +4230,7 @@ llvm::Value *irgen::emitDynamicTypeOfOpaqueHeapObject(IRGenFunction &IGF,
42304230
object,
42314231
object->getName() + ".Type");
42324232
metadata->setDoesNotThrow();
4233-
metadata->setDoesNotAccessMemory();
4233+
metadata->setOnlyReadsMemory();
42344234
return metadata;
42354235
}
42364236

test/IRGen/object_type.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -O %s -o %t/a.out
3+
// RUN: %target-build-swift -O %s -emit-ir | %FileCheck --check-prefix=CHECK-IR %s
4+
// RUN: %target-run %t/a.out | %FileCheck %s
5+
// REQUIRES: executable_test
6+
7+
// Check if the runtime function swift_getObjectType is not readnone and
8+
// therefore not re-scheduled with release-calls, which would lead to a crash
9+
// in this example.
10+
11+
public protocol Proto: class {
12+
static func printit()
13+
}
14+
15+
public final class ConformingClass : Proto {
16+
public static func printit() { print("okay") }
17+
}
18+
19+
public final class Creator {
20+
@inline(never)
21+
public init() {}
22+
23+
@inline(never)
24+
public func createIt() -> Proto {
25+
return ConformingClass ()
26+
}
27+
}
28+
29+
func work() {
30+
let myProtocolType: Proto.Type = type(of: Creator().createIt())
31+
myProtocolType.printit()
32+
}
33+
34+
// CHECK-IR: call {{.*}} @swift_getObjectType({{.*}}) #[[M:[0-9]]]
35+
// CHECK-IR: declare {{.*}} @swift_getObjectType{{.*}} #[[M]]
36+
// CHECK-IR: attributes #[[M]] = { nounwind readonly }
37+
38+
// CHECK: okay
39+
work()

0 commit comments

Comments
 (0)