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] Aliasing inline log1pf causes compilation failure #95748

Open
fpallaresintel opened this issue Jun 17, 2024 · 3 comments
Open

[clang] Aliasing inline log1pf causes compilation failure #95748

fpallaresintel opened this issue Jun 17, 2024 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@fpallaresintel
Copy link

fpallaresintel commented Jun 17, 2024

Clang throws an error when compiling the following C code. Changing the log1pf function name to something else will make this compile, as well as removing inline or __attribute__((always_inline)) from the definition. This code compiles with GCC.
https://godbolt.org/z/oqPeqsva6

float log1pf(float);

inline float __attribute__((always_inline)) log1pf(float x) {
  return x;
}

float foo(float) __attribute__((alias("log1pf")));

Output:

<source>:7:33: error: alias must point to a defined variable or function
    7 | float foo(float) __attribute__((alias("log1pf")));
      |                                 ^
<source>:7:33: note: the function or variable specified in an alias must refer to its mangled name
<source>:7:33: note: function by that name is mangled as "log1pf"
    7 | float foo(float) __attribute__((alias("log1pf")));
      |                                 ^~~~~~~~~~~~~~~
      |                                 alias("log1pf")
1 error generated.
Compiler returned: 1

Version (trunk):

clang version 19.0.0git (https://github.com/llvm/llvm-project.git 753498eed1d2d6d8c419bae5b65458640e5fbfd7)
Target: x86_64-unknown-linux-gnu
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jun 17, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Jun 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2024

@llvm/issue-subscribers-clang-frontend

Author: Ferran Pallarès (fpallaresintel)

Clang throws an error when compiling the following C code. Changing the `log1pf` function name to something else will make this compile, as well as removing `inline` or `__attribute__((always_inline))` from the definition. This code compiles with GCC. https://godbolt.org/z/oqPeqsva6 ``` float log1pf(float);

inline float attribute((always_inline)) log1pf(float x) {
return x;
}

float foo(float) attribute((alias("log1pf")));

Output:

<source>:7:33: error: alias must point to a defined variable or function
7 | float foo(float) attribute((alias("log1pf")));
| ^
<source>:7:33: note: the function or variable specified in an alias must refer to its mangled name
<source>:7:33: note: function by that name is mangled as "log1pf"
7 | float foo(float) attribute((alias("log1pf")));
| ^~~~~~~~~~~~~~~
| alias("log1pf")
1 error generated.
Compiler returned: 1

</details>

@efriedma-quic
Copy link
Collaborator

In general, an alias has to be aliased to a definition, in the ELF sense. A C "inline definition" doesn't count as a definition in that sense. So we have to make sure that the definition is written in a way that it will actually be emitted.

Normally, the given testcase wouldn't count as an "inline definition"... but this particular testcase is hitting the carveout from https://reviews.llvm.org/D71082 . Which I think is a bug: it shouldn't count as an inline definition of a builtin because it's not an inline definition at all. That said, it's hard for me to imagine anyone hitting this in practice.

@shafik
Copy link
Collaborator

shafik commented Sep 3, 2024

Looks like a duplicate of: #89474

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