]> git.ipfire.org Git - thirdparty/gcc.git/commit
match.pd: Defer some CTZ/CLZ foldings until after ubsan pass for -fsanitize=builtin...
authorJakub Jelinek <jakub@redhat.com>
Thu, 12 Dec 2024 18:47:46 +0000 (19:47 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 12 Dec 2024 18:47:46 +0000 (19:47 +0100)
commitf7d1b9cdc0dd811722798530efffd736bfc2bc1d
treedfb84b599f86fae2d1c8655fde02e9619a493819
parent2cbb2408a830a63fbd901a4da3bfd341cec4b6ef
match.pd: Defer some CTZ/CLZ foldings until after ubsan pass for -fsanitize=builtin [PR115127]

As the following testcase shows, -fsanitize=builtin instruments the
builtins in the ubsan pass which is done shortly after going into
SSA, but if optimizations optimize the builtins away before that,
nothing is instrumented.  Now, I think it is just fine if the
result of the builtins isn't used in any way and we just DCE them,
but in the following optimizations the result is used.
So, the following patch for -fsanitize=builtin only defers the
optimizations that might turn single argument CLZ/CTZ (aka undefined
at zero) until the ubsan pass is done.
Now, we don't have PROP_ubsan and am not sure it is worth adding it,
there is PROP_ssa set by the ssa pass which is 3 passes before
ubsan, but there are only 2 warning passes in between, so PROP_ssa
looked good enough to me.

2024-12-12  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/115127
* match.pd (clz (X) == C, ctz (X) == C, ctz (X) >= C): Don't
optimize if -fsanitize=builtin and not yet in SSA form.

* c-c++-common/ubsan/builtin-2.c: New test.
gcc/match.pd
gcc/testsuite/c-c++-common/ubsan/builtin-2.c [new file with mode: 0644]