Skip to content

Commit ba304c3

Browse files
committed
[IRGen] IRGen fixes for SE-0033.
Teach IRGen's type lowering to cope with swift_newtype'd types.
1 parent 180c30b commit ba304c3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/IRGen/GenStruct.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,12 @@ const TypeInfo *TypeConverter::convertStructType(TypeBase *key, CanType type,
805805
assert(std::distance(D->getStoredProperties().begin(),
806806
D->getStoredProperties().end()) == 1 &&
807807
"Struct representation of a Clang enum should wrap one value");
808-
808+
} else if (clangDecl->hasAttr<clang::SwiftNewtypeAttr>()) {
809+
// Fall back to Swift lowering for the underlying type's
810+
// representation as a struct member.
811+
assert(std::distance(D->getStoredProperties().begin(),
812+
D->getStoredProperties().end()) == 1 &&
813+
"Struct representation of a swift_newtype should wrap one value");
809814
} else {
810815
llvm_unreachable("Swift struct represents unexpected imported type");
811816
}

test/IRGen/newtype.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN// RUN: %target-swift-frontend -I %S/../IDE/Inputs/custom-modules %s -emit-ir | FileCheck %s
2+
import Newtype
3+
4+
// CHECK-LABEL: define %CSo8NSString* @_TF7newtype14getErrorDomainFT_VSC11ErrorDomain()
5+
public func getErrorDomain() -> ErrorDomain {
6+
// CHECK: load %CSo8NSString*, %CSo8NSString** getelementptr inbounds (%VSC11ErrorDomain, %VSC11ErrorDomain* @SNTErrOne
7+
return .one
8+
}
9+

0 commit comments

Comments
 (0)