public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/53103] New: bug locating unsigned type for non-standard precision
@ 2012-04-24 15:50 bigotp at acm dot org
  2012-04-25 11:09 ` [Bug middle-end/53103] " rguenth at gcc dot gnu.org
  2024-02-16  6:03 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: bigotp at acm dot org @ 2012-04-24 15:50 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53103
           Summary: bug locating unsigned type for non-standard precision
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bigotp@acm.org


gcc segfaults with this code:

  typedef long int __attribute__((__a20__)) int20_t;
  int20_t xi;
  int20_t addit () { xi += 0x54321L; }

in a back end where xi ends up in mode PSImode which is a MODE_PARTIAL_INT
with 20 bits of precision and 32-bit width.

convert() notices that, because the constant in the add expression is
SImode, there's an SImode add being truncated to a PSImode result, and
pushes the truncation down into the operands.  This ends up in
convert_to_integer, which detects that the signed operation might overflow
so calls unsigned_type_for() to get the unsigned variant.

Unfortunately, this ends up in c_common_type_for_size(), which knows nothing
about PSImode, and returns an unsigned type with 32 bits of precision when
asked for one with 20 bits of precision.  The expression is rewritten with
the 32-bit constant integer recast to the 32-bit unsigned integer (instead
of the 20-bit one it might have used), and infinite recursion through
convert results.

Per http://gcc.gnu.org/ml/gcc/2012-04/msg00805.html, recommendation is to
abort the optimization if the required type is not selected.


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

* [Bug middle-end/53103] bug locating unsigned type for non-standard precision
  2012-04-24 15:50 [Bug middle-end/53103] New: bug locating unsigned type for non-standard precision bigotp at acm dot org
@ 2012-04-25 11:09 ` rguenth at gcc dot gnu.org
  2024-02-16  6:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-25 11:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-04-25
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-25 11:08:45 UTC ---
Confirmed.  All callers of type_for_size need to be audited for this case.


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

* [Bug middle-end/53103] bug locating unsigned type for non-standard precision
  2012-04-24 15:50 [Bug middle-end/53103] New: bug locating unsigned type for non-standard precision bigotp at acm dot org
  2012-04-25 11:09 ` [Bug middle-end/53103] " rguenth at gcc dot gnu.org
@ 2024-02-16  6:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-16  6:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.8.0

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
unsigned_type_for/signed_type_for was actally fixed on the trunk, a month
before this bug report was filed, by r0-115650-g7ee6fd6836b487 .

I tested:
```
  __int24 xi;
  __int24 addit () { xi += 0x54321L; }
```

On AVR and it has worked at least since GCC 5 when __int24 was added.

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

end of thread, other threads:[~2024-02-16  6:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-24 15:50 [Bug middle-end/53103] New: bug locating unsigned type for non-standard precision bigotp at acm dot org
2012-04-25 11:09 ` [Bug middle-end/53103] " rguenth at gcc dot gnu.org
2024-02-16  6:03 ` 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).