ICE extracted from a real project: $ cat bug.cpp #include <atomic> bool bug(std::atomic<unsigned> & ready, unsigned u) { return (ready.fetch_and(~u) & u); } $ g++-12.0.0 -Ofast -c bug.cpp during GIMPLE pass: fab bug.cpp: In function 'bool bug(std::atomic<unsigned int>&, unsigned int)': bug.cpp:6:6: internal compiler error: gimple check: expected gimple_assign(error_mark), have gimple_nop() in gimple_assign_rhs_code, at gimple.h:2852 6 | bool bug(std::atomic<unsigned> & ready, unsigned u) { | ^~~ 0x20a58f7 internal_error(char const*, ...) ???:0 0x7c76dd gimple_check_failed(gimple const*, char const*, int, char const*, gimple_code, tree_code) ???:0 $ g++-12.0.0 -v Using built-in specs. COLLECT_GCC=/nix/store/3x3yy5hhikzn8zvhq5fj14a2m9qyxbc8-gcc-12.0.0/bin/g++ COLLECT_LTO_WRAPPER=/nix/store/3x3yy5hhikzn8zvhq5fj14a2m9qyxbc8-gcc-12.0.0/libexec/gcc/x86_64-unknown-linux-gnu/12.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.0.0 20211212 (experimental) (GCC)
Confirmed, started with r12-5486-g7df89377a7ae3906.
Confirmed. C testcase: int bug(unsigned *ready, unsigned u) { return __atomic_fetch_and (ready, ~u, 0) & u; }
Mine.
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>: https://gcc.gnu.org/g:a2a0c91b47537b16908981e206f4e42db8425eca commit r12-5981-ga2a0c91b47537b16908981e206f4e42db8425eca Author: liuhongt <hongtao.liu@intel.com> Date: Tue Dec 14 09:47:08 2021 +0800 Fix ICE. [PR103682] Check is_gimple_assign before gimple_assign_rhs_code. gcc/ChangeLog: PR target/103682 * tree-ssa-ccp.c (optimize_atomic_bit_test_and): Check is_gimple_assign before gimple_assign_rhs_code. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr103682.c: New test.
Fixed in GCC12.
.