]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix SRA issue with -ftrivial-auto-var-init= [PR121894]
authorQing Zhao <qing.zhao@oracle.com>
Thu, 18 Sep 2025 15:50:38 +0000 (15:50 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Thu, 18 Sep 2025 18:31:33 +0000 (18:31 +0000)
commitf613fdc6920c83658f033501fce1a1420e687d11
tree755b490465fbae4ff477706d6a02628c72732557
parentc52c745c98f846308ad18a6d49da541cebb0a8b3
Fix SRA issue with -ftrivial-auto-var-init= [PR121894]

In tree-sra.cc, for the following stmt (initialization in source code):
s = {};

for the above lhs "s", the field "grp_assignment_write" of the created
struct access is 1;

however, for the following stmt (compiler added initialization):
s = .DEFERRED_INIT (size, init_type, &"s"[0]);

for the above lhs "s", the field "grp_assignment_write" of the created
struct access is 0;

Since the field "grp_assignment_write" of the struct access for the
corresponding LHS "s" is not set correctly when the RHS is .DEFERRED_INIT,
SRA phase didn't do a correct transformation for call to .DEFERRED_INIT.

To fix this issue, we should set the field "grp_assignment_write" correctly
for .DEFERRED_INIT.

PR tree-optimization/121894

gcc/ChangeLog:

* tree-sra.cc (scan_function): Set grp_assignment_write to 1 when
specially handle call to .DEFERRED_INIT.

gcc/testsuite/ChangeLog:

* g++.dg/opt/auto-init-sra-pr121894.C: New test.
gcc/testsuite/g++.dg/opt/auto-init-sra-pr121894.C [new file with mode: 0644]
gcc/tree-sra.cc