llvm / llvm-project

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

Clang complains about ambiguous functions with #pragma weak #56760

Open clausecker opened 2 years ago

clausecker commented 2 years ago

In a variant of bug #35478, we can fix the compiler crash by declaring the functions involved with prototypes. This works fine when no parameters are involved. However, once a parameter enters the game, we get a weird compiler error. This is all C code.

int test2(int), test1(int);
#pragma weak test2 = test1
int test1(int i) { return 0; }
int main() { return test2(0); return 0; }

When compiling with clang 14.0.6, I get the following error message:

a.c:4:21: error: call to 'test2' is ambiguous
int main() { return test2(0); return 0; }
                    ^~~~~
a.c:1:5: note: candidate function
int test2(int), test1(int);
    ^
a.c:2:14: note: candidate function
#pragma weak test2 = test1
             ^
1 error generated.

This is very unexpected. GCC processes this code just fine.

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-frontend

Alex-EEE commented 1 year ago

+1 to please fix this. Here is my example:

    __attribute__((weak)) void __throw_length_error(const char*) { while(1); };

Not sure why std version doesn't win in this case

/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/string:1805:9: error: call to 'throw_length_error' is ambiguous std::throw_length_error("basic_string"); ^~~~~~~~~ /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/stdexcept:254:6: note: candidate function void throw_length_error(const char*msg) ^ /Users/alex/work/repos/dsp-hr-transform-block/cpp/./edge-impulse-sdk/dsp/numpy_types.h:589:32: note: candidate function attribute((weak)) void __throw_length_error(const char*) { while(1); };