| Issue |
184362
|
| Summary |
Attribute on namespace overrides `-fvisibility-inlines-hidden`
|
| Labels |
clang:codegen,
diverges-from:gcc
|
| Assignees |
|
| Reporter |
aaronpuchert
|
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`: the library applies default visibility on namespace level, but this prevents inlining if the functions are not interposable.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs