From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4E84E3858C78; Mon, 4 Dec 2023 09:07:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E84E3858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701680867; bh=OorHA1FLx6Z0t1kkS+cBzrE0w+E+irCplg+zyoHx2c4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=x2PrGpQ45D5D7AOQCFwY/BoVCLQ5IcOuOUUts6tdaHWxV+3HyLDNiaJpW1NieJhmC Xk+C1lRNfYEAQD0yQMgqSfFdEK6R91mpPE6s+RNiglGWkuJf/FeQSaMljNfCmhxT8v 0Im6obxY8eYHgYhLWGwMgWDD3L4irMPRtfYaraiE= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/112830] internal compiler error: in convert_memory_address_addr_space_1, at explow.cc:302 Date: Mon, 04 Dec 2023 09:07:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: addr-space, ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: assigned_to bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112830 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot = gnu.org Status|NEW |ASSIGNED --- Comment #5 from Richard Biener --- Note we end up trying to expand a memcpy between different address spaces and that does addr =3D expand_expr (orig_exp, NULL_RTX, ptr_mode, EXPAND_NORMAL); mem =3D gen_rtx_MEM (BLKmode, memory_address (BLKmode, addr));=20 which assumes the default address-space. The get_memory_rtx () function also doesn't correctly preserve the address-space for the MEM_EXPR. The following fixes the ICE and tries to correct the MEM_EXPR. But I wonder if the actual code generation is sane? It also appears we'd eventually emit a call to memcpy as we call emit_block_move_hints with BLOCK_OP_NORMAL which sets may_use_call to 1. So, can you check whether we generate correct code with the following patch? Otherwise we should keep it ICEing (wrong-code is IMHO worse). diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 4fc58a0bda9..244863699be 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -1353,7 +1353,8 @@ get_memory_rtx (tree exp, tree len) exp =3D TREE_OPERAND (exp, 0); addr =3D expand_expr (orig_exp, NULL_RTX, ptr_mode, EXPAND_NORMAL); - mem =3D gen_rtx_MEM (BLKmode, memory_address (BLKmode, addr)); + addr_space_t as =3D TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp))); + mem =3D gen_rtx_MEM (BLKmode, memory_address_addr_space (BLKmode, addr, = as)); /* Get an expression we can use to find the attributes to assign to MEM. First remove any nops. */ @@ -1363,8 +1364,11 @@ get_memory_rtx (tree exp, tree len) /* Build a MEM_REF representing the whole accessed area as a byte blob, (as builtin stringops may alias with anything). */ + tree ctype =3D char_type_node; + if (as !=3D ADDR_SPACE_GENERIC) + ctype =3D build_qualified_type (ctype, ENCODE_QUAL_ADDR_SPACE (as)); exp =3D fold_build2 (MEM_REF, - build_array_type (char_type_node, + build_array_type (ctype, build_range_type (sizetype, size_one_node, len= )), exp, build_int_cst (ptr_type_node, 0)); @@ -1381,7 +1385,7 @@ get_memory_rtx (tree exp, tree len) unsigned int align =3D get_pointer_alignment (TREE_OPERAND (exp, 0)); exp =3D build_fold_addr_expr (base); exp =3D fold_build2 (MEM_REF, - build_array_type (char_type_node, + build_array_type (ctype, build_range_type (sizetype, size_zero_node, NULL)),=