Bug 51321 - __builtin_types_compatible_p (any_type_t[1][], any_other_type_t) crashes GCC
Summary: __builtin_types_compatible_p (any_type_t[1][], any_other_type_t) crashes GCC
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.4
: P3 normal
Target Milestone: 4.7.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: error-recovery, ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2011-11-27 07:20 UTC by Herman Narkaytis
Modified: 2011-11-30 19:56 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-11-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Herman Narkaytis 2011-11-27 07:20:42 UTC
int main ()
{
  return (__builtin_types_compatible_p (char[1][], char[1][1]));
}


cc -Wall -O2 -g    bug.c   -o bug
bug.c: In function 'main':
bug.c:3: error: array type has incomplete element type
bug.c:3: confused by earlier errors, bailing out
Preprocessed source stored into /tmp/ccPgaiXX.out file, please attach this to your bugreport.
make: *** [bug] Error 1


// /usr/libexec/gcc/x86_64-redhat-linux/4.4.4/cc1 -quiet bug.c -quiet -dumpbase bug.c -mtune=generic -auxbase bug -g -O2 -Wall -o - -frandom-seed=0
# 1 "bug.c"
# 1 "/home/smash/development/hello//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "bug.c"
int main ()
{
  return (__builtin_types_compatible_p (char[1][], char[1][1]));
}
Comment 1 Herman Narkaytis 2011-11-27 07:27:23 UTC
gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.4 20100630 (Red Hat 4.4.4-10) (GCC)
Comment 2 Andrew Pinski 2011-11-29 05:24:07 UTC
t34.c: In function ‘main’:
t34.c:3:2: error: array type has incomplete element type
t34.c:3:2: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in c_parser_postfix_expression, at c-parser.c:6572
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


Confirmed.
Comment 3 Andrew Pinski 2011-11-29 05:28:24 UTC
Semi-obvious patch:
Index: c-parser.c
===================================================================
--- c-parser.c	(revision 181796)
+++ c-parser.c	(working copy)
@@ -6568,9 +6568,16 @@ c_parser_postfix_expression (c_parser *p
 				     "expected %<)%>");
 	  {
 	    tree e1, e2;
+	    e1 = groktypename (t1, NULL, NULL);
+	    e2 = groktypename (t2, NULL, NULL);
+	    if (e1 == error_mark_node || e2 == error_mark_node)
+	      {
+		expr.value = error_mark_node;
+		break;
+	      }
 
-	    e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL));
-	    e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL));
+	    e1 = TYPE_MAIN_VARIANT (e1);
+	    e2 = TYPE_MAIN_VARIANT (e2);
 
 	    expr.value
 	      = comptypes (e1, e2) ? integer_one_node : integer_zero_node;
Comment 4 Andrew Pinski 2011-11-30 19:55:41 UTC
Author: pinskia
Date: Wed Nov 30 19:55:36 2011
New Revision: 181857

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181857
Log:
2011-11-30  Andrew Pinski  <apinski@cavium.com>

	PR c/51321
	* c-parser.c (c_parser_postfix_expression): Check groktypename results
	before looking at the main variant.

2011-11-30  Andrew Pinski  <apinski@cavium.com>

	* gcc.dg/pr51321.c: New testcase.




Added:
    trunk/gcc/testsuite/gcc.dg/pr51321.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-parser.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Andrew Pinski 2011-11-30 19:56:35 UTC
Fixed.