From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 091FA3858D39; Sun, 26 Dec 2021 16:53:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 091FA3858D39 From: "fxcoudert at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/103828] Type generated for CHARACTER(C_CHAR), VALUE arguments is wrong Date: Sun, 26 Dec 2021 16:53:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: ABI, testsuite-fail, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: fxcoudert at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Dec 2021 16:53:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103828 --- Comment #2 from Francois-Xavier Coudert = --- So, even modifying gfc_sym_type() in trans-types.c to emit the proper type = does not fix the issue. Why? Because the rug is pulled under our feet later. Tur= ns out there is a function that deals with this, much later in the front-end: gfc_conv_scalar_char_value() But that function is really wrong. It's called in generate_local_decl(), wh= ich says: /* Modify the tree type for scalar character dummy arguments of bind= (c) procedures if they are passed by value. The tree type for them wi= ll be promoted to INTEGER_TYPE for the middle end, which appears to be what C would do with characters passed by-value. The value attrib= ute implies the dummy is a scalar. */ and gfc_conv_scalar_char_value() does this: /* This becomes the nominal_type in function.c:assign_parm_find_data_types. */ TREE_TYPE (sym->backend_decl) =3D unsigned_char_type_node; /* This becomes the passed_type in function.c:assign_parm_find_data_types. C promotes char to integer for argument passing. */ DECL_ARG_TYPE (sym->backend_decl) =3D unsigned_type_node; But this is completely wrong. In C, `char` arguments are only promoted to `= int` when the destination type is unknown, i.e., in unprototyped functions (K&R style) or variadic arguments. C interoperability only interoperates with prototyped C functions, so this promotion should not happen, and `char` sho= uld be passed as `char`! I am attaching the patch under testing.=