Skip to content

Commit 13a7ca0

Browse files
committed
test: be more flexible about anonymous enumeration imports
This test ensures that we correctly translate the anonymous enumeration value. However, this is an odd case within the specification. C11 6.7.2.2p2: "The expression that defines the value of an enumeration constant shall be an integer constant expression that has a value representable as an `int`." C11 6.7.2.2p4: "Each enumerated type shall be compatible with `char`, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration." C11 6.7.2.2p3: "The identifiers in an enumerator list are declared as constants that have type `int` and may appear wherever such are permitted." Because the enumeration is anonymous, the value could never be written as spelled. This type is imported as an `int` on Windows as per the ABI and as an `unsigned long` on LP64 targets.
1 parent aec5756 commit 13a7ca0

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

test/ClangImporter/ctypes_parse.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ func testTribool() {
2828
_ = b.rawValue
2929
}
3030

31+
func verifyIsInt(_: inout Int) { }
32+
func verifyIsUInt(_: inout UInt) { }
33+
func verifyIsUInt64(_: inout UInt64) { }
34+
3135
func testAnonEnum() {
3236
var a = AnonConst1
3337
a = AnonConst2
34-
#if arch(i386) || arch(arm) || os(Windows)
35-
_ = a as CUnsignedLongLong
38+
#if os(Windows)
39+
verifyIsInt(&a)
40+
#elseif arch(i386) || arch(arm)
41+
verifyIsUInt64(&a)
3642
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
37-
_ = a as CUnsignedLong
38-
#else
39-
__portMe()
43+
verifyIsUInt(&a)
4044
#endif
4145
}
4246

test/Inputs/clang-importer-sdk/usr/include/ctypes.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@ enum Tribool {
77
True, False, Indeterminate
88
};
99

10-
// This is explicitly sized on Windows since we do not use the type to infer the
11-
// type that we are importing it as as this is known to be explicitly different
12-
// in that environment.
13-
enum
14-
#if defined(_WIN32)
15-
: unsigned long long
16-
#endif
17-
{
10+
enum {
1811
AnonConst1 = 0x700000000,
1912
AnonConst2
2013
};
21-
_Static_assert(sizeof(AnonConst1) == 8);
2214

2315
enum {
2416
AnonConstSmall1 = 16,

0 commit comments

Comments
 (0)