-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Sema] Mark alias/ifunc targets used and consider mangled names #87130
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
Changes from 5 commits
23422a0
9ae8958
3bd4297
6f2a3da
1b3847e
c3793ad
1e8d74c
fb2b988
5b85c1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
set(LLVM_LINK_COMPONENTS | ||
Core | ||
Demangle | ||
FrontendHLSL | ||
FrontendOpenMP | ||
MC | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c -verify %s | ||
nickdesaulniers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// RUN: %clang_cc1 -triple %itanium_abi_triple -Wunused -x c++ -verify=expected,cxx %s | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
static int f(void) { return 42; } | ||
int g(void) __attribute__((alias("f"))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong to me, a false negative. FWICT, for C++ mode, even in an We mangle, they do not. That's going to lead to further compatibility issues when trying to use this function attribute. Ah! right you pointed this out in your note. Perhaps we should fix/change that first in clang? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I remember an existing issue about the mangling difference, but I don't recall the link now. https://eel.is/c++draft/dcl.link gives an example extern "C" {
static void f4(); // the name of the function f4 has internal linkage,
// so f4 has no language linkage; its type has C language linkage
} I am unsure whether "no language linkage" means that ignoring the C language linkage is fine. Improving GCC consistency is not the goal of this PR. This PR intends to make clangSema and clangCodeGen consistent. If we want to follow GCC in the future, the updated test will show the differences. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is there a bug on file wrt to this inconsistency? I would like to link to it from the test, sources, and public docs on the function attribute if we don't fix this inconsistency BEFORE landing this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please file a bug and link to it from a TODO comment in the tests and/or sources. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #88593 But I don't think a TODO applies. Clang's behavior is probably desired. So this just records a difference. This difference probably doesn't make a difference because people rarely use |
||
|
||
static int foo [] = { 42, 0xDEAD }; // cxx-warning{{variable 'foo' is not needed and will not be emitted}} | ||
nickdesaulniers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
extern typeof(foo) bar __attribute__((unused, alias("foo"))); | ||
|
||
static int (*resolver(void))(void) { return f; } // cxx-warning{{unused function 'resolver'}} | ||
nickdesaulniers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int ifunc(void) __attribute__((ifunc("resolver"))); | ||
|
||
static int __attribute__((overloadable)) f0(int x) { return x; } | ||
static float __attribute__((overloadable)) f0(float x) { return x; } // expected-warning{{unused function 'f0'}} | ||
int g0(void) __attribute__((alias("_ZL2f0i"))); | ||
|
||
#ifdef __cplusplus | ||
static int f1() { return 42; } | ||
int g1(void) __attribute__((alias("_ZL2f1v"))); | ||
} | ||
|
||
/// We demangle alias/ifunc target and mark all found functions as used. | ||
|
||
static int f2(int) { return 42; } // cxx-warning{{unused function 'f2'}} | ||
static int f2() { return 42; } | ||
int g2() __attribute__((alias("_ZL2f2v"))); | ||
|
||
static int (*resolver1())() { return f; } // cxx-warning{{unused function 'resolver1'}} | ||
static int (*resolver1(int))() { return f; } | ||
int ifunc1() __attribute__((ifunc("_ZL9resolver1i"))); | ||
|
||
/// We should report "unused function" for f3(int). | ||
namespace ns { | ||
static int f3(int) { return 42; } // cxx-warning{{unused function 'f3'}} | ||
static int f3() { return 42; } // cxx-warning{{unused function 'f3'}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Isn't this with Is this a bug in Sema::LookupOrdinaryName ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surely there's another case where we need to go from mangled string back to named decl. Perhaps there's somewhere else in clang that already does so and can be reused here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fully support qualified names in alias/ifunc attributes for the This PR intends to address the The test is added here to test the current behavior. |
||
int g3() __attribute__((alias("_ZN2nsL2f3Ev"))); | ||
} | ||
|
||
template <class T> | ||
static void *f4(T) { return nullptr; } | ||
static void *f4() { return nullptr; } // cxx-warning{{unused function 'f4'}} | ||
extern void g4() __attribute__((ifunc("_ZL2f4IiEPvT_"))); | ||
void *use3 = f4(0); | ||
nickdesaulniers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif |
Uh oh!
There was an error while loading. Please reload this page.