This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/81273] Wrong code generated for ARM setting volatile struct field with a literal
- From: "ldeboer at gateway dot net.au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 03 Jul 2017 14:09:58 +0000
- Subject: [Bug target/81273] Wrong code generated for ARM setting volatile struct field with a literal
- Auto-submitted: auto-generated
- References: <bug-81273-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81273
--- Comment #3 from LdB <ldeboer at gateway dot net.au> ---
I am stunned you could not build the code the only requirement is you include
the stdint.h so the uint32_t types are defined. I will fix the typos are you
really saying you can't compile this?
#include <stdint.h>
struct __attribute__((__packed__)) TimerRegisters {
volatile uint32_t Load; //0x00
volatile uint32_t Value; //0x04
};
uint32_t base_addr = 0x3F000000;
#define TIMER ((struct TimerRegisters*)(base_addr + 0xB400))
void ShowBug (void){
TIMER->Load = 0x400; // -02 compile and look at code
}
void ShowFix1 (void){
*(volatile uint32_t*)TIMER->Load = 0x400;
}
void ShowFix2 (void){
volatile uint32_t temp = 0x400;
TIMER->Load = temp;
}
Alignment is not really a concern it's a hardware register to the CPU so it's a
given.