Skip to content
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

Availability attribute triggers from a non-template inline function marked as unavailable #61563

Open
ldionne opened this issue Mar 20, 2023 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@ldionne
Copy link
Member

ldionne commented Mar 20, 2023

The following code snippet fails to compile:

cat <<EOF | clang++ -xc++ - -fsyntax-only
__attribute__((unavailable))
void f(char*) { }

template <class T>
void call_it(T* p) {
  f(p);
}

// template <class = void>
inline __attribute__((unavailable))
void top_level(char* p) {
  call_it(p);
}
EOF

The compiler issues the following error:

<stdin>:6:3: error: 'f' is unavailable
  f(p);
  ^
<stdin>:12:3: note: in instantiation of function template specialization 'call_it<char>' requested here
  call_it(p);
  ^
<stdin>:2:6: note: 'f' has been explicitly marked unavailable here
void f(char*) { }
     ^
1 error generated.

This is annoying because top_level is an inline function that never gets called and is marked as unavailable, yet the availability attribute on the leaf function f() still triggers an error. This means that we need to poison all the functions in the stack from top_level() to f() with the availability attribute, which could be many many functions. Instead, it seems that inline functions should have their availability attribute treated a bit more lazily.

Basically, __availability__ should be an attribute on symbols required from a TU. If there is no dependency of the program on the f symbol (in this case aka if there was no codegen for top_level()), there should be no diagnostic because the program doesn't actually depend on f().

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Mar 20, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 20, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Mar 20, 2023

Note gcc also generates a diagnostic for this case: https://godbolt.org/z/fqjaYThTj

From what can see this is expected behavior @AaronBallman wdyt?

@AaronBallman
Copy link
Collaborator

I don't honestly recall if this is expected behavior or not -- the unavailable attribute predates Attr.td even existing and it has no documentation associated with it. I haven't been able to track down who added it to see what the review looks like for it.

Changing the behavior of the attribute seems risky because we might break long-standing expectations from someone, but it's really hard to say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

5 participants