Skip to content

[Sema] Allow @_section/@_used in concrete generic contex #75277

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
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
10 changes: 8 additions & 2 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,10 @@ void AttributeChecker::visitUsedAttr(UsedAttr *attr) {
if (D->getDeclContext()->isLocalContext())
diagnose(attr->getLocation(), diag::attr_only_at_non_local_scope,
attr->getAttrName());
else if (D->getDeclContext()->isGenericContext())
else if (D->getDeclContext()->isGenericContext() &&
!D->getDeclContext()
->getGenericSignatureOfContext()
->areAllParamsConcrete())
diagnose(attr->getLocation(), diag::attr_only_at_non_generic_scope,
attr->getAttrName());
else if (auto *VarD = dyn_cast<VarDecl>(D)) {
Expand All @@ -2345,7 +2348,10 @@ void AttributeChecker::visitSectionAttr(SectionAttr *attr) {
if (D->getDeclContext()->isLocalContext())
return; // already diagnosed

if (D->getDeclContext()->isGenericContext())
if (D->getDeclContext()->isGenericContext() &&
!D->getDeclContext()
->getGenericSignatureOfContext()
->areAllParamsConcrete())
diagnose(attr->getLocation(), diag::attr_only_at_non_generic_scope,
attr->getAttrName());
else if (auto *VarD = dyn_cast<VarDecl>(D)) {
Expand Down
7 changes: 7 additions & 0 deletions test/IRGen/section_errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ struct MyStruct4<T> {
}
}

struct MyStruct5<T> {
}

extension MyStruct5 where T == Never {
@_used @_section("__TEXT,__mysection") static let static3: Int = 1 // ok
}

@_section("__TEXT,__mysection") // expected-error {{'@_section' attribute cannot be applied to this declaration}}
struct SomeStruct {}

Expand Down