public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/48274] New: C frontend emit invalid promotions
@ 2011-03-24 14:24 matz at gcc dot gnu.org
  2011-03-24 14:34 ` [Bug c/48274] " joseph at codesourcery dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: matz at gcc dot gnu.org @ 2011-03-24 14:24 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48274

           Summary: C frontend emit invalid promotions
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: matz@gcc.gnu.org


This came up in the context of a stricter consistency checker for types in
our middle end.  I believe the C frontend emits invalid promotions for calls
to prototyped functions:

% cat x.c
unsigned passchar (char c);
unsigned passflt (float f);
unsigned passva (int i, ...);
char blachar (char c, float f)
{
  return passchar (c) + passflt (f) + passva(1, f);
}
% ./cc1 x.c -fdump-tree-original
% cat x.c.003t.original
;; Function blachar (null)
;; enabled by -tree-original
{
  return (char) (((unsigned char) passchar ((int) c) + (unsigned char) passflt
(f)) + (unsigned char) passva (1, (double) f));
}

The emitted code doesn't depend on the -std=xxx setting.  What I believe
is invalid here is the call to passchar().  First, it's a prototyped
function, hence 6.5.2.2 #7 is invoked:

#7: ... the arguments are implicitly converted, as if by assignment, to the
    types of the corresponding parameters, taking the type of each parameter
    to be the unqualified version of its declared type. The ellipsis notation
    ...

Hence, as if by assignment.  types of assignment expressions is that of the
left operand after lvalue conversions.  In this case the left operand is
the corresponding parameter (char c), hence I don't think there's much
leeway to read this as actually passing an 'int'.

This sort of looks as if the argument passer applies either default argument
promotions (6.5.2.2 #6, but that would mean it also had to promote the
float in passflt() call to double), or integer promotions (which would be
completely off) to arguments for calls to prototyped functions.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/48274] C frontend emit invalid promotions
  2011-03-24 14:24 [Bug c/48274] New: C frontend emit invalid promotions matz at gcc dot gnu.org
@ 2011-03-24 14:34 ` joseph at codesourcery dot com
  2011-03-24 15:02 ` matz at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: joseph at codesourcery dot com @ 2011-03-24 14:34 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48274

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2011-03-24 14:01:18 UTC ---
Does the target in question define TARGET_PROMOTE_PROTOTYPES to return 
true?  If so, the front end is behaving as requested by the target - while 
it would be better for this to be implemented as a lowering phase some 
time after the front end is finished, to the extent that the hook 
represents meaningful ABI or optimization information, that's not the 
internal interface at present.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/48274] C frontend emit invalid promotions
  2011-03-24 14:24 [Bug c/48274] New: C frontend emit invalid promotions matz at gcc dot gnu.org
  2011-03-24 14:34 ` [Bug c/48274] " joseph at codesourcery dot com
@ 2011-03-24 15:02 ` matz at gcc dot gnu.org
  2011-03-24 15:03 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: matz at gcc dot gnu.org @ 2011-03-24 15:02 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48274

--- Comment #2 from Michael Matz <matz at gcc dot gnu.org> 2011-03-24 14:51:08 UTC ---
It's x86_64-linux and indeed it does define that hook.  Like 19 other targets.
This is quite inconvenient.  The target should have a say in what instructions
are generated (as in influencing the setup of RTL call, and setup of arguments
in the callee, also at RTL), not on the types the middle end sees.  Sigh.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/48274] C frontend emit invalid promotions
  2011-03-24 14:24 [Bug c/48274] New: C frontend emit invalid promotions matz at gcc dot gnu.org
  2011-03-24 14:34 ` [Bug c/48274] " joseph at codesourcery dot com
  2011-03-24 15:02 ` matz at gcc dot gnu.org
@ 2011-03-24 15:03 ` rguenth at gcc dot gnu.org
  2011-03-24 15:13 ` rguenth at gcc dot gnu.org
  2021-07-19 22:28 ` [Bug c/48274] C frontend emit invalid promotions (TARGET_PROMOTE_PROTOTYPES ) pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-24 15:03 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48274

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.03.24 14:58:31
     Ever Confirmed|0                           |1

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-24 14:58:31 UTC ---
With similar promotions done to return values I got away by simply removing
the offending code from the FE ... there definitely _is_ code in backends
to influence argument passing at call expansion time and at least Fortran
doesn't seem to care for these hooks (which also means C interface Fortran
calls are "wrong").

So I suggest simply trying to remove this code from the FE ;)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/48274] C frontend emit invalid promotions
  2011-03-24 14:24 [Bug c/48274] New: C frontend emit invalid promotions matz at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-03-24 15:03 ` rguenth at gcc dot gnu.org
@ 2011-03-24 15:13 ` rguenth at gcc dot gnu.org
  2021-07-19 22:28 ` [Bug c/48274] C frontend emit invalid promotions (TARGET_PROMOTE_PROTOTYPES ) pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-24 15:13 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48274

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-24 15:00:23 UTC ---
FYI

2007-07-09  Richard Guenther  <rguenther@suse.de>

        * decl.c (start_preparsed_function): Do not promote return type.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/48274] C frontend emit invalid promotions (TARGET_PROMOTE_PROTOTYPES )
  2011-03-24 14:24 [Bug c/48274] New: C frontend emit invalid promotions matz at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-03-24 15:13 ` rguenth at gcc dot gnu.org
@ 2021-07-19 22:28 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-19 22:28 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2011-03-24 14:58:31         |2021-7-19
           Keywords|                            |missed-optimization
            Summary|C frontend emit invalid     |C frontend emit invalid
                   |promotions                  |promotions
                   |                            |(TARGET_PROMOTE_PROTOTYPES
                   |                            |)

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Still true today.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-19 22:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-24 14:24 [Bug c/48274] New: C frontend emit invalid promotions matz at gcc dot gnu.org
2011-03-24 14:34 ` [Bug c/48274] " joseph at codesourcery dot com
2011-03-24 15:02 ` matz at gcc dot gnu.org
2011-03-24 15:03 ` rguenth at gcc dot gnu.org
2011-03-24 15:13 ` rguenth at gcc dot gnu.org
2021-07-19 22:28 ` [Bug c/48274] C frontend emit invalid promotions (TARGET_PROMOTE_PROTOTYPES ) pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).