[cfe-dev] LibC functions redefined by the user

Alexey Zhikhartsev via cfe-dev cfe-dev at lists.llvm.org
Mon May 4 08:01:00 PDT 2020


Hi Michael, Johannes,


I'm creating a new thread since my question would be slightly out-of-topic
in the original discussion about function attributes:

http://lists.llvm.org/pipermail/llvm-dev/2020-April/141312.html



If my reading of the C standard is correct, it is UB to redefine libc
functions: "If the program declares or defines an identifier in a context
in which it is reserved (other than as allowed by 7.1.4), or defines a
reserved identifier as a macro name, the behavior is undefined." (
http://port70.net/~nsz/c/c11/n1570.html#7.1.3p2)



Michael mentioned this in the original thread:



> Frontends are supposed to add a "nobuiltin" attribute to functions that
do not correspond to the semantics of the C library function with the same
name.



I don't think it was implied that the frontend can argue about the
semantics of a function, was it?



There is a "-fno-builtin-<value> family of clang CLI options that forbid
the compiler to convert libc calls into intrinsics. Is it correct to say
that the only way for the user to define their `memcpy` and avoid UB is to
pass "-fno-builtin-memcpy" to the compiler?


Thanks,

Alexey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200504/a9f56f05/attachment-0001.html>


More information about the cfe-dev mailing list