public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26511]  New: Using -O3, doesn't assign in a pointer to a global structure
@ 2006-03-01 13:30 wielemak at science dot uva dot nl
  2006-03-01 13:31 ` [Bug c/26511] " wielemak at science dot uva dot nl
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: wielemak at science dot uva dot nl @ 2006-03-01 13:30 UTC (permalink / raw)
  To: gcc-bugs

Trying to compile SWI-Prolog (www.swi-prolog.org) on Debian-Alpha the
following is not compiled correctly (function initPrologThreads())

  info = &threads[1];
  info->tid = pthread_self();
  info->pl_tid = 1;                      // this assignment is simply not done
  info->thread_data = &PL_local_data;
  info->status = PL_THREAD_RUNNING;
  PL_local_data.thread.info = info;
  PL_local_data.thread.magic = PL_THREAD_MAGIC;

Swapping the last two lines just below the first is a `work around'.

Compiled with the commandline:

gcc -c -I. -I/home/wielemaker/src/pl/src -I/home/wielemaker/src/pl/src/rc -Wall
-O3 -fno-strict-aliasing -mieee pl-thread.c -o pl-thread.o

$ gcc -v
Using built-in specs.
Target: alphaev67-unknown-linux-gnu
Configured with: ../gcc-4.0.2/configure --prefix=/usr/local
Thread model: posix
gcc version 4.0.2

I'll attach pl-thread.i.  If you need the full source, please download
version 5.6.6 tarball from www.swi-prolog.org.  There have been some patches
since, but the bug reproduces on that version.


-- 
           Summary: Using -O3, doesn't assign in a pointer to a global
                    structure
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wielemak at science dot uva dot nl
 GCC build triplet: alphaev67-unknown-linux-gnu
  GCC host triplet: alphaev67-unknown-linux-gnu
GCC target triplet: alphaev67-unknown-linux-gnu


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
@ 2006-03-01 13:31 ` wielemak at science dot uva dot nl
  2006-03-01 15:48 ` [Bug target/26511] " pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: wielemak at science dot uva dot nl @ 2006-03-01 13:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from wielemak at science dot uva dot nl  2006-03-01 13:31 -------
Created an attachment (id=10945)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10945&action=view)
Preprocessor output


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
  2006-03-01 13:31 ` [Bug c/26511] " wielemak at science dot uva dot nl
@ 2006-03-01 15:48 ` pinskia at gcc dot gnu dot org
  2006-03-02  9:24 ` wielemak at science dot uva dot nl
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-01 15:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-03-01 15:48 -------
Do you have a simple self contained testcase?


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
  2006-03-01 13:31 ` [Bug c/26511] " wielemak at science dot uva dot nl
  2006-03-01 15:48 ` [Bug target/26511] " pinskia at gcc dot gnu dot org
@ 2006-03-02  9:24 ` wielemak at science dot uva dot nl
  2006-03-02 10:08 ` wielemak at science dot uva dot nl
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: wielemak at science dot uva dot nl @ 2006-03-02  9:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from wielemak at science dot uva dot nl  2006-03-02 09:24 -------
Andrew,

If you think this is a real and still present bug I could try to add a
little main() to the file and turn the file into a stand-alone program.
I guess it is pretty likely it depends on nasty details in the structure
definitions and it will be a lot of work to cut down the headers and
still be able to compile the program and reproduce the bug.

If you simply want to reproduce, fetch pl-5.6.6.tar.gz from
http://gollem.science.uva.nl/cgi-bin/nph-download/SWI-Prolog/pl-5.6.6.tar.gz
Unpack, goto pl-5.6.6/src, type ./configure, add -g to COFLAGS in
Makefile, make (few warnings, these are fixed already but do not affect
this problem), abort Prolog which will be crashing in a loop using ^\.
Now 

gdb pl
(gdb) break initPrologThreads
(gdb) run
(gdb) finish
(gdb) print *info

And you see the problem. The nasty thing is that if you add a
print-statement reading the info->pl_tid, it is compiled correctly. It
gives the impression that somehow gcc thinks the value is never used and
it thus can ignore the assignment. As the structure is in global memory
(part of the threads[] array) and it *is* used, this is of course
completely wrong.

   Cheers --- Jan


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (2 preceding siblings ...)
  2006-03-02  9:24 ` wielemak at science dot uva dot nl
@ 2006-03-02 10:08 ` wielemak at science dot uva dot nl
  2006-03-03  9:42 ` falk at debian dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: wielemak at science dot uva dot nl @ 2006-03-02 10:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from wielemak at science dot uva dot nl  2006-03-02 10:08 -------
Oops, must be ./configure --enable-mt


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (3 preceding siblings ...)
  2006-03-02 10:08 ` wielemak at science dot uva dot nl
@ 2006-03-03  9:42 ` falk at debian dot org
  2006-03-03 10:55 ` wielemak at science dot uva dot nl
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: falk at debian dot org @ 2006-03-03  9:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from falk at debian dot org  2006-03-03 09:42 -------
(In reply to comment #3)
> If you think this is a real and still present bug I could try to add a
> little main() to the file and turn the file into a stand-alone program.

Well, we can't know whether it is a real and still present bug unless we
have a test case :-) So it would be really nice if you could create one.


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (4 preceding siblings ...)
  2006-03-03  9:42 ` falk at debian dot org
@ 2006-03-03 10:55 ` wielemak at science dot uva dot nl
  2006-03-03 12:22 ` falk at debian dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: wielemak at science dot uva dot nl @ 2006-03-03 10:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from wielemak at science dot uva dot nl  2006-03-03 10:55 -------
So true, but you have a test-case.  Ok, its a big program, but it will do
the job for you in 5 minutes typing 3 commands.  Turning it into a small
program is not a trivial exercise, while it definitely doesn't help verifying
whether the bug is still present and isn't even that likely to help finding
it.  Quite likely simply reading the assembly of the function will tell you
the output is wrong.  I guess it either skipped the assignment or writes to
the wrong place.  My assembly experience is too outdated and I never saw
Alpha assembly.

True, you're a volunteer, but the same holds for me, fixing similar
problems in SWI-Prolog.  My only criterium is something I can unpack and
run in a few commands.  Only if it turns out that their is no way to tell
whether the bug is in my compiler or not without examining large parts of
the program I ask the submitter to create a small program.

    Cheers --- Jan


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (5 preceding siblings ...)
  2006-03-03 10:55 ` wielemak at science dot uva dot nl
@ 2006-03-03 12:22 ` falk at debian dot org
  2006-03-03 12:43 ` wielemak at science dot uva dot nl
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: falk at debian dot org @ 2006-03-03 12:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from falk at debian dot org  2006-03-03 12:21 -------
I can't reproduce this problem on alphaev68-linux with gcc 4.0.3 20060212
(prerelease) (Debian 4.0.2-9). So either it is fixed already, or caused by
something else. Can you attach the assembly for the function from your 4.0.2
compiler?


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (6 preceding siblings ...)
  2006-03-03 12:22 ` falk at debian dot org
@ 2006-03-03 12:43 ` wielemak at science dot uva dot nl
  2006-03-03 14:24 ` falk at debian dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: wielemak at science dot uva dot nl @ 2006-03-03 12:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from wielemak at science dot uva dot nl  2006-03-03 12:43 -------
Created an attachment (id=10962)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10962&action=view)
Sources and assembly output

Contains sources and assembly for broken version as well as working version
(resulted from swapping a few statements).  See contained README.


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (7 preceding siblings ...)
  2006-03-03 12:43 ` wielemak at science dot uva dot nl
@ 2006-03-03 14:24 ` falk at debian dot org
  2006-03-03 14:38 ` wielemak at science dot uva dot nl
  2006-03-03 15:16 ` falk at debian dot org
  10 siblings, 0 replies; 12+ messages in thread
From: falk at debian dot org @ 2006-03-03 14:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from falk at debian dot org  2006-03-03 14:24 -------
The reason is:

pl-thread.c:78: warning: ignoring asm-specifier for non-static local variable
'_sc_0'
pl-thread.c:78: warning: ignoring asm-specifier for non-static local variable
'_sc_19'

This makes gcc not know that $19 gets clobbered by syscall. You need to add the
 register" keyword. I don't know exactly where your syscall macro is coming
from, but it's broken. I'd suggest you get a proper one from current glibc.


-- 

falk at debian dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (8 preceding siblings ...)
  2006-03-03 14:24 ` falk at debian dot org
@ 2006-03-03 14:38 ` wielemak at science dot uva dot nl
  2006-03-03 15:16 ` falk at debian dot org
  10 siblings, 0 replies; 12+ messages in thread
From: wielemak at science dot uva dot nl @ 2006-03-03 14:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from wielemak at science dot uva dot nl  2006-03-03 14:37 -------
Frank,

Thanks a lot!  It just comes from man gettid:

NAME
       gettid - get thread identification

SYNOPSIS
       #include <sys/types.h>
       #include <linux/unistd.h>
       #include <errno.h>

       _syscall0(pid_t,gettid)

       pid_t gettid(void);

This code passes configure and is thus included.  Should I conclude glibc
is broken?  Its not my machine, I'm just trying to fix a problem for a
SWI-Prolog user ...  Anyway, if it doesn't reproduce on the latest Debian
I guess it is fixed.


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug target/26511] Using -O3, doesn't assign in a pointer to a global structure
  2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
                   ` (9 preceding siblings ...)
  2006-03-03 14:38 ` wielemak at science dot uva dot nl
@ 2006-03-03 15:16 ` falk at debian dot org
  10 siblings, 0 replies; 12+ messages in thread
From: falk at debian dot org @ 2006-03-03 15:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from falk at debian dot org  2006-03-03 15:16 -------
(In reply to comment #10)

> This code passes configure and is thus included.  Should I conclude glibc
> is broken?

The macro comes from the Debian package "linux-kernel-headers", which
takes it from the Linux kernel.

>  Its not my machine, I'm just trying to fix a problem for a
> SWI-Prolog user ...  Anyway, if it doesn't reproduce on the latest Debian
> I guess it is fixed.

It's fixed already in Debian sarge linux-kernel-headers 2.5.999-test7-bk-17, so
that must be an ancient system.


-- 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-03-03 15:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-01 13:30 [Bug c/26511] New: Using -O3, doesn't assign in a pointer to a global structure wielemak at science dot uva dot nl
2006-03-01 13:31 ` [Bug c/26511] " wielemak at science dot uva dot nl
2006-03-01 15:48 ` [Bug target/26511] " pinskia at gcc dot gnu dot org
2006-03-02  9:24 ` wielemak at science dot uva dot nl
2006-03-02 10:08 ` wielemak at science dot uva dot nl
2006-03-03  9:42 ` falk at debian dot org
2006-03-03 10:55 ` wielemak at science dot uva dot nl
2006-03-03 12:22 ` falk at debian dot org
2006-03-03 12:43 ` wielemak at science dot uva dot nl
2006-03-03 14:24 ` falk at debian dot org
2006-03-03 14:38 ` wielemak at science dot uva dot nl
2006-03-03 15:16 ` falk at debian dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).