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/25296] New: Const promotion not working correctly


I am an adamant user of const, as it helps checking the code with (by way of
the compiler) for stupid errors, helps with defining what is happening and
gives the compiler more help optimisation.

I had tried something that I think should have work as promoting a type to a
const type should be straight forward.  I?ve distilled the problem down to the
following two examples:

Example 1:

void myTestFn2(int * const array[4])
{
}

void myTestFn()
{
  int * array[4];
  myTestFn2(array);
}
--end of file?


This example works no problem.  From the eyes of myTestFn2() an array of
pointers to const ints are being received.  This means that myTestFn2() may not
change the *pointers* in the array passed.  From the eyes of myTestFn() it is
to pass to the myTestFn2() an array of int pointers and can expect that none of
the pointer are to have changed upon return.


Example 2:

void myTestFn2(int const * array[4])
{
}

void myTestFn()
{
  int * array[4];
  myTestFn2(array);
}
--end of file?


This is the offending example.  From the eyes of myTestFn2() an array of const
pointers to ints are being received.  This means that myTestFn2() may not
change the *ints* pointed at by the pointers in the array passed.  From the
eyes of myTestFn() it is to pass to myTestFn2() an array of int pointers and
can expect that the ints pointed at are *not* to have changed, though the
pointers may have changed to point at different ints.

This resulted in the following error on a cygwin compiler as well as a similar
error on a vxWorks gnu cross compiler.

test.c: In function `myTestFn':
test.c:8: warning: passing arg 1 of `myTestFn2' from incompatible pointer type
 /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/as.exe -o
test.o test.s


The following is from the cygwin gcc compiler command ?gcc -v -save-temps -c -o
test.o test.c?


Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose --prefix=/usr
--exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--enable-languages=c,ada,c++,d,f77,java,objc --enable-nls
--without-included-gettext --enable-version-specific-runtime-libs --without-x
--enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter
--disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm
--disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization
--enable-libstdcxx-debug : (reconfigured) 
Thread model: posix
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
 /usr/lib/gcc/i686-pc-cygwin/3.4.4/cc1.exe -E -quiet -v -D__CYGWIN32__
-D__CYGWIN__ -Dunix -D__unix__ -D__unix -idirafter
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/w32api -idirafter
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/../../include/w32api
test.c -mtune=pentiumpro -o test.i
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory
"/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/include"
ignoring duplicate directory
"/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i686-pc-cygwin/3.4.4/include
 /usr/include
 /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/w32api
End of search list.
 /usr/lib/gcc/i686-pc-cygwin/3.4.4/cc1.exe -fpreprocessed test.i -quiet
-dumpbase test.c -mtune=pentiumpro -auxbase-strip test.o -version -o test.s
GNU C version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
(i686-pc-cygwin)
        compiled by GNU C version 3.4.4 (cygming special) (gdc 0.12, using dmd
0.125).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
test.c: In function `myTestFn':
test.c:8: warning: passing arg 1 of `myTestFn2' from incompatible pointer type
 /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/as.exe -o
test.o test.s
--end of output--

The following is from the vxWorks cross compiler command ?ccppc -v -save-temps
-c -o test.o test.c?.

Reading specs from
c:/Tornado/T2.2/host/x86-win32/bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/specs
gcc version gcc-2.96 (2.96+) 19990621 AltiVec VxWorks 5.5

c:/Tornado/T2.2/host/x86-win32/bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/cpp.exe
-lang-c -v -iprefix
c:\Tornado\T2.2\host\x86-win32\bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/
-D__GNUC__=2 -D__GNUC_MINOR__=96 -D__vxworks -D__PPC__ -D__vxworks -D__PPC__
-Asystem(vxworks) -Asystem(embedded) -Acpu(powerpc) -Amachine(powerpc)
-D__CHAR_UNSIGNED__ -D_CALL_SYSV -D_BIG_ENDIAN -D__BIG_ENDIAN__
-Amachine(bigendian) -D_ARCH_PPC -DCPU=PPC603 test.c test.i
GNU CPP version gcc-2.96 (2.96+) 19990621 AltiVec VxWorks 5.5 (PowerPC System
V.4)
#include "..." search starts here:
#include <...> search starts here:

c:/Tornado/T2.2/host/x86-win32/bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/include

c:/Tornado/T2.2/host/x86-win32/bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/../../../../../../target/h

c:/Tornado/T2.2/host/x86-win32/bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/../../../../powerpc-wrs-vxworks/include
End of search list.
The following default directories have been omitted from the search path:

/wind/river/host/x86-win32/lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/../../../../include/g++-3
End of omitted list.

c:/Tornado/T2.2/host/x86-win32/bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/cc1.exe
test.i -quiet -dumpbase test.c -version -o test.s
GNU C version gcc-2.96 (2.96+) 19990621 AltiVec VxWorks 5.5
(powerpc-wrs-vxworks) compiled by GNU C version 2.95.3-5 (cygwin special).
test.c: In function `myTestFn':
test.c:8: warning: passing arg 1 of `myTestFn2' from incompatible pointer type

c:/Tornado/T2.2/host/x86-win32/bin/../lib/gcc-lib/powerpc-wrs-vxworks/gcc-2.96/../../../../powerpc-wrs-vxworks/bin/as.exe
-mppc -V -Qy -o test.o test.s
GNU assembler version 2.11.2-moto-1.7 (powerpc-wrs-vxworks) using BFD version
2.11.2-moto-1.7
--end of output--


-- 
           Summary: Const promotion not working correctly
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: adrian dot hawryluk at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25296


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