Bug 35764 - improper load from volatile
Summary: improper load from volatile
Status: RESOLVED DUPLICATE of bug 47698
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
Keywords: wrong-code
: 35762 (view as bug list)
Depends on:
Reported: 2008-03-30 04:18 UTC by John Regehr
Modified: 2021-07-29 22:34 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.1.2, 4.7.0
Known to fail: 4.0.1, 4.3.0, 4.4.0, 4.6.4
Last reconfirmed: 2008-12-29 03:54:58


Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2008-03-30 04:18:26 UTC
This is for "gcc version 4.3.0 (GCC)" 

This is very likely related to 35729 and 35762.

This code:

extern int bar (void);
volatile int g_156;
int foo (void)
  if (bar ())
    return 0;
    return g_156;

Compiled with:

  gcc -O1 -S foo.c

        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        call    bar
        cmpl    $1, %eax
        sbbl    %eax, %eax
        andl    g_156, %eax

The unconditional load from volatile g_156 is incorrect.
Comment 1 Andrew Pinski 2008-11-15 00:09:09 UTC
This works for me on the trunk.  I either get a cmove or a branch.
Comment 2 John Regehr 2008-11-16 04:34:06 UTC
I'm not sure what is going on, I get the same code as before using r141907 on Ubuntu Hardy on x86.  What compiler options are you using and what platform?

regehr@john-home:~$ current-gcc -O -S vol.c -o -
	.file	"vol.c"
.globl foo
	.type	foo, @function
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	call	bar
	cmpl	$1, %eax
	sbbl	%eax, %eax
	andl	g_156, %eax
	.size	foo, .-foo
	.comm	g_156,4,4
	.ident	"GCC: (GNU) 4.4.0 20081116 (experimental)"
	.section	.note.GNU-stack,"",@progbits
regehr@john-home:~$ current-gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --program-prefix=current- --enable-languages=c,c++ --prefix=/home/regehr
Thread model: posix
gcc version 4.4.0 20081116 (experimental) (GCC) 
Comment 3 Andrew Pinski 2008-12-29 03:51:11 UTC
*** Bug 35762 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2008-12-29 03:54:58 UTC
Confirmed, -march=i386 -mtune=i686 is needed to confirm the bug in general.

GCC is producing a "conditional move" for the code even though it is invalid to produce such a thing.

Comment 5 Andrew Pinski 2021-07-29 22:34:07 UTC
Fixed in GCC 4.7.0 because this is a dup of bug 47698.

*** This bug has been marked as a duplicate of bug 47698 ***