Skip to content

Commit 26cc36b

Browse files
committed
[ClangImporter] Handle swift_wrapper annotated typedefs, skip CGFloats when importing const values
1 parent 8e6071e commit 26cc36b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4620,13 +4620,21 @@ namespace {
46204620
ImportDiagnosticAdder(Impl, decl, decl->getLocation()),
46214621
isInSystemModule(dc), Bridgeability::None, ImportTypeAttrs());
46224622

4623-
auto convertKind = ConstantConvertKind::None;
4624-
if (decl->getType()->isEnumeralType())
4625-
convertKind = ConstantConvertKind::Construction;
4626-
4627-
result = synthesizer.createConstant(
4628-
name, dc, type, *val, convertKind, isStatic, decl,
4629-
importer::convertClangAccess(decl->getAccess()));
4623+
// FIXME: Handle CGFloat too.
4624+
if (!type->isCGFloat()) {
4625+
auto convertKind = ConstantConvertKind::None;
4626+
// Request conversions on enums, and swift_wrapper((enum/struct))
4627+
// types
4628+
if (decl->getType()->isEnumeralType())
4629+
convertKind = ConstantConvertKind::Construction;
4630+
else if (findSwiftNewtype(decl, Impl.getClangSema(),
4631+
Impl.CurrentVersion))
4632+
convertKind = ConstantConvertKind::Construction;
4633+
4634+
result = synthesizer.createConstant(
4635+
name, dc, type, *val, convertKind, isStatic, decl,
4636+
importer::convertClangAccess(decl->getAccess()));
4637+
}
46304638
}
46314639
}
46324640

test/ClangImporter/const_values.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ struct MyStruct {
4040
__attribute__((swift_name("MyStruct.static_const_int_as_a_member")))
4141
static const int static_const_int_as_a_member = 42;
4242

43+
typedef int ImportAsStruct __attribute__((swift_wrapper(struct)));
44+
static const ImportAsStruct ImportAsStructFoo = 123;
45+
typedef int ImportAsEnum __attribute__((swift_wrapper(enum)));
46+
static const ImportAsEnum ImportAsEnumFoo = 123;
47+
4348
//--- main.swift
4449
func foo() {
4550
print(MACRO_INT)
@@ -64,6 +69,9 @@ func foo() {
6469
print(static_const_enum)
6570

6671
print(MyStruct.static_const_int_as_a_member)
72+
73+
print(ImportAsStruct.foo)
74+
print(ImportAsEnum.foo)
6775
}
6876

6977
// Globals that don't get their value imported stay as public_external:

0 commit comments

Comments
 (0)