Skip to content

Fix the IR attributes of swift_getObjectType. #13390

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
Dec 13, 2017
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
6 changes: 1 addition & 5 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -1049,14 +1049,10 @@ FUNCTION(LookUpClass, objc_lookUpClass, C_CC,
ATTRS(NoUnwind, ReadNone))

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

// Metadata *swift_getDynamicType(opaque_t *obj, Metadata *self);
FUNCTION(GetDynamicType, swift_getDynamicType, DefaultCC,
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4230,7 +4230,7 @@ llvm::Value *irgen::emitDynamicTypeOfOpaqueHeapObject(IRGenFunction &IGF,
object,
object->getName() + ".Type");
metadata->setDoesNotThrow();
metadata->setDoesNotAccessMemory();
metadata->setOnlyReadsMemory();
return metadata;
}

Expand Down
39 changes: 39 additions & 0 deletions test/IRGen/object_type.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O %s -o %t/a.out
// RUN: %target-build-swift -O %s -emit-ir | %FileCheck --check-prefix=CHECK-IR %s
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test

// Check if the runtime function swift_getObjectType is not readnone and
// therefore not re-scheduled with release-calls, which would lead to a crash
// in this example.

public protocol Proto: class {
static func printit()
}

public final class ConformingClass : Proto {
public static func printit() { print("okay") }
}

public final class Creator {
@inline(never)
public init() {}

@inline(never)
public func createIt() -> Proto {
return ConformingClass ()
}
}

func work() {
let myProtocolType: Proto.Type = type(of: Creator().createIt())
myProtocolType.printit()
}

// CHECK-IR: call {{.*}} @swift_getObjectType({{.*}}) #[[M:[0-9]]]
// CHECK-IR: declare {{.*}} @swift_getObjectType{{.*}} #[[M]]
// CHECK-IR: attributes #[[M]] = { nounwind readonly }

// CHECK: okay
work()