Skip to content

Commit 5bbacc6

Browse files
authored
Merge pull request #4497 from gparker42/remove-rdar18950072-workaround
[stdlib] Remove workaround for an old clang bug (rdar://18950072).
2 parents 5a8950a + 1c58cc2 commit 5bbacc6

File tree

3 files changed

+116
-4
lines changed

3 files changed

+116
-4
lines changed

stdlib/public/stubs/SwiftNativeNSXXXBase.mm.gyb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ using namespace swift;
4848
SWIFT_RUNTIME_STDLIB_INTERFACE
4949
@interface _SwiftNativeNS${Class}Base : NS${Class}
5050
{
51-
// TODO: Workaround for rdar://problem/18950072
52-
// SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS;
53-
uint32_t __magic_refCount;
54-
uint32_t __magic_weakRefCount;
51+
SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS;
5552
}
5653
@end
5754

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//===--- SwiftNativeNSBase.m - Test _SwiftNativeNS*Base classes -----------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// This file is compiled and run by SwiftNativeNSBase.swift.
14+
15+
#include <Foundation/Foundation.h>
16+
#include <objc/runtime.h>
17+
18+
static int Errors;
19+
20+
#define expectTrue(expr) \
21+
do { \
22+
if (!(expr)) { \
23+
printf("%s:%d: not true: %s\n", __FILE__, __LINE__, #expr); \
24+
Errors++; \
25+
} \
26+
} while (0)
27+
28+
#define expectFalse(expr) \
29+
do { \
30+
if (expr) { \
31+
printf("%s:%d: not false: %s\n", __FILE__, __LINE__, #expr); \
32+
Errors++; \
33+
} \
34+
} while (0)
35+
36+
#define fail(format, ...) \
37+
do { \
38+
printf("%s:%d: " format, __FILE__, __LINE__, ##__VA_ARGS__); \
39+
Errors++; \
40+
} while (0)
41+
42+
43+
void TestSwiftNativeNSBase(void)
44+
{
45+
printf("TestSwiftNativeNSBase\n");
46+
47+
unsigned int classCount;
48+
Class *classes = objc_copyClassList(&classCount);
49+
50+
NSMutableSet *expectedClasses =
51+
[NSMutableSet setWithObjects:
52+
@"_SwiftNativeNSArrayBase",
53+
@"_SwiftNativeNSDictionaryBase",
54+
@"_SwiftNativeNSSetBase",
55+
@"_SwiftNativeNSStringBase",
56+
@"_SwiftNativeNSEnumeratorBase",
57+
@"_SwiftNativeNSDataBase",
58+
@"_SwiftNativeNSCharacterSetBase",
59+
@"_SwiftNativeNSIndexSetBase",
60+
nil];
61+
62+
for (unsigned int i = 0; i < classCount; i++) {
63+
Class cls = classes[i];
64+
NSString *name = @(class_getName(cls));
65+
if (! ([name hasPrefix:@"_SwiftNativeNS"] && [name hasSuffix:@"Base"])) {
66+
continue;
67+
}
68+
if (! [expectedClasses containsObject:name]) {
69+
fail("did not expect class %s\n", name.UTF8String);
70+
continue;
71+
}
72+
73+
// cls is some _SwiftNativeNS*Base class
74+
[expectedClasses removeObject:name];
75+
printf("checking class %s\n", name.UTF8String);
76+
77+
// Check for unwanted C++ cdtors (rdar://18950072)
78+
expectFalse([cls instancesRespondToSelector:sel_registerName(".cxx_construct")]);
79+
expectFalse([cls instancesRespondToSelector:sel_registerName(".cxx_destruct")]);
80+
}
81+
82+
expectTrue(expectedClasses.count == 0);
83+
84+
printf("TestSwiftNativeNSBase: %d error%s\n",
85+
Errors, Errors == 1 ? "" : "s");
86+
exit(Errors ? 1 : 0);
87+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===--- SwiftNativeNSBase.swift - Test _SwiftNativeNS*Base classes -------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// RUN: rm -rf %t && mkdir -p %t
14+
//
15+
// RUN: %target-clang %S/Inputs/SwiftNativeNSBase/SwiftNativeNSBase.m -c -o %t/SwiftNativeNSBase.o -g
16+
// RUN: %target-build-swift %s -I %S/Inputs/SwiftNativeNSBase/ -Xlinker %t/SwiftNativeNSBase.o -o %t/SwiftNativeNSBase
17+
// RUN: %target-run %t/SwiftNativeNSBase
18+
// REQUIRES: executable_test
19+
20+
// REQUIRES: objc_interop
21+
22+
import Foundation
23+
24+
@_silgen_name("TestSwiftNativeNSBase")
25+
func TestSwiftNativeNSBase()
26+
27+
TestSwiftNativeNSBase()
28+
// does not return

0 commit comments

Comments
 (0)