Code exammple:
#include <string>
std::string __attribute__((warning("getString not inlined/removed"))) getString() {
return "Foo";
}
int main() {
return getString().size();
}
Compiling this with gcc 6.3 and no flags, we get the following warning:
<source>: In function 'int main()':
<source>:10:19: warning: call to 'getString' declared with attribute warning: getString not inlined/removed
return getString().size();
~~~~~~~~~^~
Whereas with -O3
, we don't get a warning and the assembly is a lot shorter:
getString[abi:cxx11]():
lea rdx, [rdi+16]
mov rax, rdi
mov BYTE PTR [rdi+18], 111
mov QWORD PTR [rdi+8], 3
mov BYTE PTR [rdi+19], 0
mov QWORD PTR [rdi], rdx
mov edx, 28486
mov WORD PTR [rdi+16], dx
ret
main:
mov eax, 3
ret