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 tree-optimization/82697] New: Wrong optimization with aliasing and "if"


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

            Bug ID: 82697
           Summary: Wrong optimization with aliasing and "if"
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ch3root at openwall dot com
  Target Milestone: ---

A testcase is simplified from
https://stackoverflow.com/questions/46592132/is-this-use-of-the-effective-type-rule-strictly-conforming
:

----------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

__attribute__((__noinline__))
void test(int *pi, long *pl, int f)
{
  *pl = 0;

  *pi = 1;

  if (f)
    *pl = 2;
}

int main(void)
{
  void *p = malloc(10);

  test(p, p, 0);

  printf("%d\n", *(int *)p);
}
----------------------------------------------------------------------

Results:

----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out
1
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out
0
----------------------------------------------------------------------

gcc version: gcc (GCC) 8.0.0 20171024 (experimental)

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