Skip to content

Revert "Extend availability attribute to support feature-based availability" #10189

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
30 changes: 0 additions & 30 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "clang/AST/RawCommentList.h"
#include "clang/AST/TemplateName.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/DenseMap.h"
Expand Down Expand Up @@ -802,35 +801,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
return DiagAllocator;
}

struct AvailabilityDomainInfo {
FeatureAvailKind Kind = FeatureAvailKind::None;
ImplicitCastExpr *Call = nullptr;
bool isInvalid() const { return Kind == FeatureAvailKind::None; }
};

std::map<StringRef, AvailabilityDomainInfo> AvailabilityDomainMap;

void addAvailabilityDomainMap(StringRef Name, AvailabilityDomainInfo Info) {
AvailabilityDomainMap[Name] = Info;
}

std::pair<DomainAvailabilityAttr *, bool>
checkNewFeatureAvailability(Decl *D, StringRef DomainName, bool Unavailable);

bool hasFeatureAvailabilityAttr(const Decl *D) const;

// Retrieve availability domain information for a feature.
AvailabilityDomainInfo getFeatureAvailInfo(StringRef FeatureName) const;

// Retrieve feature name and availability domain information on a decl. If the
// decl doesn't have attribute availability_domain on it, the name will be
// empty and AvailabilityDomainInfo::Kind will be set to
// FeatureAvailKind::None.
std::pair<StringRef, AvailabilityDomainInfo>
getFeatureAvailInfo(Decl *D) const;

bool hasUnavailableFeature(const Decl *D) const;

const TargetInfo &getTargetInfo() const { return *Target; }
const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }

Expand Down
12 changes: 1 addition & 11 deletions clang/include/clang/AST/Availability.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class AvailabilitySpec {
/// Name of the platform that Version corresponds to.
StringRef Platform;

StringRef DomainName;

SourceLocation BeginLoc, EndLoc;

public:
Expand All @@ -47,9 +45,6 @@ class AvailabilitySpec {
: Version(Version), Platform(Platform), BeginLoc(BeginLoc),
EndLoc(EndLoc) {}

AvailabilitySpec(StringRef DomainName, SourceLocation Loc)
: DomainName(DomainName), BeginLoc(Loc), EndLoc(Loc) {}

/// This constructor is used when representing the '*' case.
AvailabilitySpec(SourceLocation StarLoc)
: BeginLoc(StarLoc), EndLoc(StarLoc) {}
Expand All @@ -60,12 +55,7 @@ class AvailabilitySpec {
SourceLocation getEndLoc() const { return EndLoc; }

/// Returns true when this represents the '*' case.
bool isOtherPlatformSpec() const {
return Version.empty() && DomainName.empty();
}

bool isDomainName() const { return !DomainName.empty(); }
StringRef getDomainName() const { return DomainName; }
bool isOtherPlatformSpec() const { return Version.empty(); }
};

class Decl;
Expand Down
39 changes: 2 additions & 37 deletions clang/include/clang/AST/ExprObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -1693,9 +1693,7 @@ class ObjCBridgedCastExpr final
/// be used in the condition of an \c if, but it is also usable as top level
/// expressions.
///
class ObjCAvailabilityCheckExpr final
: public Expr,
private llvm::TrailingObjects<ObjCAvailabilityCheckExpr, char> {
class ObjCAvailabilityCheckExpr : public Expr {
public:
struct VersionAsWritten {
/// Platform version canonicalized for use with availability checks.
Expand All @@ -1706,46 +1704,21 @@ class ObjCAvailabilityCheckExpr final

private:
friend class ASTStmtReader;
friend llvm::TrailingObjects<ObjCAvailabilityCheckExpr, char>;

VersionAsWritten VersionToCheck;
SourceLocation AtLoc, RParen;

void setHasDomainName(bool V) {
ObjCAvailabilityCheckExprBits.HasDomainName = V;
}

ObjCAvailabilityCheckExpr(SourceLocation AtLoc, SourceLocation RParen,
QualType Ty, StringRef DomainName)
: Expr(ObjCAvailabilityCheckExprClass, Ty, VK_PRValue, OK_Ordinary),
VersionToCheck(), AtLoc(AtLoc), RParen(RParen) {
setDependence(ExprDependence::None);
setHasDomainName(true);
strcpy(getTrailingObjects<char>(), DomainName.data());
}

public:
ObjCAvailabilityCheckExpr(VersionAsWritten VersionToCheck,
SourceLocation AtLoc,
SourceLocation RParen, QualType Ty)
: Expr(ObjCAvailabilityCheckExprClass, Ty, VK_PRValue, OK_Ordinary),
VersionToCheck(VersionToCheck), AtLoc(AtLoc), RParen(RParen) {
setDependence(ExprDependence::None);
setHasDomainName(false);
}

static ObjCAvailabilityCheckExpr *
CreateAvailabilityFeatureCheck(SourceLocation AtLoc, SourceLocation RParen,
QualType Ty, StringRef DomainName,
const ASTContext &C);

explicit ObjCAvailabilityCheckExpr(EmptyShell Shell)
: Expr(ObjCAvailabilityCheckExprClass, Shell) {
setHasDomainName(false);
}

static ObjCAvailabilityCheckExpr *
CreateEmpty(const ASTContext &C, Stmt::EmptyShell Empty, size_t FeaturesLen);
: Expr(ObjCAvailabilityCheckExprClass, Shell) {}

SourceLocation getBeginLoc() const { return AtLoc; }
SourceLocation getEndLoc() const { return RParen; }
Expand All @@ -1758,14 +1731,6 @@ class ObjCAvailabilityCheckExpr final
return VersionToCheck.SourceVersion;
}

bool hasDomainName() const {
return ObjCAvailabilityCheckExprBits.HasDomainName;
}
StringRef getDomainName() const {
assert(hasDomainName());
return getTrailingObjects<char>();
}

child_range children() {
return child_range(child_iterator(), child_iterator());
}
Expand Down
10 changes: 0 additions & 10 deletions clang/include/clang/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1226,15 +1226,6 @@ class alignas(void *) Stmt {
unsigned ShouldCopy : 1;
};

class ObjCAvailabilityCheckExprBitfields {
friend class ObjCAvailabilityCheckExpr;
LLVM_PREFERRED_TYPE(ExprBitfields)
unsigned : NumExprBits;

LLVM_PREFERRED_TYPE(bool)
unsigned HasDomainName : 1;
};

//===--- Clang Extensions bitfields classes ---===//

class OpaqueValueExprBitfields {
Expand Down Expand Up @@ -1333,7 +1324,6 @@ class alignas(void *) Stmt {

// Obj-C Expressions
ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
ObjCAvailabilityCheckExprBitfields ObjCAvailabilityCheckExprBits;

// Clang Extensions
OpaqueValueExprBitfields OpaqueValueExprBits;
Expand Down
19 changes: 0 additions & 19 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1124,25 +1124,6 @@ static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef Environm
let Documentation = [AvailabilityDocs];
}

def DomainAvailability : InheritableAttr {
// This attribute has no spellings as it is created implicitly when
// __attribute__((availability(domain:...))) is seen.
let Spellings = [];
let Args = [StringArgument<"domain">, BoolArgument<"unavailable">];
let AdditionalMembers = [{
std::string getFeatureAttributeStr() const;
}];
let Documentation = [InternalOnly];
}

// This attribute is used to annotate structs of type `_AvailabilityDomain`.
def AvailabilityDomain : InheritableAttr {
let Spellings = [Clang<"availability_domain">];
let Args = [IdentifierArgument<"name">];
let Subjects = SubjectList<[Var]>;
let Documentation = [Undocumented];
}

def ExternalSourceSymbol : InheritableAttr {
let Spellings = [Clang<"external_source_symbol", /*allowInC=*/1,
/*version=*/20230206>];
Expand Down
3 changes: 0 additions & 3 deletions clang/include/clang/Basic/DiagnosticFrontendKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ def err_fe_invalid_exception_model
def err_fe_invalid_source_date_epoch : Error<
"environment variable 'SOURCE_DATE_EPOCH' ('%0') must be a non-negative decimal integer <= %1">;

def err_feature_availability_flag_invalid_value : Error<
"invalid value '%0' passed to '-ffeature-availability='; expected <feature>:<on|off>">;

def err_fe_incompatible_option_with_remote_cache : Error<
"'%0' is incompatible with remote caching backend">;
def err_fe_unable_to_load_include_tree : Error<
Expand Down
5 changes: 0 additions & 5 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,6 @@ def err_availability_expected_platform : Error<
def err_availability_expected_environment : Error<
"expected an environment name, e.g., 'compute'">;

def err_features_domain_name : Error<
"expected a domain name">;
def err_feature_invalid_availability_check : Error<
"cannot pass a domain argument along with other arguments">;

// objc_bridge_related attribute
def err_objcbridge_related_expected_related_class : Error<
"expected a related Objective-C class name, e.g., 'NSColor'">;
Expand Down
22 changes: 0 additions & 22 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -3960,28 +3960,6 @@ def err_availability_unexpected_parameter: Error<
def warn_unguarded_availability :
Warning<"%0 is only available %select{|in %4 environment }3on %1 %2 or newer">,
InGroup<UnguardedAvailability>, DefaultIgnore;
def err_unguarded_feature : Error<
"use of %0 requires feature '%1' to be %select{available|unavailable}2">;
def err_label_in_conditionally_guarded_feature : Error<
"labels cannot appear in regions conditionally guarded by features">;
def err_features_invalid_for_decl : Error<
"feature attributes cannot be applied to %0">;
def err_features_invalid_name : Error<
"cannot find definition of feature attribute '%0'">;
def err_features_invalid__arg : Error<
"invalid argument %0: must evaluate to 0 or 1">;
def err_feature_invalid_for_decl : Error<
"feature attribute '%0(%1)' cannot be applied to this decl">;
def err_feature_merge_incompatible : Error<
"cannot merge incompatible feature attribute to this decl">;
def err_new_feature_redeclaration : Error<
"new feature attributes cannot be added to redeclarations">;
def err_feature_invalid_added : Error<
"cannot add feature availability to this decl">;
def note_feature_incompatible0 : Note<
"feature attribute %0">;
def note_feature_incompatible1 : Note<
"is incompatible with %0">;
def warn_unguarded_availability_unavailable :
Warning<"%0 is unavailable">,
InGroup<UnguardedAvailability>, DefaultIgnore;
Expand Down
14 changes: 0 additions & 14 deletions clang/include/clang/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ enum class PointerAuthenticationMode : unsigned {
SignAndAuth
};

enum class FeatureAvailKind { None, Available, Unavailable, Dynamic };

/// Bitfields of LangOptions, split out from LangOptions in order to ensure that
/// this large collection of bitfields is a trivial class type.
class LangOptionsBase {
Expand Down Expand Up @@ -546,8 +544,6 @@ class LangOptions : public LangOptionsBase {
/// This list is sorted.
std::vector<std::string> ModuleFeatures;

std::vector<std::string> FeatureAvailability;

/// Options for parsing comments.
CommentOptions CommentOpts;

Expand All @@ -565,16 +561,6 @@ class LangOptions : public LangOptionsBase {
/// host code generation.
std::string OMPHostIRFile;

llvm::StringMap<FeatureAvailKind> FeatureAvailabilityMap;

void setFeatureAvailability(StringRef Feature, FeatureAvailKind Kind) {
FeatureAvailabilityMap[Feature] = Kind;
}

FeatureAvailKind getFeatureAvailability(StringRef Feature) const {
return FeatureAvailabilityMap.lookup(Feature);
}

/// The user provided compilation unit ID, if non-empty. This is used to
/// externalize static variables which is needed to support accessing static
/// device variables in host code for single source offloading languages
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3433,10 +3433,6 @@ def fno_builtin : Flag<["-"], "fno-builtin">, Group<f_Group>,
def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group<f_Group>,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
HelpText<"Disable implicit builtin knowledge of a specific function">;
def ffeature_availability_EQ : Joined<["-"], "ffeature-availability=">, Group<f_Group>,
Visibility<[CC1Option]>,
HelpText<"feature availability">,
MarshallingInfoStringVector<LangOpts<"FeatureAvailability">>;
def fno_common : Flag<["-"], "fno-common">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Compile common globals like normal definitions">;
Expand Down
6 changes: 0 additions & 6 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3127,12 +3127,6 @@ class Parser : public CodeCompletionHandler {
void ParseHLSLQualifiers(ParsedAttributes &Attrs);

VersionTuple ParseVersionTuple(SourceRange &Range);
void ParseFeatureAvailabilityAttribute(
IdentifierInfo &Availability, SourceLocation AvailabilityLoc,
ParsedAttributes &attrs, SourceLocation *endLoc,
IdentifierInfo *ScopeName, SourceLocation ScopeLoc, ParsedAttr::Form Form,
BalancedDelimiterTracker &T);

void ParseAvailabilityAttribute(IdentifierInfo &Availability,
SourceLocation AvailabilityLoc,
ParsedAttributes &attrs,
Expand Down
21 changes: 1 addition & 20 deletions clang/include/clang/Sema/DelayedDiagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ class AccessedEntity {
/// the complete parsing of the current declaration.
class DelayedDiagnostic {
public:
enum DDKind : unsigned char {
Availability,
FeatureAvailability,
Access,
ForbiddenType
};
enum DDKind : unsigned char { Availability, Access, ForbiddenType };

DDKind Kind;
bool Triggered;
Expand All @@ -148,9 +143,6 @@ class DelayedDiagnostic {
StringRef Msg,
bool ObjCPropertyAccess);

static DelayedDiagnostic
makeFeatureAvailability(NamedDecl *D, ArrayRef<SourceLocation> Locs);

static DelayedDiagnostic makeAccess(SourceLocation Loc,
const AccessedEntity &Entity) {
DelayedDiagnostic DD;
Expand Down Expand Up @@ -209,12 +201,6 @@ class DelayedDiagnostic {
return AvailabilityData.AR;
}

const NamedDecl *getFeatureAvailabilityDecl() const {
assert(Kind == FeatureAvailability &&
"Not a feature availability diagnostic.");
return FeatureAvailabilityData.Decl;
}

/// The diagnostic ID to emit. Used like so:
/// Diag(diag.Loc, diag.getForbiddenTypeDiagnostic())
/// << diag.getForbiddenTypeOperand()
Expand Down Expand Up @@ -260,10 +246,6 @@ class DelayedDiagnostic {
bool ObjCPropertyAccess;
};

struct FAD {
const NamedDecl *Decl;
};

struct FTD {
unsigned Diagnostic;
unsigned Argument;
Expand All @@ -272,7 +254,6 @@ class DelayedDiagnostic {

union {
struct AD AvailabilityData;
struct FAD FeatureAvailabilityData;
struct FTD ForbiddenTypeData;

/// Access control.
Expand Down
2 changes: 0 additions & 2 deletions clang/include/clang/Sema/ParsedAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,6 @@ class ParsedAttr final
return IsProperty;
}

bool isAvailabilityAttribute() const { return IsAvailability; }

bool isInvalid() const { return Invalid; }
void setInvalid(bool b = true) const { Invalid = b; }

Expand Down
5 changes: 1 addition & 4 deletions clang/include/clang/Sema/ScopeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ class FunctionScopeInfo {
/// unavailable.
bool HasPotentialAvailabilityViolations : 1;

bool HasPotentialFeatureAvailabilityViolations : 1;

/// A flag that is set when parsing a method that must call super's
/// implementation, such as \c -dealloc, \c -finalize, or any method marked
/// with \c __attribute__((objc_requires_super)).
Expand Down Expand Up @@ -396,8 +394,7 @@ class FunctionScopeInfo {
HasBranchIntoScope(false), HasIndirectGoto(false), HasMustTail(false),
HasDroppedStmt(false), HasOMPDeclareReductionCombiner(false),
HasFallthroughStmt(false), UsesFPIntrin(false),
HasPotentialAvailabilityViolations(false),
HasPotentialFeatureAvailabilityViolations(false), ObjCShouldCallSuper(false),
HasPotentialAvailabilityViolations(false), ObjCShouldCallSuper(false),
ObjCIsDesignatedInit(false), ObjCWarnForNoDesignatedInitChain(false),
ObjCIsSecondaryInit(false), ObjCWarnForNoInitDelegation(false),
NeedsCoroutineSuspends(true), FoundImmediateEscalatingExpression(false),
Expand Down
Loading