From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3D3CD38582B0; Fri, 24 Feb 2023 01:13:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D3CD38582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677201205; bh=YSaUf3L53dmPX33Q3pGBKDXiM5XQ1XrTqJdAZcKdLtM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TiGUZP1VhuYWwH6yWtiTsXJVVW2K1NQJVyHpqgOY4Z9i20aW/DS9Vj29b7Eywbekh o+2SdCh4Z6ckvzDsPEa9CRdlWJiDi1Jk+NlKpiN+iIzHCF11qPVr8cYyWT0G8UrUqi RLxyjLZf5EuKniTI3FLmEjnR4t+DzznHIIjl4gRU= From: "ibuclaw at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug d/106977] [13 regression] d21 dies with SIGBUS on 32-bit Darwin Date: Fri, 24 Feb 2023 01:13:21 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: d X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: ibuclaw at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: ibuclaw at gdcproject dot org X-Bugzilla-Target-Milestone: 13.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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=3D106977 --- Comment #20 from ibuclaw at gcc dot gnu.org --- (In reply to Andrew Pinski from comment #19) > (In reply to Andrew Pinski from comment #18) > > > I think the visibility type is POD (assuming D has that concept) >=20 > At least the front-end does. > See dmd/dstruct.d:443 >=20 > if isPOD return false, TREE_ADDRESSABLE is set on the struct. > I have not gone through the code otherwise. See d/decl.cc:950 It's not TREE_ADDRESSABLE, but on 32-bit the struct is considered to be 'aggregate_value_p', which in turn sets up return by hidden reference. This effects how the return is handled later (around toir.cc:1044), which splits up the init and return expression. Returning this way I guess is fi= ne for extern(D) functions, however we should not be so eager to do rvo/sret f= or other extern language functions. Having a quick look at C++ front-end, they require both `aggregate_value_p`= and for a named variable to be in the return expression. ``` if (current_function_return_value) { tree r =3D current_function_return_value; tree outer; if (r !=3D error_mark_node /* This is only worth doing for fns that return in memory--and simpler, since we don't have to worry about promoted modes. */ && aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl)), fndecl) ``` So for the current gate in D: ``` if (TREE_ADDRESSABLE (TREE_TYPE (resdecl)) || aggregate_value_p (TREE_TYPE (resdecl), fndecl)) ``` I think tightening that to (its late, and my parentheses may be wrong). ``` if (TREE_ADDRESSABLE (TREE_TYPE (resdecl)) || ((d->resolvedLinkage () =3D=3D LINK::d || (d->resolvedLinkage () =3D=3D LINK::cpp && d->nrvo_var)) && aggregate_value_p (TREE_TYPE (resdecl), fndecl))) ``` Which is: 1. TREE_ADDRESSABLE 2. extern(D) and aggregate_value_p 3. extern(C++) and have NVRO variable and aggregate_value_p I guess for extern(C) functions we should just forget even attempting to do= any (N)RVO/SRET returns and let tree-nrv.cc decide whether to optimize or not.=