aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Function.cpp
diff options
context:
space:
mode:
authorlntue <35648136+lntue@users.noreply.github.com>2024-09-11 14:13:31 -0400
committerGitHub <noreply@github.com>2024-09-11 14:13:31 -0400
commit1896ee38898a73ea9c2894e848884c8999884ab1 (patch)
tree8c27e2a00766ce5a486eb9d4c0bb61a12a2c06b6 /llvm/lib/IR/Function.cpp
parent8625eb0b87c86d3ef42a365d7593eed664b379e8 (diff)
downloadllvm-1896ee38898a73ea9c2894e848884c8999884ab1.zip
llvm-1896ee38898a73ea9c2894e848884c8999884ab1.tar.gz
llvm-1896ee38898a73ea9c2894e848884c8999884ab1.tar.bz2
[libc] Fix undefined behavior for nan functions. (#106468)
Currently the nan* functions use nullptr dereferencing to crash with SIGSEGV if the input is nullptr. Both `nan(nullptr)` and `nullptr` dereferencing are undefined behaviors according to the C standard. Employing `nullptr` dereference in the `nan` function implementation is ok if users only linked against the pre-built library, but it might be completely removed by the compilers' optimizations if it is built from source together with the users' code. See for instance: https://godbolt.org/z/fd8KcM9bx This PR uses volatile load to prevent the undefined behavior if libc is built without sanitizers, and leave the current undefined behavior if libc is built with sanitizers, so that the undefined behavior can be caught for users' codes.
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
0 files changed, 0 insertions, 0 deletions