https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107339
Bug ID: 107339 Summary: RISC V -mstrict-align Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: yy172179 at 163 dot com Target Milestone: --- When I use GCC12 to compile the files with - march=rv32imac - mabi=ilp32 - mstrict align - c option,then objdump it.I found that the assembly code will use “LW” instruction to access Non aligned address. Causing hardware errors。 Here's an example #include<stdio.h> typedef struct __attribute__((packed)) misalign { uint8_t rseq[16]; uint8_t type; uint8_t cnt; } misalign_t; void tttt (misalign_t* t){ printf("%x\n",(*(const uint32_t*)&t->rseq[0])); printf("%x\n",(*(const uint32_t*)&t->rseq[1])); } int main() { misalign_t abc; misalign_t *test=&abc; tttt(test); while(1); } What compilation options or settings can I use to avoid this situation, or is this a bug??