[Bug c/42476] New: "warning: will never be executed" about code which is executed with "-Wunreachable-code"

2009-12-23 Thread agraf at znc dot in
Compiling the following code snippet:

int main(int argc, char **argv)
{
int i;
int asize = 3;
int array[3];

for (i = asize - 1; i < asize; i++)
array[i] = 42;

for (i = 0; i < asize; i++)
printf("%i\n", array[i]);
}

with "gcc -O -Wunreachable-code gccbug.c" shows the following warning message:

gccbug.c: In function 'main':
gccbug.c:8: warning: will never be executed

(Where line 8 is the body of the first for-loop, array[i] = 42;)

Though, array[2] is set to 42, as the later printf shows when executing.

When replacing the "- 1" of line 7 with an higher value, e.g. "- 2", the
warning disappears. Not passing "-O" to the compiler lets the warning
disappear, too.

I tested it with two versions of gcc. The first:
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.3.4/work/gcc-4.3.4/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.3.4
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.4
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.4/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.4/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --enable-nls --without-included-gettext
--with-system-zlib --disable-checking --disable-werror --enable-secureplt
--enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp
--disable-libgcj --enable-languages=c,c++,treelang,fortran --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.3.4 p1.0,
pie-10.1.5'
Thread model: posix
gcc version 4.3.4 (Gentoo 4.3.4 p1.0, pie-10.1.5) 

The second:
Using built-in specs.
Target: arm-elf
Configured with: /tmp/gcc.ndS8/gcc-4.4.1/configure --enable-languages=c
--with-mpfr=/usr --without-headers --target=arm-elf --prefix=/usr/local/arm-elf
--with-local-prefix=/usr/local/arm-elf --disable-werror --disable-multilib
--disable-shared --disable-nls --disable-libssp --with-arch=armv4t
--with-cpu=arm7tdmi-s
Thread model: single
gcc version 4.4.1 (GCC) 

The warning appears with both gcc versions.


-- 
   Summary: "warning: will never be executed" about code which is
executed with "-Wunreachable-code"
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
     Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: agraf at znc dot in


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



[Bug inline-asm/42984] New: gcc produces broken code when passing struct pointer to static inline function with asm()

2010-02-06 Thread agraf at znc dot in
Compiling the following C source:

struct test {
int a;
};

static inline void test2(struct test *t)
{
register int a asm("r0") = (int) t;
asm volatile ("swi #0" :: "r" (a));
}

void test1(void)
{
struct test t;
t.a = 0;
test2(&t);
}

with "arm-elf-gcc test.c -S -O1" produces the following assembler output:

.file   "test.c"
.text
.align  2
.global test1
.type   test1, %function
test1:
@ args = 0, pretend = 0, frame = 4
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
sub sp, sp, #4
mov r0, sp
@ 8 "test.c" 1
swi #0
@ 0 "" 2
add sp, sp, #4
bx  lr
.size   test1, .-test1
.ident  "GCC: (GNU) 4.4.1"

For the call to test2(), the pointer to struct test t is properly set up, but
the content of the struct (t.a = 0) isn't.  This is the case for -O1, -O2, -Os
and -O3, but not for -O0, where gcc produces working code.

arm-elf-gcc -v:
Using built-in specs.
Target: arm-elf
Configured with: /var/tmp/gcc.uZt0/gcc-4.4.1/configure --enable-languages=c
--with-mpfr=/usr/local --without-headers --target=arm-elf
--prefix=/usr/local/arm-elf --with-local-prefix=/usr/local/arm-elf
--disable-werror --enable-multilib --enable-shared --disable-nls
--disable-libssp --with-arch=armv4t --with-cpu=arm7tdmi-s
Thread model: single
gcc version 4.4.1 (GCC)


-- 
   Summary: gcc produces broken code when passing struct pointer to
static inline function with asm()
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: inline-asm
    AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: agraf at znc dot in
GCC target triplet: arm-elf


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