Bug 8859 - [CygWin] Initializer element allegedly not constant
Summary: [CygWin] Initializer element allegedly not constant
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.2
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-07 07:46 UTC by mlt
Modified: 2003-07-17 11:22 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
xdts-bcst-gen.i.bz2 (65.19 KB, application/octet-stream)
2003-05-21 15:16 UTC, mlt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mlt 2002-12-07 07:46:00 UTC
Internal error: Segmentation fault on the attached pre-processed file with the command line specified in "How-to-repeat".

This is the output with some version stuff:
$ gcc -v -c -o xdts-bcst-gen.o xdts-bcst-gen.i -g
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs
Configured with: /netrel/src/gcc-3.2-3/configure --enable-languages=c,c++,f77,java --enable-libgcj --enable-threads=posi
x --with-system-zlib --enable-nls --without-included-gettext --enable-interpreter --disable-sjlj-exceptions --disable-ve
rsion-specific-runtime-libs --enable-shared --build=i686-pc-linux --host=i686-pc-cygwin --target=i686-pc-cygwin --enable
-haifa --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --includedir=/nonexistent/include --libexecd
ir=/usr/sbin
Thread model: posix
gcc version 3.2 20020927 (prerelease)
 /usr/lib/gcc-lib/i686-pc-cygwin/3.2/cc1.exe -fpreprocessed xdts-bcst-gen.i -quiet -dumpbase xdts-bcst-gen.i -g -version
 -o /cygdrive/c/DOCUME~1/Mats/LOCALS~1/Temp/ccP7x7gQ.s
GNU CPP version 3.2 20020927 (prerelease) (cpplib) (80386, BSD syntax)
GNU C version 3.2 20020927 (prerelease) (i686-pc-cygwin)
        compiled by GNU C version 3.2 20020927 (prerelease).
xdts-bcst-gen.c:308: internal error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.

Release:
gcc version 3.2 20020927 (prerelease)

Environment:
Cygwin (latest packages as of 2002-12-07) on Windows XP (SP1)

How-To-Repeat:
gcc -c -o xdts-bcst-gen.o xdts-bcst-gen.i -g
Comment 1 Volker Reichelt 2002-12-07 13:14:15 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: The preprocessed file is missing.
    Could you please provide it?
Comment 2 mlt 2002-12-08 10:30:50 UTC
From: "Mats Ljungqvist" <mlt@bredband.net>
To: <reichelt@igpm.rwth-aachen.de>,
	<gcc-bugs@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>,
	<mlt@bredband.net>,
	<nobody@gcc.gnu.org>,
	<gcc-gnats@gcc.gnu.org>
Cc:  
Subject: Re: other/8859: internal error: Segmentation fault
Date: Sun, 8 Dec 2002 10:30:50 +0100

 That's strange. I did attach the pre-processed file! Is it possible that the
 size (600K) of the file was to large?
 
 Anyway, I do have the pre-processed file. Where do you want me to send it?
 
 // Mats
 
 ----- Original Message -----
 From: <reichelt@igpm.rwth-aachen.de>
 To: <gcc-bugs@gcc.gnu.org>; <gcc-prs@gcc.gnu.org>; <mlt@bredband.net>;
 <nobody@gcc.gnu.org>
 Sent: Saturday, December 07, 2002 10:14 PM
 Subject: Re: other/8859: internal error: Segmentation fault
 
 
 > Synopsis: internal error: Segmentation fault
 >
 > State-Changed-From-To: open->feedback
 > State-Changed-By: reichelt
 > State-Changed-When: Sat Dec  7 13:14:15 2002
 > State-Changed-Why:
 >     The preprocessed file is missing.
 >     Could you please provide it?
 >
 >
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=8859
 >
 
 
Comment 3 Volker Reichelt 2002-12-10 03:19:01 UTC
State-Changed-From-To: feedback->open
State-Changed-Why: Attachment received.
Comment 4 Giovanni Bajo 2003-04-07 00:31:24 UTC
From: "Giovanni Bajo" <giovannibajo@libero.it>
To: <mlt@bredband.net>,
	<gcc-gnats@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<nobody@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>
Cc: "Wolfgang Bangerth" <bangerth@ices.utexas.edu>
Subject: Re: c/8859: [CygWin] internal error: Segmentation fault
Date: Mon, 7 Apr 2003 00:31:24 +0200

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=8859
 
 Redux:
 
 -----------------------------------------------
 struct Foo
 {
     int a;
 };
 
 __attribute__((__dllimport__)) struct Foo f;
 
 void* b = &f;
 -----------------------------------------------
 
 ICE on 3.2:
 pr8859.c:9: internal error: Segmentation fault
 Please submit a full bug report,
 
 Error on 2.95 and 3.3:
 pr8859.c:9: error: initializer element is not constant
 
 I would flag this as rejects-legal, since the code looks ok to me (even if I
 don't know exactly how attributes are supposed to work). It's not a
 regression, though. There was a regression in 3.2 (ICE) but it's fixed in
 3.3
 
 Giovanni Bajo
 
Comment 5 Wolfgang Bangerth 2003-04-07 13:52:42 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Giovanni comfirmed this
Comment 6 Danny Smith 2003-04-07 22:49:35 UTC
From: Danny Smith <dannysmith@clear.net.nz>
To: mlt@bredband.net, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
 nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org
Cc:  
Subject: Re: c/8859: [CygWin] Initializer element allegedly not constant
Date: Mon, 07 Apr 2003 22:49:35 +0100

 http://gcc.gnu.org/cgi-bin/gnatseb.pl?cmd=view%20audit-trail&database=gc
 c&pr=8859
 
 
 This is not a a regression, but  YA  "dllimport" expectation that the MS
 native compiler fulfills, but GCC does not.
 
 The dllimport attribute,  does this in config/i386/winnt.c
 (i386_pe_mark_dllimport):
 
 at line 343, config/i386/winnt.c:
 
   /* Can't treat a pointer to this as a constant address */
   DECL_NON_ADDR_CONST_P (decl) = 1;
 
 This is because:
 
 __attribute__((dllimport)) int foo;
 
 really means something like:
 
 extern int* _imp__foo;
 #define foo  *_imp__foo
 
 Because of this, the assignment error in the PR is actually valid: in C
 it is illegal
 to assign to non-constant at global scope. in C++  it works but requires
 dynamic
 global initialisation.
 
 Apparently, the native MS compiler ignores the the dllimport attribute
 in (some/all??) cases of assignment at global scope.
 
 Golly, I wonder if these MS rules are documented somewhere.
 I haven't found all the rules yet.
 
 
 Danny
Comment 7 Danny Smith 2003-07-17 10:55:35 UTC
This should be closed, IMO.  The initializer element is not constant, as 
explained in my last post, so the error report is valid.

Here is minimal testcase:

__declspec (dllimport) int foo;
int*  hook = &foo;

This is what MS compiler say about it:
cl /c address.c
d:\develop\bugs\address.c(2) : error C2099: initializer is not a constant

This is what gcc (3.4) says:
gcc -c address.c 
address.c:2: error: initializer element is not constant

A workaround is available for dllimported function addresses (not data) and 
that is to use -mnop-fun-dllimport switch to ignore the attribute for functions

Danny
Comment 8 Giovanni Bajo 2003-07-17 11:22:42 UTC
Not a bug, as explained by Danny. And it does emit a correct error message in 
all open branches. Thanks Danny for your patches!