https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121427
Bug ID: 121427
Summary: For some structs, GCC ignores the volatile qualifier
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pascal_cuoq at hotmail dot com
Target Milestone: ---
This is most similar to but different from
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45852
When presented with the code below, GCC 15.1 generates an empty function for
f3.
volatile struct s3 { char i[3]; } s3;
volatile struct s2 { char i[2]; } s2;
void f2(void) {
s2;
}
void f3(void) {
s3;
}
Compiler Explorer link: https://gcc.godbolt.org/z/8Kr83Wjvs
I would expect GCC to generate assembly instructions that access each of the
bytes of the members of s3 once. Tons of ambiguity remain in presence of
padding, but at least Clang generates a 16-bit move and a 8-bit move for f3,
which seems reasonable.