public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/46192] New: renaming of a volatile variable generates wrong code
@ 2010-10-26 22:32 rolf.ebert.gcc at gmx dot de
  2010-10-26 22:40 ` [Bug ada/46192] " rolf.ebert.gcc at gmx dot de
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: rolf.ebert.gcc at gmx dot de @ 2010-10-26 22:32 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: renaming of a volatile variable generates wrong code
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rolf.ebert.gcc@gmx.de
            Target: avr


The following Ada code is translated to wrong assembler when using the renamed
variable.

with Interfaces;  use Interfaces;
package Renaming is

   procedure Put_Raw;

end Renaming;

with System;    use System;

package body Renaming is

   type Bit_Number is new Unsigned_8 range 0 .. 7;

   --  Give access to every single bit in a byte as a boolean.
   type Bits_In_Byte is array (Bit_Number) of Boolean;
   pragma Pack (Bits_In_Byte);
   for Bits_In_Byte'Size use 8;

   --  USART Control and Status Register A
   UCSR0A_Addr    : constant Address    := System'To_Address(16#c0#);
   UCSR0A_Bits    : Bits_In_Byte;
   for UCSR0A_Bits'Address use UCSR0A_Addr;
   pragma Volatile (UCSR0A_Bits);

   UCSRA_Bits : Bits_In_Byte renames UCSR0A_Bits;

   procedure Put_Raw is
   begin
      -- wait until Data Register Empty (DRE) is signaled
      while UCSRA_Bits (5) = False loop null; end loop;
   end Put_Raw;

end Renaming;

$ avr-gcc -S -mmcu=atmega328p -Os renaming.adb

.global renaming__put_raw
        .type   renaming__put_raw, @function
renaming__put_raw:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
        lds r24,192
        sbrs r24,5
.L5:
        rjmp .L5
.L4:
        ret
        .size   renaming__put_raw, .-renaming__put_raw

See the placement of the label .L5

If you don't use the renamed variable but directly UCSR0A_Bits as in 
      while UCSR0A_Bits (5) = False loop null; end loop;
you get correct assembler code:

.global renaming__put_raw
        .type   renaming__put_raw, @function
renaming__put_raw:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
.L3:
        lds r24,192
        sbrs r24,5
        rjmp .L3
/* epilogue start */
        ret
        .size   renaming__put_raw, .-renaming__put_raw


Rolf


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

end of thread, other threads:[~2012-01-21 15:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-26 22:32 [Bug ada/46192] New: renaming of a volatile variable generates wrong code rolf.ebert.gcc at gmx dot de
2010-10-26 22:40 ` [Bug ada/46192] " rolf.ebert.gcc at gmx dot de
2011-02-11 18:14 ` simon at pushface dot org
2011-02-11 18:20 ` simon at pushface dot org
2012-01-16 22:18 ` rolf.ebert.gcc at gmx dot de
2012-01-20 16:09 ` [Bug ada/46192] [4.5/4.6/4.7 regression] wrong code for renaming of packed array with address clause ebotcazou at gcc dot gnu.org
2012-01-20 16:24 ` ebotcazou at gcc dot gnu.org
2012-01-20 21:00 ` [Bug ada/46192] [4.5/4.6/4.7 regression] wrong code for renaming of volatile " jakub at gcc dot gnu.org
2012-01-21 15:07 ` ebotcazou at gcc dot gnu.org
2012-01-21 15:12 ` ebotcazou at gcc dot gnu.org
2012-01-21 15:25 ` ebotcazou at gcc dot gnu.org
2012-01-21 15:25 ` ebotcazou 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).