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: [email protected]
ReportedBy: [email protected]
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