This matches how GCC handles it, see e.g. https://gcc.godbolt.org/z/HPplnl.
The previous behaviour of gnu_inline in C++, without the extern keyword, can be traced back to the original commit that added support for gnu_inline, SVN r69045.
Differential D67414
[AST] Treat "inline gnu_inline" the same way as "extern inline gnu_inline" in C++ mode mstorsjo on Sep 10 2019, 1:52 PM. Authored by
Details
This matches how GCC handles it, see e.g. https://gcc.godbolt.org/z/HPplnl. The previous behaviour of gnu_inline in C++, without the extern keyword, can be traced back to the original commit that added support for gnu_inline, SVN r69045.
Diff Detail
Event Timeline
Comment Actions Seems very surprising to me that the gnu_inline attribute has different behavior in their C and C++ frontends. That said, it looks like it's a behavior that they document; their documentation says "In C++, this attribute does not depend on extern in any way, but it still requires the inline keyword to enable its special behavior." and that matches their observed behavior. And they behave this way even for functions in extern "C" blocks. The question for us, then, is do we want to be compatible with C source code built as C++ (that is, the status quo) and C++ source code using this attribute and targeting older versions of Clang, or with g++? Is Clang's current behavior actually causing problems for some real use case? Changing this behavior is not without risk, and the old behavior is certainly defensible. If we want to match GCC's behavior for gnu_inline in C++ mode, we should think about whether we also want to permit things like: __attribute__((__gnu_inline__)) extern inline int externinlinefunc() { return 0; } int externinlinefunc() { return 1; } (with or without the extern), which g++ allows and clang rejects. Comment Actions I think it's a rather uncommon combination (I think most use of gnu_inline is together with extern), so I wouldn't think that there's a lot of users relying on the current behaviour (in clang-only codebases), but I have no data to back it up with.
It did come up in mingw-w64 recently; new header additions (that were developed with gcc) broke when built with clang (due to multiple definitions of a symbol). It's been rectified for now by avoiding this combination (for compatibility with existing clang versions) though. Comment Actions OK. If this is causing compatibility pain in practice, following GCC here seems reasonable. We should at least produce a warning on gnu_inline without extern in C++ mode, though. Comment Actions Yes, a warning probably is good. As these things tend to be in headers, it'd be quite spammy, but it would alert the user that while the construct does work in current (future) clang versions, it doesn't in older ones, allowing users to steer clear of it. Is there any existing DiagGroup which would be a good fit for such a warning, and what would be good wording for it? "gnu_inline without extern in C++ treated as if externally available" (which is exactly what the GCC docs for the attribute says, which isn't too understandable unless you know the history) "gnu_inline without extern in C++ changed behaviour in Clang 10" (doesn't say much about what changed and how) Comment Actions Adapted based on the feedback so far, suggestions on naming and grouping the warning are welcome. The warning did trigger in an existing CUDA test as well - I'm not familiar with cuda and how it relates to other languages, so suggestions on what to do wrt it, if anything, are also welcome.
Comment Actions Updated the CUDA test based on the suggestion. @rsmith - What do you think of this version, the warning message, and the invariants for the isInlineDefinitionExternallyVisible method? Comment Actions It looks like our behavior still differs from gcc in the case of a static inline __attribute__((gnu_inline)) function: https://gcc.godbolt.org/z/cY9-HQ. We emit it and gcc doesn't. I don't think that combination makes a lot of sense, but I ran into it in some internal code while testing LLVM 10. Comment Actions gcc's behavior for your testcase makes no sense. We have to emit the definition of a static function: it can't be defined in any other translation unit because it's impossible to name in any other translation unit. Note the "_ZL" prefix. (Given the way ELF works, I guess you could get around that limitation if the function is extern "C", but still...) Comment Actions You're right. Perhaps we should just not warn for the combination of static and gnu_inline then? On my end I'm just planning to drop the gnu_inline in the internal code though, since I can't fathom a reason for wanting the combination of the two. Comment Actions I agree, it doesn't make sense to warn on static functions; the behavior didn't change, and there's only one reasonable result. |