llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.06k stars 11.59k forks source link

[clang] Aliasing inline log1pf causes compilation failure #95748

Open fpallaresintel opened 3 months ago

fpallaresintel commented 3 months ago

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
llvmbot commented 3 months ago

@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 ```
efriedma-quic commented 3 months ago

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 commented 2 weeks ago

Looks like a duplicate of: https://github.com/llvm/llvm-project/issues/89474