https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97205

--- Comment #4 from SRINATH PARVATHANENI <sripar01 at gcc dot gnu.org> ---
(In reply to Bernd Edlinger from comment #2)
> 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;
> +}

With the above patch I'm getting ICE as below while building arm-none-eabi
target:

checking for scalbnl... during RTL pass: expand

generice_bug/src/gcc/libstdc++-v3/src/c++98/locale_init.cc: In constructor
'std::locale::_Impl::_Impl(std::size_t)':

generice_bug/src/gcc/libstdc++-v3/src/c++98/locale_init.cc:471:3: internal
compiler error: tree check: expected bit_field_ref or mem_ref, have ssa_name in
expand_assignment, at expr.c:5203
  471 |   locale::_Impl::
      |   ^~~~~~

Reply via email to