https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128002
liu zhenyu <lzy20000419 at outlook dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lzy20000419 at outlook dot com
--- Comment #2 from liu zhenyu <lzy20000419 at outlook dot com> ---
The rewrite is in sanitize_rewrite_addressable_params. A parameter that already
has a DECL_VALUE_EXPR (here FRAME.0.x from tree-nested.cc) is skipped, but only
after TREE_ADDRESSABLE has been cleared and has_any_addressable_param has been
set. rewrite_usage_of_param then replaces every PARM_DECL with
DECL_HAS_VALUE_EXPR_P, including that skipped x. So the entry copy `_6 = x;
FRAME.0.x = _6;` becomes `_6 = FRAME.0.x;` and reads the uninitialized frame
slot.
The same happens with a second addressable parameter next to it. This also
aborts at -O0 -fsanitize=address on trunk 17.0.0 20261126 and on 14.2.0; -O0
and -O1/-O2 -fsanitize=address are fine:
__attribute__((noipa)) int f (int x, int y)
{
int *p = &x, *q = &y;
int get (void) { return x * 10; }
return *p + *q + get ();
}
int main (void) { if (f (1, 2) != 13) __builtin_abort (); }
Checking DECL_HAS_VALUE_EXPR_P in the initial addressable test, and having
rewrite_usage_of_param only touch the parameters that were actually rewritten,
fixes both testcases on 14.2. Checking only in the walker is not enough:
TREE_ADDRESSABLE has already been cleared, and verify_ssa then fails.
Disclaimer: This test case was found with LLM-assisted targeted testing, and
the comment was written with LLM assistance.