https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97205
--- Comment #2 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
Thanks for reporting this.
The expansion of assignments to misaligned ssa names
does not handle the case of misaligned stores, which
would result in incorrect code without the assertion.
I have an untested patch below:
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 3706f0a..12b81cd 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -2089,7 +2089,8 @@ set_mem_attributes_minus_bitpos (rtx ref, tree t, int
objectp,
{
gcc_assert (handled_component_p (t)
|| TREE_CODE (t) == MEM_REF
- || TREE_CODE (t) == TARGET_MEM_REF);
+ || TREE_CODE (t) == TARGET_MEM_REF
+ || TREE_CODE (t) == SSA_NAME);
attrs.expr = t;
attrs.offset_known_p = true;
attrs.offset = 0;
diff --git a/gcc/expr.c b/gcc/expr.c
index 9d951e8..49f2699 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -5200,6 +5200,9 @@ expand_assignment (tree to, tree from, bool nontemporal)
|| (TREE_CODE (to) == MEM_REF
&& (REF_REVERSE_STORAGE_ORDER (to)
|| mem_ref_refers_to_non_mem_p (to)))
+ || (TREE_CODE (to) == SSA_NAME
+ && mode != BLKmode
+ && TYPE_ALIGN (TREE_TYPE (to)) < GET_MODE_ALIGNMENT (mode))
|| TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
{
machine_mode mode1;
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr97205.c
b/gcc/testsuite/gcc.c-torture/compile/pr97205.c
new file mode 100644
index 0000000..6600011
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr97205.c
@@ -0,0 +1,7 @@
+int a;
+typedef __attribute__((aligned(2))) int x;
+int f ()
+{
+ x b = a;
+ return b;
+}