public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16718] New: wrong code-gen for (e1 ?: e2)()
@ 2004-07-26 16:48 djg at cs dot washington dot edu
  2004-07-26 17:25 ` [Bug c/16718] " bangerth at dealii dot org
  0 siblings, 1 reply; 2+ messages in thread
From: djg at cs dot washington dot edu @ 2004-07-26 16:48 UTC (permalink / raw)
  To: gcc-bugs

On both gcc versions I have available (tageting x86), I get a seg-fault or
illegal-instruction for this program:

int h() {return 17;}
int g() {(h ?:0)();} // runs fine as (h ? h : 0)()
int main() {g(); return 0;}

I believe this happens whenever (e1 ?: e2) is used as a function argument and e1
is non-zero (haven't tested the case where e1 is 0)

gcc versions (perhaps it's only relevant that the target is x86):

swan% gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-113)
swan% gcc -save-temps blah.c

/cygdrive/y/cyclone$gcc -v
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,ja
va --enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls --with
out-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)

-- 
           Summary: wrong code-gen for (e1 ?: e2)()
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: djg at cs dot washington dot edu
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: Redhat (gcc 2.96) and Cygwin (gcc 3.2)


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


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

* [Bug c/16718] wrong code-gen for (e1 ?: e2)()
  2004-07-26 16:48 [Bug c/16718] New: wrong code-gen for (e1 ?: e2)() djg at cs dot washington dot edu
@ 2004-07-26 17:25 ` bangerth at dealii dot org
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth at dealii dot org @ 2004-07-26 17:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-07-26 17:25 -------
Confirmed. To avoid trouble with a non-void function not returning 
a value, the testcase should be written like this: 
--------------- 
void h() {} 
void g() { (h ?:0)(); } 
int main() {g(); return 0;} 
--------------- 
 
This program indeed crashes with gcc 3.2.x, 3.3.x and 3.4.x: 
g/x> /home/bangerth/bin/gcc-3.2*/bin/gcc x.c ; ./a.out  
Segmentation fault 
g/x> /home/bangerth/bin/gcc-3.3*/bin/gcc x.c ; ./a.out  
Segmentation fault 
g/x> /home/bangerth/bin/gcc-3.4*/bin/gcc x.c ; ./a.out  
Segmentation fault 
 
It doesn't, however, with present mainline, and in addition prints a 
very valid warning message: 
 
g/x> /home/bangerth/bin/gcc-3.5*/bin/gcc x.c ; ./a.out  
x.c: In function `g': 
x.c:2: warning: the address of `h', will always evaluate as `true' 
 
In other words: this is fixed already. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
      Known to fail|                            |3.5.0
      Known to work|                            |3.2.3 3.3.3 3.4.0
         Resolution|                            |FIXED
   Target Milestone|---                         |3.5.0


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


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

end of thread, other threads:[~2004-07-26 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-26 16:48 [Bug c/16718] New: wrong code-gen for (e1 ?: e2)() djg at cs dot washington dot edu
2004-07-26 17:25 ` [Bug c/16718] " bangerth at dealii 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).