This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/82340] New: volatile ignored in compound literal


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82340

            Bug ID: 82340
           Summary: volatile ignored in compound literal
           Product: gcc
           Version: 8.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: ---

Consider the function f below:

int f(void) {
  volatile char *p = (volatile char[1]){1};
  for (int i=1; i<10; i++) *p=4;
  return *p;
}

Volatile access is a visible side-effect, so one may expect the generated code
for the function f to do “something” nine times, for some definition of
“something”.

In GCC 7.2 and in gcc.godbolt.org's current snapshot of “gcc (trunk)”, the
function f is compiled to:

f:
        movl    $4, %eax
        ret

Command: gcc -O3 -std=c11 -xc -pedantic -S t.c
Link: https://godbolt.org/g/4Ua1Ud

I would expect function f to be compiled to something that ressembles the code
produced for function g, or the code produced by Clang for f:

int g(void) {
  volatile char t[1] = {1};
  volatile char *p = t;
  for (int i=1; i<10; i++) *p=4;
  return *p;
}

g:
        movb    $1, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movb    $4, -1(%rsp)
        movsbl  -1(%rsp), %eax
        ret

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]