Attribute on namespace overrides `-fvisibility-inlines-hidden`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Compile the following code with `-fPIC -fvisibility-inlines-hidden`:
```c++
__attribute__((visibility("default")))
inline int id(int x) { return x; }
struct __attribute__((visibility("default"))) S {
static int id(int x) { return x; }
};
namespace N __attribute__((visibility("default"))) {
inline int id(int x) { return x; }
}
int test(int x) {
return id(x) + S::id(x) + N::id(x);
}
```
We emit only `.hidden S::id(int)`, but GCC additionally emits `.hidden N::id(int)`.
Technically, the [GCC docs](https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-fvisibility-inlines-hidden) don't talk about namespaces:
> You may mark a method as having a visibility explicitly to negate the effect of the switch for that method. For example, if you do want to compare pointers to a particular inline method, you might mark it as having default visibility. Marking the enclosing class with explicit visibility has no effect.
However:
* Namespaces create a weaker connection than classes, so if an attribute on classes doesn't override the flag, an attribute on namespaces should also not do it.
* The motivation talks about "a particular inline method", so it seems the intention is to only take attributes on the function itself into account.
* We're diverging from GCC here.
This can be observed when building with libstdc++ and `-fsemantic-interposition -fvisibility-inlines-hidden`: the library applies default visibility on namespace level, which prevents inlining of inline functions because they get default visibility and thus have to be interposable.
Contributor guide
Research direction
Start by compiling the supplied C++ reproducer with -fPIC -fvisibility-inlines-hidden under LLVM and GCC, then inspect the emitted visibility for S::id(int) and N::id(int). The issue names no source files or tests; done means resolving whether namespace attributes should affect inline visibility and aligning LLVM's behavior with the documented intent and GCC output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100