[Bug 1685385] Re: GCC generates bad code with zero length array and -O3

Launchpad Bug Tracker 1685385 at bugs.launchpad.net
Sun May 7 15:54:32 UTC 2017


This bug was fixed in the package gcc-6 - 6.3.0-16ubuntu6

---------------
gcc-6 (6.3.0-16ubuntu6) artful; urgency=medium

  * Update to SVN 20170506 (r247720) from the gcc-6-branch.
    - Fix PR target/77728 (ARM), PR target/68491 (x86), PR fortran/80392,
      PR libgomp/80394, PR c/79940, PR c++/79572, PR c++/79641, PR c/80097,
      PR c++/79512, PR rtl-optimization/80501, PR sanitizer/80349,
      PR rtl-optimization/80385, PR libgomp/80394, PR c++/80297, PR debug/80321,
      PR target/80286 (x86), PR debug/79255, PR debug/80025, PR sanitizer/80168,
      PR rtl-optimization/80112, PR c++/80129, PR sanitizer/79944,
      PR target/79932 (x86), PR target/79932 (x86), PR c/79940,
      PR rtl-optimization/79901, PR target/79807 (x86), PR c++/79681,
      PR target/79729 (x86), PR middle-end/79396, PR target/79570,
      PR target/79494 (x86), PR target/79568 (x86), PR target/79559 (x86),
      PR c++/80363, PR c++/80176, PR c++/79572, PR c++/80141, PR c++/79896,
      PR c++/79664, PR c++/79639, PR c++/79512.
  * Fix dependency on gcc-base package for rtlibs stage build (Helmut Grohne).
  * Remove libquadmath/gdtoa license from debian/copyright (files removed).
  * Stop building packages now built by the gcc-7 source.
  * Fix PR rtl-optimization/60818, taken from the trunk (Adrian Glaubitz).
    Closes: #861945.
  * Fix building libgfortran, libgphobos and libmpx when building without
    common libs.

 -- Matthias Klose <doko at ubuntu.com>  Sun, 07 May 2017 09:21:42 +0200

** Changed in: gcc-6 (Ubuntu)
       Status: New => Fix Released

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-5 in Ubuntu.
https://bugs.launchpad.net/bugs/1685385

Title:
  GCC generates bad code with zero length array and -O3

Status in gcc:
  In Progress
Status in gcc-5 package in Ubuntu:
  New
Status in gcc-6 package in Ubuntu:
  Fix Released

Bug description:
  With the program below, if I compile it with '-O3 -DFLEX' I get good code but if I compile it with '-O3 -UFLEX' then I get bad code.  The program is (unfortunately) not runnable but if you generate
  assembly language you can see that the good version has a loop with ldr/str/ldr/str and the bad
  version has a loop with ldr/ldr/str/str.  I.e. the second load has been moved to be before the first store and if they are referencing the same memory that will result in incorrect behavior.

  It is unclear to me why declaring the array 'o' at the end of struct 's' as a zero length array
  instead of a C99 flexible array would affect the code generation but it does.  The version with
  the flexible array works, the version with a zero length array does not work (i.e. it moves the
  second load up to before the first store).

  Test case (compile with -O3 and either -DFLEX or -UFLEX):

  struct q {
  	int b;
  };
  struct r {
     int n;
     struct q slot[0];
  };
  struct s {
     int n;
  #ifdef FLEX
   long int o[];
  #else
   long int o[0];
  #endif
  };
  extern int x, y, m;
  extern struct s *a;
  extern struct r *b;
  extern void bar();
  int foo() {
     int i,j;
     for (i = 0; i < m; i++) {
     	a->o[i] = sizeof(*a);
     	b = ((struct r *)(((char *)a) + a->o[a->n]));
  	for (j = 0; j < 10; j++) {
  		b->slot[j].b = 0;
     	}
          bar();
    }
  }

  ProblemType: Bug
  DistroRelease: Ubuntu 16.04
  Package: gcc 4:5.3.1-1ubuntu1
  Uname: Linux 4.10.0-rc2-00045-g2748079 aarch64
  ApportVersion: 2.20.1-0ubuntu2.5
  Architecture: arm64
  Date: Fri Apr 21 16:07:53 2017
  JournalErrors:
   Error: command ['journalctl', '-b', '--priority=warning', '--lines=1000'] failed with exit code 1: Failed to search journal ACL: Operation not supported
   No journal files were opened due to insufficient permissions.
  ProcEnviron:
   TERM=xterm-256color
   PATH=(custom, no user)
   XDG_RUNTIME_DIR=<set>
   LANG=en_US.UTF-8
   SHELL=/bin/bash
  SourcePackage: gcc-defaults
  UpgradeStatus: No upgrade log present (probably fresh install)

To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc/+bug/1685385/+subscriptions



More information about the foundations-bugs mailing list