This avoids initializating "uninitialized" hardregs like SP. Bootstrap / regtest pending on x86_64-unknown-linux-gnu.
2021-10-04 Richard Biener <rguent...@suse.de> * gimplify.c (is_var_need_auto_init): DECL_HARD_REGISTER variables are not to be initialized. * gcc.dg/auto-init-hardreg-1.c: New testcase. --- gcc/gimplify.c | 2 ++ gcc/testsuite/gcc.dg/auto-init-hardreg-1.c | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/auto-init-hardreg-1.c diff --git a/gcc/gimplify.c b/gcc/gimplify.c index f4bc649632e..b27776af7c8 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1825,6 +1825,8 @@ static bool is_var_need_auto_init (tree decl) { if (auto_var_p (decl) + && (TREE_CODE (decl) != VAR_DECL + || !DECL_HARD_REGISTER (decl)) && (flag_auto_var_init > AUTO_INIT_UNINITIALIZED) && (!lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))) && !is_empty_type (TREE_TYPE (decl))) diff --git a/gcc/testsuite/gcc.dg/auto-init-hardreg-1.c b/gcc/testsuite/gcc.dg/auto-init-hardreg-1.c new file mode 100644 index 00000000000..7c9de99bf05 --- /dev/null +++ b/gcc/testsuite/gcc.dg/auto-init-hardreg-1.c @@ -0,0 +1,9 @@ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-options "-ftrivial-auto-var-init=zero" } */ + +int +main () +{ + register long *sp __asm__("sp"); + return 0; +} -- 2.31.1