summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Jambor <mjambor@suse.cz>2024-02-09 18:58:43 +0100
committerMartin Jambor <mjambor@suse.cz>2024-02-09 18:59:14 +0100
commit010e4a04c4daaf1b0dacf6aa30fcbdaa73eda33c (patch)
treed8d6315748d9012e3ec2b7d9408b9bf3637c9628
parent629157bfbca83ec040b7e83d82c9d74d74893d4b (diff)
sra: Disqualify bases of operands of asm gotos
PR 110422 shows that SRA can ICE assuming there is a single edge outgoing from a block terminated with an asm goto. We need that for BB-terminating statements so that any adjustments they make to the aggregates can be copied over to their replacements. Because we can't have that after ASM gotos, we need to punt. gcc/ChangeLog: 2024-01-17 Martin Jambor <mjambor@suse.cz> PR tree-optimization/110422 * tree-sra.c (scan_function): Disqualify bases of operands of asm gotos. gcc/testsuite/ChangeLog: 2024-01-17 Martin Jambor <mjambor@suse.cz> PR tree-optimization/110422 * gcc.dg/torture/pr110422.c: New test. (cherry picked from commit 2b7204c52392c1c0da9c91a5feae0c44018a6f37)
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr110422.c10
-rw-r--r--gcc/tree-sra.c29
2 files changed, 33 insertions, 6 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr110422.c b/gcc/testsuite/gcc.dg/torture/pr110422.c
new file mode 100644
index 00000000000..2e171a7a19e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110422.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+struct T { int x; };
+int foo(void) {
+ struct T v;
+ asm goto("" : "+r"(v.x) : : : lab);
+ return 0;
+lab:
+ return -5;
+}
diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index 5a1fc81d301..7ae0d10734b 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -1390,15 +1390,32 @@ scan_function (void)
gasm *asm_stmt = as_a <gasm *> (stmt);
walk_stmt_load_store_addr_ops (asm_stmt, NULL, NULL, NULL,
asm_visit_addr);
- for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++)
+ if (stmt_ends_bb_p (asm_stmt)
+ && !single_succ_p (gimple_bb (asm_stmt)))
{
- t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i));
- ret |= build_access_from_expr (t, asm_stmt, false);
+ for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++)
+ {
+ t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i));
+ disqualify_base_of_expr (t, "OP of asm goto.");
+ }
+ for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
+ {
+ t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
+ disqualify_base_of_expr (t, "OP of asm goto.");
+ }
}
- for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
+ else
{
- t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
- ret |= build_access_from_expr (t, asm_stmt, true);
+ for (i = 0; i < gimple_asm_ninputs (asm_stmt); i++)
+ {
+ t = TREE_VALUE (gimple_asm_input_op (asm_stmt, i));
+ ret |= build_access_from_expr (t, asm_stmt, false);
+ }
+ for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
+ {
+ t = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
+ ret |= build_access_from_expr (t, asm_stmt, true);
+ }
}
}
break;