Skip to content

[ClangImporter] If enum_extensibility was removed, it's not an enum. #8992

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 1 commit into from
Apr 25, 2017
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
12 changes: 12 additions & 0 deletions lib/ClangImporter/ImportEnumInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ void EnumInfo::classifyEnum(ASTContext &ctx, const clang::EnumDecl *decl,
return;
}

// If API notes have /removed/ a FlagEnum or EnumExtensibility attribute,
// then we don't need to check the macros.
for (auto *attr : decl->specific_attrs<clang::SwiftVersionedAttr>()) {
if (!attr->getVersion().empty())
continue;
if (isa<clang::FlagEnumAttr>(attr->getAttrToAdd()) ||
isa<clang::EnumExtensibilityAttr>(attr->getAttrToAdd())) {
kind = EnumKind::Unknown;
return;
}
}

// Was the enum declared using *_ENUM or *_OPTIONS?
// FIXME: Stop using these once flag_enum and enum_extensibility
// have been adopted everywhere, or at least relegate them to Swift 3 mode
Expand Down
10 changes: 10 additions & 0 deletions test/ClangImporter/enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import Foundation
import user_objc
import enums_using_attributes

// NS_ENUM
var mince = NSRuncingMode.mince
Expand Down Expand Up @@ -149,6 +150,7 @@ var topLevelCaseName = RuncingMince // expected-error{{}}
#endif

let _: EnumViaAttribute = .first
let _: CFEnumWithAttr = .first

// NS_OPTIONS
var withMince: NSRuncingOptions = .enableMince
Expand Down Expand Up @@ -196,6 +198,7 @@ let objcFlags: objc_flags = [.taggedPointer, .swiftRefcount]

let optionsWithSwiftName: NSOptionsAlsoGetSwiftName = .Case
let optionsViaAttribute: OptionsViaAttribute = [.first, .second]
let optionsViaAttribute2: CFOptionsWithAttr = [.first]

// <rdar://problem/25168818> Don't import None members in NS_OPTIONS types
#if !IRGEN
Expand All @@ -211,3 +214,10 @@ _ = EmptySet3.None
// Just use this type, making sure that its case alias doesn't cause problems.
// rdar://problem/30401506
_ = EnumWithAwkwardDeprecations.normalCase1

#if !IRGEN
let _: UnknownEnumThanksToAPINotes = .first // expected-error {{has no member 'first'}}
let _: UnknownOptionsThanksToAPINotes = .first // expected-error {{has no member 'first'}}
#endif
let _ = UnknownEnumThanksToAPINotesFirst
let _ = UnknownOptionsThanksToAPINotesFirst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Name: enums_using_attributes
Tags:
- Name: UnknownEnumThanksToAPINotes
EnumKind: none
- Name: UnknownOptionsThanksToAPINotes
EnumKind: none
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#define CF_ENUM(_type, _name) enum _name : _type _name; \
enum __attribute__((enum_extensibility(open))) _name : _type
#define CF_OPTIONS(_type, _name) enum _name : _type _name; \
enum __attribute__((enum_extensibility(open), flag_enum)) _name : _type

typedef CF_ENUM(int, CFEnumWithAttr) {
CFEnumWithAttrFirst = 1,
};
typedef CF_ENUM(int, UnknownEnumThanksToAPINotes) {
UnknownEnumThanksToAPINotesFirst = 1,
};

typedef CF_OPTIONS(int, CFOptionsWithAttr) {
CFOptionsWithAttrFirst = 1,
};
typedef CF_OPTIONS(int, UnknownOptionsThanksToAPINotes) {
UnknownOptionsThanksToAPINotesFirst = 1,
};
4 changes: 4 additions & 0 deletions test/Inputs/clang-importer-sdk/usr/include/module.map
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ module objc_structs {
export *
}

module enums_using_attributes {
header "enums_using_attributes.h"
}

module errors {
header "errors.h"
export *
Expand Down