https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98499
--- Comment #3 from Sergei Trofimovich <slyfox at gcc dot gnu.org> --- `--param=modref-max-depth=0` makes the bug disappear. Looking at `-fdump-tree-all` the harmful optimization happens at `107.fre3` where: ``` if (&MEM[(struct string *)&D.2237 + 48B]._M_local_buf != _17) goto <bb 3>; [0.00%] else goto <bb 4>; [100.00%] <bb 3> [count: 0]: __builtin_trap (); ``` is converted into an unconditional `__builtin_trap ();`. `-fdump-tree-all-all` says it's a constant fold: ``` Value numbering stmt = if (&MEM[(struct string *)&D.2237 + 48B]._M_local_buf != _17) Applying pattern match.pd:4920, gimple-match.c:3373 marking known outgoing edge 2 -> 3 executable Block 1: BB4 found not executable ... ``` It looks like it's constant-folded into always-true instead of expected always-false. `match.pd:4920` is a `pta`: ``` /* Simplify pointer equality compares using PTA. */ (for neeq (ne eq) (simplify (neeq @0 @1) (if (POINTER_TYPE_P (TREE_TYPE (@0)) && ptrs_compare_unequal (@0, @1)) { constant_boolean_node (neeq != EQ_EXPR, type); }))) ``` `036t.ealias` and `043t.modref1` says `--param=modref-max-depth=0` has the effect on how many things escape from main(), but I don't understand the output.