[llvm-dev] Inline function not eventually inlined is removed (original) (raw)

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 4 04:46:30 PDT 2021


On 02/08/2021 18:05, Mariusz Sikora via llvm-dev wrote:

I'm just trying to understand is this Code undefined behavior or this is a bug in LLVM? Because why LLVM is removing functions without inlining it? For example GCC is not removing function event after inlining it.

C++ inline means 'the definition is provided in line with the declaration, the compiler and linker are responsible for ensuring that exactly one definition exists in the final binary'

C inline means 'this definition is provided in line with a declaration and may be used by the compiler in preference to one that a linker finds'

C inline extern means 'a definition of this may appear in line with the declaration but please provide a canonical definition here for when the compiler decides not to emit it'

C inline static means 'a definition exists here inline and it is not an error if this is not used. If it is, then it is private to this compilation unit and it is not an error for the same static function to exist in multiple compilation units'.

None of these say anything about whether the compiler is required to inline the function, but they all specify what must happen to the original definition:

Clang is generating IR that makes LLVM do exactly what the language semantics require: eliminate the definition.

The inline keyword is probably the most confusingly named keyword in C/C++, though static comes close. The general rule of thumb for C is:

David



More information about the llvm-dev mailing list