Skip to content

[stdlib] Remove workaround for an old clang bug (rdar://18950072). #4497

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
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
5 changes: 1 addition & 4 deletions stdlib/public/stubs/SwiftNativeNSXXXBase.mm.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ using namespace swift;
SWIFT_RUNTIME_STDLIB_INTERFACE
@interface _SwiftNativeNS${Class}Base : NS${Class}
{
// TODO: Workaround for rdar://problem/18950072
// SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS;
uint32_t __magic_refCount;
uint32_t __magic_weakRefCount;
SWIFT_HEAPOBJECT_NON_OBJC_MEMBERS;
}
@end

Expand Down
87 changes: 87 additions & 0 deletions test/1_stdlib/Inputs/SwiftNativeNSBase/SwiftNativeNSBase.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//===--- SwiftNativeNSBase.m - Test _SwiftNativeNS*Base classes -----------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

// This file is compiled and run by SwiftNativeNSBase.swift.

#include <Foundation/Foundation.h>
#include <objc/runtime.h>

static int Errors;

#define expectTrue(expr) \
do { \
if (!(expr)) { \
printf("%s:%d: not true: %s\n", __FILE__, __LINE__, #expr); \
Errors++; \
} \
} while (0)

#define expectFalse(expr) \
do { \
if (expr) { \
printf("%s:%d: not false: %s\n", __FILE__, __LINE__, #expr); \
Errors++; \
} \
} while (0)

#define fail(format, ...) \
do { \
printf("%s:%d: " format, __FILE__, __LINE__, ##__VA_ARGS__); \
Errors++; \
} while (0)


void TestSwiftNativeNSBase(void)
{
printf("TestSwiftNativeNSBase\n");

unsigned int classCount;
Class *classes = objc_copyClassList(&classCount);

NSMutableSet *expectedClasses =
[NSMutableSet setWithObjects:
@"_SwiftNativeNSArrayBase",
@"_SwiftNativeNSDictionaryBase",
@"_SwiftNativeNSSetBase",
@"_SwiftNativeNSStringBase",
@"_SwiftNativeNSEnumeratorBase",
@"_SwiftNativeNSDataBase",
@"_SwiftNativeNSCharacterSetBase",
@"_SwiftNativeNSIndexSetBase",
nil];

for (unsigned int i = 0; i < classCount; i++) {
Class cls = classes[i];
NSString *name = @(class_getName(cls));
if (! ([name hasPrefix:@"_SwiftNativeNS"] && [name hasSuffix:@"Base"])) {
continue;
}
if (! [expectedClasses containsObject:name]) {
fail("did not expect class %s\n", name.UTF8String);
continue;
}

// cls is some _SwiftNativeNS*Base class
[expectedClasses removeObject:name];
printf("checking class %s\n", name.UTF8String);

// Check for unwanted C++ cdtors (rdar://18950072)
expectFalse([cls instancesRespondToSelector:sel_registerName(".cxx_construct")]);
expectFalse([cls instancesRespondToSelector:sel_registerName(".cxx_destruct")]);
}

expectTrue(expectedClasses.count == 0);

printf("TestSwiftNativeNSBase: %d error%s\n",
Errors, Errors == 1 ? "" : "s");
exit(Errors ? 1 : 0);
}
28 changes: 28 additions & 0 deletions validation-test/stdlib/SwiftNativeNSBase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===--- SwiftNativeNSBase.swift - Test _SwiftNativeNS*Base classes -------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

// RUN: rm -rf %t && mkdir -p %t
//
// RUN: %target-clang %S/Inputs/SwiftNativeNSBase/SwiftNativeNSBase.m -c -o %t/SwiftNativeNSBase.o -g
// RUN: %target-build-swift %s -I %S/Inputs/SwiftNativeNSBase/ -Xlinker %t/SwiftNativeNSBase.o -o %t/SwiftNativeNSBase
// RUN: %target-run %t/SwiftNativeNSBase
// REQUIRES: executable_test

// REQUIRES: objc_interop

import Foundation

@_silgen_name("TestSwiftNativeNSBase")
func TestSwiftNativeNSBase()

TestSwiftNativeNSBase()
// does not return