[Bug tree-optimization/65918] Optimized code ( -O0) on 2-dim array iteration incorrect

2015-04-28 Thread habanero_pizza at yahoo dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65918

J. W. Mitchell habanero_pizza at yahoo dot com changed:

   What|Removed |Added

 CC||habanero_pizza at yahoo dot com

--- Comment #1 from J. W. Mitchell habanero_pizza at yahoo dot com ---
Created attachment 35414
  -- https://gcc.gnu.org/bugzilla/attachment.cgi?id=35414action=edit
Preprocessed test case.


[Bug tree-optimization/65918] New: Optimized code ( -O0) on 2-dim array iteration incorrect

2015-04-28 Thread habanero_pizza at yahoo dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65918

Bug ID: 65918
   Summary: Optimized code ( -O0) on 2-dim array iteration
incorrect
   Product: gcc
   Version: 5.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: habanero_pizza at yahoo dot com
  Target Milestone: ---
  Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
 Build: i686-pc-linux-gnu

Created attachment 35413
  -- https://gcc.gnu.org/bugzilla/attachment.cgi?id=35413action=edit
Test case source:  execution fails if OKAY is not defined...

When the following function is compiled with gcc 4.8.3, 4.9.2, or 5.1.0, it
only executes properly when no optimization is specified (-O0):

int f(int value, int type)
{
static const int limits[2][3] = {
{ 400, 480, 512 },
{ 460, 492, 500 }
};

int retval = 0;

while ((value  limits[type][retval])  (retval  3)) {
retval++;
}

return retval;
}

The problem is in the case where retval should be 3; for example, if value is
550 and type is 0, the retval should be 3, but the function will return 2.  For
cases where the function is supposed to return 0, 1, or 2, it does work
correctly.

However, if gcc 4.6.4 or gcc 4.7.2 is used, it works correctly with and without
optimization.

If the loop is changed to use an array of a single dimension, the problem is
also eliminated (4.8, 4.9, 5.1):

const int *limit = limits[type];

while ((value  limit[retval])  (retval  3)) {
retval++;
}

I have also confirmed that the problem appears for x86_64 and ARM
architectures.

See attached file (test-opt-2-dim-array-iter.c) for further information.

Compilation details:

Using built-in specs.
COLLECT_GCC=i386-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../../gcc-5.1.0/configure --prefix=/usr/local/i386-eabi-5.1.0
--program-prefix=i386-eabi- --enable-languages=c,c++
--with-gmp=/usr/local/i386-eabi-5.1.0 --with-mpfr=/usr/local/i386-eabi-5.1.0
--with-mpc=/usr/local/i386-eabi-5.1.0 --with-isl=/usr/local/i386-eabi-5.1.0
--with-zlib=/usr/local --enable-lto --enable-gold
Thread model: posix
gcc version 5.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-O1' '-v' '-save-temps' '-o' 'test-opt-2-dim-array-iter'
'-mtune=generic' '-march=pentiumpro'
 /usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/cc1 -E -quiet
-v test-opt-2-dim-array-iter.c -mtune=generic -march=pentiumpro -O1
-fpch-preprocess -o test-opt-2-dim-array-iter.i
ignoring nonexistent directory
/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../i686-pc-linux-gnu/include
#include ... search starts here:
#include ... search starts here:
 /usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/include
 /usr/local/include
 /usr/local/i386-eabi-5.1.0/include
 /usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-O1' '-v' '-save-temps' '-o' 'test-opt-2-dim-array-iter'
'-mtune=generic' '-march=pentiumpro'
 /usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/cc1
-fpreprocessed test-opt-2-dim-array-iter.i -quiet -dumpbase
test-opt-2-dim-array-iter.c -mtune=generic -march=pentiumpro -auxbase
test-opt-2-dim-array-iter -O1 -version -o test-opt-2-dim-array-iter.s
GNU C11 (GCC) version 5.1.0 (i686-pc-linux-gnu)
compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2,
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C11 (GCC) version 5.1.0 (i686-pc-linux-gnu)
compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2,
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d06407f4e6fff3c174315d9bcdf98d85
COLLECT_GCC_OPTIONS='-O1' '-v' '-save-temps' '-o' 'test-opt-2-dim-array-iter'
'-mtune=generic' '-march=pentiumpro'

/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../i686-pc-linux-gnu/bin/as
-v --32 -o test-opt-2-dim-array-iter.o test-opt-2-dim-array-iter.s
GNU assembler version 2.25 (i686-pc-linux-gnu) using BFD version (GNU Binutils)
2.25
COMPILER_PATH=/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../i686-pc-linux-gnu/bin/
LIBRARY_PATH=/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/:/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS

[Bug tree-optimization/65918] Optimized code ( -O0) on 2-dim array iteration incorrect

2015-04-28 Thread habanero_pizza at yahoo dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65918

--- Comment #3 from J. W. Mitchell habanero_pizza at yahoo dot com ---
Indeed.  Apologies for the submission


[Bug c++/65880] New: Member function issue with argument pointer to const array of member function pointers

2015-04-24 Thread habanero_pizza at yahoo dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65880

Bug ID: 65880
   Summary: Member function issue with argument pointer to const
array of member function pointers
   Product: gcc
   Version: 5.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: habanero_pizza at yahoo dot com
CC: habanero_pizza at yahoo dot com
  Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
 Build: i686-pc-linux-gnu

Created attachment 35396
  -- https://gcc.gnu.org/bugzilla/attachment.cgi?id=35396action=edit
Test case source:  fails if OKAY is not defined...

When a member function takes an argument of the form:

  type (classname::* const *ptr)(void)

AND the implementation of the function appears BEFORE its reference by another
member function, the compiler believes (at reference time) that the argument
type should be:

  type (classname::* *ptr)(void)

That is, the const seems to get dropped from the declaration.  However, if
the implementation of the function appears AFTER references by other member
functions, the code compiles correctly.

This seems to be a new issue with gcc 5.1.0, as 4.9.2 compiles the problem case
properly.

Example run demonstrating the problem:

$ i386-eabi-g++ -v -save-temps -o test-const-mfp-table-arg
test-const-mfp-table-arg.cc
Using built-in specs.
COLLECT_GCC=i386-eabi-g++
COLLECT_LTO_WRAPPER=/usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1
.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../../gcc-5.1.0/configure --prefix=/usr/local/i386-eabi-5.1.0
-
-program-prefix=i386-eabi- --enable-languages=c,c++
--with-gmp=/usr/local/i386-e
abi-5.1.0 --with-mpfr=/usr/local/i386-eabi-5.1.0
--with-mpc=/usr/local/i386-eabi
-5.1.0 --with-isl=/usr/local/i386-eabi-5.1.0 --with-zlib=/usr/local
--enable-lto
 --enable-gold
Thread model: posix
gcc version 5.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'test-const-mfp-table-arg'
'-shared-
libgcc' '-mtune=generic' '-march=pentiumpro'
 /usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/cc1plus -E
-quie
t -v -D_GNU_SOURCE test-const-mfp-table-arg.cc -mtune=generic -march=pentiumpro 
-fpch-preprocess -o test-const-mfp-table-arg.ii
ignoring nonexistent directory
/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux
-gnu/5.1.0/../../../../i686-pc-linux-gnu/include
#include ... search starts here:
#include ... search starts here:

/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../include/
c++/5.1.0

/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../include/
c++/5.1.0/i686-pc-linux-gnu

/usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/../../../../include/
c++/5.1.0/backward
 /usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/include
 /usr/local/include
 /usr/local/i386-eabi-5.1.0/include
 /usr/local/i386-eabi-5.1.0/lib/gcc/i686-pc-linux-gnu/5.1.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'test-const-mfp-table-arg'
'-shared-
libgcc' '-mtune=generic' '-march=pentiumpro'
 /usr/local/i386-eabi-5.1.0/libexec/gcc/i686-pc-linux-gnu/5.1.0/cc1plus
-fprepro
cessed test-const-mfp-table-arg.ii -quiet -dumpbase test-const-mfp-table-arg.cc 
-mtune=generic -march=pentiumpro -auxbase test-const-mfp-table-arg -version -o
t
est-const-mfp-table-arg.s
GNU C++ (GCC) version 5.1.0 (i686-pc-linux-gnu)
compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2, 
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) version 5.1.0 (i686-pc-linux-gnu)
compiled by GNU C version 5.1.0, GMP version 5.1.3, MPFR version 3.1.2, 
MPC version 1.0.3
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8a9e49c211f4d1d2fc149d62c24d84d4
test-const-mfp-table-arg.cc: In member function ‘bool Test::barl()’:
test-const-mfp-table-arg.cc:67:20: error: invalid conversion from ‘bool
(Test::*
 const*)()’ to ‘bool (Test::**)()’ [-fpermissive]
 return fool(fms);
^
test-const-mfp-table-arg.cc:40:6: note:   initializing argument 1 of ‘bool
Test:
:fool(bool (Test::**)())’
 bool Test::fool(bool (Test::* const *fms)(void))
  ^

Preprocessor output (test-const-mfp-table-arg.ii):

# 1 test-const-mfp-table-arg.cc
# 1 built-in
# 1 command-line
# 1 test-const-mfp-table-arg.cc


class Test
{
  public:
Test();
~Test();

bool barl(void);

  private:
bool fool(bool (Test::* const *fms)(void));
bool foo(void);
bool bar(void);
};

Test::Test()
{
}

Test::~Test()
{
}
# 40 test-const-mfp-table-arg.cc
bool Test::fool(bool (Test::* const *fms)(void))
{
bool retval = false;

int i = 0;
bool (Test::*f)(void) = fms[i++];

while (f) {
retval = (this-*f