Bug 37217 - [4.4 Regression] -Wconversion causes ICE with __builtin_strcmp with one char compare
Summary: [4.4 Regression] -Wconversion causes ICE with __builtin_strcmp with one char ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 37230 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-08-24 01:39 UTC by James McKelvey
Modified: 2008-08-28 02:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-08-24 22:27:02


Attachments
Compressed preprocessed source (60.28 KB, application/octet-stream)
2008-08-24 01:41 UTC, James McKelvey
Details
test2.i.gz (31.24 KB, application/octet-stream)
2008-08-25 11:37 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James McKelvey 2008-08-24 01:39:58 UTC
This code has been working forever:

$ g++ -v
Using built-in specs.
Target: i686-pc-cygwin
Configured with: /cygdrive/f/Home/cvsroot/gcc/configure --verbose --enable-threads --disable-nls --disable-win32-registry --enable-languages=c,c++
Thread model: posix
gcc version 4.4.0 20080823 (experimental) (GCC) 

User@MCKELVEY-XP ~/PD
$ uname -a
CYGWIN_NT-5.1 MCKELVEY-XP 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin



$ g++ -c -g -fno-elide-constructors      -DUSE_MUTEX=1  -pedantic-errors -Werror -ansi -fno-common -Wall -Wold-style-cast -Wsign-promo -Wpointer-arith -Wundef -Wwrite-strings -Winvalid-pch -Woverloaded-virtual -Wcast-qual -Wextra -Wredundant-decls -Wshadow -Wcast-align -Wcomment -fstrict-aliasing -Winit-self -Wmissing-include-dirs -Wswitch-default -Wswitch-enum -Wlogical-op -Wconversion -Wmissing-declarations -Wunused -MMD   --save-temp   -fimplicit-templates -o Types.o Types.cc
In file included from /usr/local/lib/gcc/i686-pc-cygwin/4.4.0/../../../../include/c++/4.4.0/bits/localefwd.h:48,
                 from /usr/local/lib/gcc/i686-pc-cygwin/4.4.0/../../../../include/c++/4.4.0/locale:46,
                 from Types.h:37,
                 from Types.cc:29:
/usr/local/lib/gcc/i686-pc-cygwin/4.4.0/../../../../include/c++/4.4.0/i686-pc-cygwin/bits/c++locale.h: In function 'int std::__convert_from_v(int* const&, char*, int, const char*, ...)':
/usr/local/lib/gcc/i686-pc-cygwin/4.4.0/../../../../include/c++/4.4.0/i686-pc-cygwin/bits/c++locale.h:67: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.



$ alias CONFIGURECVS
alias CONFIGURECVS='/cygdrive/f/Home/cvsroot/gcc/configure     --verbose --enable-threads --disable-nls     --disable-win32-registry --enable-languages=c,c++'

User@MCKELVEY-XP ~/PD
$ alias BUILD
alias BUILD='nice make CFLAGS='\'''\'' BOOT_CFLAGS='\'''\'' LIBCFLAGS='\''-g -O'\''     CXXFLAGS='\''-O'\'' LIBCXXFLAGS='\''-g -O'\''     bootstrap'
Comment 1 James McKelvey 2008-08-24 01:41:40 UTC
Created attachment 16135 [details]
Compressed preprocessed source
Comment 2 Andrew Pinski 2008-08-24 22:20:04 UTC
Reducing, -Wconversion causes the ICE.
Comment 3 Andrew Pinski 2008-08-24 22:27:02 UTC
Confirmed, reduced testcase:
    int   __convert_from_v( )   {
     char* __old;
     if (__builtin_strcmp(__old, "C")) {}
}
Comment 4 Tobias Burnus 2008-08-25 08:26:08 UTC
My PR 37230 is presumably a duplicate of this PR. There, valgrind shows for "gcc -Wconcersion":

==26156== Invalid read of size 2
==26156==    at 0x458558: conversion_warning (c-common.c:1571)
==26156==    by 0x4593F7: convert_and_check (c-common.c:1839)
==26156==    by 0x42BF71: build_binary_op (c-typeck.c:8434)

1571 is this line:
  1566    /* If any operand is artificial, then this expression was generated
  1567       by the compiler and we do not warn.  */
  1568    for (i = 0; i < expr_num_operands; i++)
  1569      {
  1570        tree op = TREE_OPERAND (expr, i);
  1571        if (DECL_P (op) && DECL_ARTIFICIAL (op))
  1572          return;
  1573      }

Working: 2008-08-20-r139252
Failing: 2008-08-21-r139367
Failing: 20080824 (experimental) [trunk revision 139535]
Comment 5 Tobias Burnus 2008-08-25 09:31:22 UTC
Manuel, I think it was caused by your check in for:

2008-08-17  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c++/35602
	* c-common.c (conversion_warning): Do not want for artificial
	expressions.

It fits time wise and valgrind points at lines you added there.
Comment 6 Manuel López-Ibáñez 2008-08-25 10:22:04 UTC
(In reply to comment #5)
> Manuel, I think it was caused by your check in for:
> 
> 2008-08-17  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
> 
>         PR c++/35602
>         * c-common.c (conversion_warning): Do not want for artificial
>         expressions.
> 
> It fits time wise and valgrind points at lines you added there.

I cannot reproduce this with any of the testcases in x86_64-unknow-linux-gnu and that is all I have access to. Please attach your testcase from PR37230 and if it could be reduced for x86_64-unknow-linux-gnu by Andrew or someone else, that would be extremely helpful.


Comment 7 Tobias Burnus 2008-08-25 11:37:23 UTC
Created attachment 16144 [details]
test2.i.gz

> I cannot reproduce this with any of the testcases in x86_64-unknow-linux-gnu
> and that is all I have access to. Please attach your testcase from PR37230 and
> if it could be reduced for x86_64-unknow-linux-gnu by Andrew or someone else,
> that would be extremely helpful.

Test case from PR37230. Run as:
$ gcc -Wconversion test2.i

That gives the mentioned segfault and the valgrind error on my x86_64-unknow-linux-gnu.
Comment 8 Manuel López-Ibáñez 2008-08-25 12:36:55 UTC
The fix is trivial:

Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c      (revision 139373)
+++ gcc/c-common.c      (working copy)
@@ -1566,11 +1566,11 @@ conversion_warning (tree type, tree expr
   /* If any operand is artificial, then this expression was generated
      by the compiler and we do not warn.  */
   for (i = 0; i < expr_num_operands; i++)
     {
       tree op = TREE_OPERAND (expr, i);
-      if (DECL_P (op) && DECL_ARTIFICIAL (op))
+      if (op && DECL_P (op) && DECL_ARTIFICIAL (op))
        return;
     }

   switch (TREE_CODE (expr))
     {

However, the testcase is too big for the testsuite...
Comment 9 Andrew Pinski 2008-08-25 18:59:53 UTC
(In reply to comment #8)
> However, the testcase is too big for the testsuite...
The C++ testcase I attached is small.  See comment #4.
Comment 10 Manuel López-Ibáñez 2008-08-25 19:07:37 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > However, the testcase is too big for the testsuite...
> The C++ testcase I attached is small.  See comment #4.

I don't get the ICE with that testcase in x86_64-unknown-linux-gnu.
Comment 11 Manuel López-Ibáñez 2008-08-25 21:53:27 UTC
(In reply to comment #10)
> (In reply to comment #9)
> > (In reply to comment #8)
> > > However, the testcase is too big for the testsuite...
> > The C++ testcase I attached is small.  See comment #4.
> 
> I don't get the ICE with that testcase in x86_64-unknown-linux-gnu.
> 

Reduced testcase for x86_64-unknown-linux-gnu.

typedef struct Tcl_ResolvedVarInfo {
 char *re_guts;
} regex_t;
void TclReComp(regex_t *re)
{
 if (re->re_guts == ((void *)0)) ;
}
Comment 12 Manuel López-Ibáñez 2008-08-26 07:58:43 UTC
Patch: http://gcc.gnu.org/ml/gcc-patches/2008-08/msg01913.html

Please test that it fixes the ICE in i686-pc-cygwin. Thanks.
Comment 13 Tobias Burnus 2008-08-27 15:36:57 UTC
*** Bug 37230 has been marked as a duplicate of this bug. ***
Comment 14 Manuel López-Ibáñez 2008-08-28 00:02:16 UTC
Subject: Bug 37217

Author: manu
Date: Thu Aug 28 00:00:49 2008
New Revision: 139682

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139682
Log:
2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR 37217
	* c-common.c (convesion_warning): Check for null operands.
testsuite/
	* gcc.dg/pr37217.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/pr37217.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/testsuite/ChangeLog

Comment 15 Manuel López-Ibáñez 2008-08-28 00:09:34 UTC
Subject: Bug 37217

Author: manu
Revision: 139682
Modified property: svn:log

Modified: svn:log at Thu Aug 28 00:09:20 2008
------------------------------------------------------------------------------
--- svn:log (original)
+++ svn:log Thu Aug 28 00:09:20 2008
@@ -1,6 +1,6 @@
 2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
 	PR 37217
-	* c-common.c (convesion_warning): Check for null operands.
+	* c-common.c (conversion_warning): Check for null operands.
 testsuite/
 	* gcc.dg/pr37217.c: New.

Comment 16 Manuel López-Ibáñez 2008-08-28 00:12:51 UTC
Fixed in GCC 4.4.
Comment 17 James McKelvey 2008-08-28 02:41:09 UTC
(In reply to comment #12)
> Patch: http://gcc.gnu.org/ml/gcc-patches/2008-08/msg01913.html
> 
> Please test that it fixes the ICE in i686-pc-cygwin. Thanks.
> 

Yes! Thanks!