middle-end/9998: Lost update on bitfield manipulation via pointer

eriksoe@daimi.au.dk eriksoe@daimi.au.dk
Sat Mar 8 06:56:00 GMT 2003


>Number:         9998
>Category:       middle-end
>Synopsis:       Lost update on bitfield manipulation via pointer
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 08 06:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Erik Søe Sørensen
>Release:        gcc version 3.1.1
>Organization:
>Environment:
(Red Hat Linux 7.3 2.96-113)
>Description:
Under certain circumstances involving two or more write operations on a bitfield, one of the writes may be lost.
The reason is that code like this is emitted:
	movl	8(%ebp), %ecx
	orb	$1, 8(%ebp)
        ...
	movl	%eax, 8(%ebp)
- the first two instructions are in the wrong order.

I first noticed this with gcc version 2.96 20000731 - which only generated wrong code with -O2 or higher; in gcc 3.1.1 the problem occurs even without optimizations.
>How-To-Repeat:
gcc -ggdb bug1.c -O0
The attached program ought to print '1'.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bug1.i"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug1.i"

IyAxICJidWcxLmMiCiMgMSAiPGJ1aWx0LWluPiIKIyAxICI8Y29tbWFuZCBsaW5lPiIKIyAxICJi
dWcxLmMiCmV4dGVybiBpbnQgcHJpbnRmKGNvbnN0IGNoYXIqIGZvcm1hdCwuLi4pOwoKc3RydWN0
IE0gewogICAgICAgIHVuc2lnbmVkIGEgOiAxOwogICAgICAgIHVuc2lnbmVkIGIgOiAyOwp9OwoK
c3RydWN0IE4gewogICAgICAgIHVuc2lnbmVkIGEgOiAxOwogICAgICAgIHVuc2lnbmVkIGIgOiAy
Owp9OwoKc3RydWN0IE4qIGZvbyhzdHJ1Y3QgTSBtKSB7CiAgICAgICAgc3RydWN0IE0gc2F2ZSA9
IG07CiAgICAgICAgc3RydWN0IE4gKm4gPSAoc3RydWN0IE4qKSAmbTsKICAgICAgICBuLT5hID0g
MTsKICAgICAgICBuLT5iID0gc2F2ZS5iXjI7CiAgICAgICAgcmV0dXJuIG47Cn0KCmludCBtYWlu
KCkgewogICAgICAgIHN0cnVjdCBNIG07CiAgICAgICAgc3RydWN0IE4qIG47CiAgICAgICAgbS5h
ID0gMDsKICAgICAgICBuPWZvbyhtKTsKICAgICAgICBwcmludGYoIiVkXG4iLCBuLT5hKTsKfQo=



More information about the Gcc-prs mailing list