[cfe-dev] LibC functions redefined by the user

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Tue May 5 09:25:57 PDT 2020


On 04/05/2020 16:15, Michael Kruse via cfe-dev wrote:
> As for Clang, a C/C++/Objective-C frontend, it adheres to the
> C/C++/Objectice-C specification where those function names are
> reserved. I recommend not to redefine those.
> 
> I am not sure what the purpose of the -fno-builtin-* flags are, but I
> suggest to avoid them as they are non-standard. For Clang, the only
> reason for their existence is probably compatibility with gcc.

The C standard is written assuming that a C standard library 
implementation appeared fully formed out of the aether.  It is UB to 
define any of the functions from the standard library.  It is UB to 
dereference a pointer after it has been passed to free.  It is therefore 
completely impossible to implement a C standard library in standard C.

As a result, compilers define a superset of C, which allows the standard 
library to be implemented.  The -fno-builtin-* flags are intended to 
support this.

Some of the cases are particularly complex.  For example, some of the 
math.h functions need to disallow the compiler from treating others as 
builtins.  We've had cases in FreeBSD's libm, for example, where part of 
one function was turned by the compiler into something calling another 
libm function that, in turn called the first one.  Specifying 
-fno-builtin-* flags allows the compiler to know that this transform is 
unsound.

David



More information about the cfe-dev mailing list