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

[clang][alias fn attr] error: alias must point to a defined variable or function false negative when optimizations are enabled #89474

Open
nickdesaulniers opened this issue Apr 19, 2024 · 3 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@nickdesaulniers
Copy link
Member

nickdesaulniers commented Apr 19, 2024

https://godbolt.org/z/TrGeazYc5

extern inline __attribute__((gnu_inline))
void bar (void) {}

void foo [[gnu::alias("_Z3barv")]] (void);
void foo2 (void) __attribute__((alias("_Z3barv")));
void foo3 (void) asm("_Z3barv");
<source>:4:12: error: alias must point to a defined variable or function
    4 | void foo [[gnu::alias("_Z3barv")]] (void);
      |            ^
<source>:4:12: note: the function or variable specified in an alias must refer to its mangled name
<source>:5:33: error: alias must point to a defined variable or function
    5 | void foo2 (void) __attribute__((alias("_Z3barv")));
      |                                 ^
<source>:5:33: note: the function or variable specified in an alias must refer to its mangled name

we only observe these diagnostics at -O0, not -O2.

via #60481

@nickdesaulniers nickdesaulniers added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Apr 19, 2024
@nickdesaulniers nickdesaulniers changed the title [clang] error: alias must point to a defined variable or function false negative when optimizations are enabled [clang][alias fn attr] error: alias must point to a defined variable or function false negative when optimizations are enabled Apr 19, 2024
@shafik
Copy link
Collaborator

shafik commented Apr 20, 2024

Worth noting this crashes on asserts build: https://godbolt.org/z/basjzojxE

Alias must point to a definition
ptr @_Z3foov
Alias must point to a definition
ptr @_Z4foo2v
fatal error: error in backend: Broken module found, compilation aborted!

Look related maybe duplicate: #69066

@shafik
Copy link
Collaborator

shafik commented Apr 20, 2024

It looks like we diagnose this in codegen:

if (GV->isDeclaration()) {
Diags.Report(Location, diag::err_alias_to_undefined) << IsIFunc << IsIFunc;
Diags.Report(Location, diag::note_alias_requires_mangled_name)
<< IsIFunc << IsIFunc;

and:

if (IsIFunc) {
// Check resolver function type.
const auto *F = dyn_cast<llvm::Function>(GV);
if (!F) {
Diags.Report(Location, diag::err_alias_to_undefined)
<< IsIFunc << IsIFunc;
return false;
}

I think then it makes more sense now that this is optimization sensitive.

CC @AaronBallman @erichkeane

@AaronBallman
Copy link
Collaborator

Both of those checks should always be called:

void CodeGenModule::Release() {
calls checkAliases() which has no optimization-specific logic. So perhaps optimizations are removing some aliases from the list?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

3 participants