Open clin111 opened 4 years ago
I think we just need to add aligned_alloc
to clang/include/clang/Basic/Builtins.def
It's not immediately clear to me what has to be done here. I've never worked on Clang, but this looks pretty straightforward to fix for someone who has. It's also not clear if InstCombine has to be fixed to do the right thing whenever the alignment isn't known to be a power of two. When the alignment isn't a power of two, aligned_alloc
returns NULL
and errno
should be EINVAL
.
Extended Description
For users that have a different
aligned_alloc
implementation such as jemalloc: http://jemalloc.net/it might be desirable to turn off TLI recognition of
aligned_alloc
(commit D76970) without having to turn off all builtins with-fno-builtin
or-ffreestanding
.-fno-builtin-aligned_alloc
doesn't look like it's recognized by the front end (and doesn't result in anobuiltin
attribute on the call).As an example of a difference, the above jemalloc library is strict POSIX and will set
errno
if a non-power-of-2 alignment is given. When the code below is compiled withclang -O2
and jemalloc, theprintf
will print(nil) 0
because jemalloc will produceNULL
, but InstCombine assumes the call will succeed and replaceserrno
with 0. Having a way to turn off recognition just for this function, would be very helpful to fix the inconsistency.