[PATCH] D56567: [ADT] Force attribute used on functions marked as always_inline.
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 10 16:43:06 PST 2019
davide marked 2 inline comments as done.
davide added inline comments.
================
Comment at: llvm/include/llvm/ADT/SmallVector.h:128
// forward iterator creation methods.
- LLVM_ATTRIBUTE_ALWAYS_INLINE
+ LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_USED
iterator begin() { return (iterator)this->BeginX; }
----------------
dexonsmith wrote:
> I don't think we want this for Release or RelWithDebInfo builds since it will bloat the binaries. How is `LLVM_ATTRIBUTE_USED` conditionalized in those cases?
Thanks, I agree this should be emitted only at `-O0`.
Is there an easy way of conveying that information?
================
Comment at: llvm/include/llvm/ADT/StringRef.h:127
LLVM_NODISCARD
- LLVM_ATTRIBUTE_ALWAYS_INLINE
+ LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_USED
const char *data() const { return Data; }
----------------
dexonsmith wrote:
> This already has `LLVM_NODISCARD`. How does that differ from `LLVM_ATTRIBUTE_USED`?
They're completely different attributes, to the best of my knowledge.
1) __attribute__((used)) forces the symbol to be emitted even if unreferenced.
http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Variable-Attributes.html
2) [[nodiscard]] causes the compiler to emit a warning if the return value is discarded.
https://en.cppreference.com/w/cpp/language/attributes
Example:
```
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000fa3 a.out`main at pat.cpp:12:3
9
10 int main(void) {
11 Baciotto blondie;
-> 12 return blondie.patatino();
13 }
(lldb) p blondie
(Baciotto) $0 = {}
(lldb) p blondie.patatino()
(int) $1 = 23
(lldb) ^D
Davides-Mac-Pro:bin davide$ cat pat.cpp
class Baciotto {
public:
__attribute__((used))
__attribute__((always_inline))
int patatino() {
return 23;
}
};
int main(void) {
Baciotto blondie;
return blondie.patatino();
}
```
If you use [[nodiscard]], the symbol won't be emitted.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56567/new/
https://reviews.llvm.org/D56567
More information about the llvm-commits
mailing list