Bug 35764 - improper load from volatile
Summary: improper load from volatile
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 35762 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-03-30 04:18 UTC by John Regehr
Modified: 2008-12-29 03:54 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:
Known to fail: 4.4.0 4.3.0 4.0.1
Last reconfirmed: 2008-12-29 03:54:58


Attachments

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;
  else
    return g_156;
}

Compiled with:

  gcc -O1 -S foo.c

Gives:
foo:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        call    bar
        cmpl    $1, %eax
        sbbl    %eax, %eax
        andl    g_156, %eax
        leave
        ret

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"
	.text
.globl foo
	.type	foo, @function
foo:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	call	bar
	cmpl	$1, %eax
	sbbl	%eax, %eax
	andl	g_156, %eax
	leave
	ret
	.size	foo, .-foo
	.comm	g_156,4,4
	.ident	"GCC: (GNU) 4.4.0 20081116 (experimental)"
	.section	.note.GNU-stack,"",@progbits
regehr@john-home:~$ 
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) 
regehr@john-home:~$ 
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.