Skip to content
Merged
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
34 changes: 29 additions & 5 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6868,25 +6868,26 @@ void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
}
}

static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
// Ensure that an auto decl is deduced otherwise the checks below might cache
// the wrong linkage.
assert(S.ParsingInitForAutoVars.count(&ND) == 0);

static void checkWeakAttr(Sema &S, NamedDecl &ND) {
// 'weak' only applies to declarations with external linkage.
if (WeakAttr *Attr = ND.getAttr<WeakAttr>()) {
if (!ND.isExternallyVisible()) {
S.Diag(Attr->getLocation(), diag::err_attribute_weak_static);
ND.dropAttr<WeakAttr>();
}
}
}

static void checkWeakRefAttr(Sema &S, NamedDecl &ND) {
if (WeakRefAttr *Attr = ND.getAttr<WeakRefAttr>()) {
if (ND.isExternallyVisible()) {
S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
ND.dropAttrs<WeakRefAttr, AliasAttr>();
}
}
}

static void checkAliasAttr(Sema &S, NamedDecl &ND) {
if (auto *VD = dyn_cast<VarDecl>(&ND)) {
if (VD->hasInit()) {
if (const auto *Attr = VD->getAttr<AliasAttr>()) {
Expand All @@ -6897,7 +6898,9 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
}
}
}
}

static void checkSelectAnyAttr(Sema &S, NamedDecl &ND) {
// 'selectany' only applies to externally visible variable declarations.
// It does not apply to functions.
if (SelectAnyAttr *Attr = ND.getAttr<SelectAnyAttr>()) {
Expand All @@ -6907,12 +6910,17 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
ND.dropAttr<SelectAnyAttr>();
}
}
}

static void checkHybridPatchableAttr(Sema &S, NamedDecl &ND) {
if (HybridPatchableAttr *Attr = ND.getAttr<HybridPatchableAttr>()) {
if (!ND.isExternallyVisible())
S.Diag(Attr->getLocation(),
diag::warn_attribute_hybrid_patchable_non_extern);
}
}

static void checkInheritableAttr(Sema &S, NamedDecl &ND) {
if (const InheritableAttr *Attr = getDLLAttr(&ND)) {
auto *VD = dyn_cast<VarDecl>(&ND);
bool IsAnonymousNS = false;
Expand All @@ -6937,7 +6945,9 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
ND.setInvalidDecl();
}
}
}

static void checkLifetimeBoundAttr(Sema &S, NamedDecl &ND) {
// Check the attributes on the function type and function params, if any.
if (const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
// Don't declare this variable in the second operand of the for-statement;
Expand Down Expand Up @@ -6989,6 +6999,20 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
}
}

static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
// Ensure that an auto decl is deduced otherwise the checks below might cache
// the wrong linkage.
assert(S.ParsingInitForAutoVars.count(&ND) == 0);

checkWeakAttr(S, ND);
checkWeakRefAttr(S, ND);
checkAliasAttr(S, ND);
checkSelectAnyAttr(S, ND);
checkHybridPatchableAttr(S, ND);
checkInheritableAttr(S, ND);
checkLifetimeBoundAttr(S, ND);
}

static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
NamedDecl *NewDecl,
bool IsSpecialization,
Expand Down
Loading