LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 855 - ICE on invalid array with size determined by sizeof incomplete type
Summary: ICE on invalid array with size determined by sizeof incomplete type
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-gcc (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Bill Wendling
URL:
Keywords: crash-on-invalid
Depends on:
Blocks:
 
Reported: 2006-07-30 07:48 PDT by Nick Lewycky
Modified: 2010-03-06 14:00 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Lewycky 2006-07-30 07:48:06 PDT
$ llvm-gcc 025.c -c -o 025
025.c:1: error: invalid application of ‘sizeof’ to incomplete type ‘struct
poll_table_entry’ 
025.c:1: warning: division by zero
025.c:1: error: array type has incomplete element type
025.c:1: internal compiler error: tree check: expected class ‘type’, have
‘exceptional’ (error_mark) in grokdeclarator, at c-decl.c:4356
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://llvm.org/bugs> for instructions.
$ cat 025.c
 struct poll_table_entry inline_entries[((832 - 256) / sizeof(struct
poll_table_entry))];
$
Comment 1 Bill Wendling 2006-07-30 13:26:03 PDT
Hi Nick,

Which version of llvm-gcc are you using? It doesn't ICE on this version:

[Gaz:llvm] llvm-gcc --version
llvm-gcc (GCC) 3.4-llvm 20051104 (LLVM 1.7cvs)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 2 Nick Lewycky 2006-07-30 14:55:36 PDT
$ llvm-gcc --version
llvm-gcc (GCC) 4.0.1 LLVM (Apple Computer, Inc. build 5400)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Latest out of the subversion repository last night.
Comment 3 Chris Lattner 2006-07-30 18:50:22 PDT
I'll take a look tomorrow unless someone beats me to it.
Comment 4 Chris Lattner 2006-07-31 12:37:05 PDT
This appears to be a problem with the generic GCC code llvm-gcc is based on.  
Comment 5 Bill Wendling 2006-09-20 01:51:37 PDT
Merged some code from mainline GCC to c-decl.c. Essentially, if there is an array with an incomplete type, 
it sets the type to an error type. But then we were trying to do things with that type.

Submitted a fix for this to the llvmdev mailing list.
Comment 6 Bill Wendling 2006-09-21 13:57:50 PDT
A quick test with the gcc 4.0.1 compiler on a Mac Intel machine (without the apple local patches) and it 
doesn't ICE.
Comment 7 Nick Lewycky 2006-09-21 17:34:19 PDT
I can verify that this patch works on my x86-linux build, and still passes
dejagnu's frontend tests. The patch itself looks minimal to me (though I'm no
gcc hacker).

I think it should be applied. Chris?
Comment 8 Bill Wendling 2006-09-21 23:03:28 PDT
Mystery Of The Kind-of Working Compiler!

Here's what's happening. In LLVM's GCC, the crashing line resolves to this after preprocessing:

   if (size_varies)
     (__extension__ ({ const tree __t = (type); if (tree_code_type[(int) (((enum tree_code) (__t)-
>common.code))] != (tcc_type)) tree_class_check_failed (__t, (tcc_type), "../../llvm-\
gcc4/gcc/c-decl.c", 4358, __FUNCTION__); __t; })->type.lang_flag_1) = 1;

With TOT in positron, it comes out as:

   if (size_varies)
    ((type)->type.lang_flag_1) = 1;

So, basically, when tree checking is enabled, we get the ICE. Otherwise, it goes away.
Comment 9 Chris Lattner 2006-09-21 23:05:30 PDT
Ahh, so this fails with a non-llvm checking-enabled positron compiler as well?

-Chris
Comment 10 Bill Wendling 2006-09-21 23:07:02 PDT
That's my next check. :-) I'll generate the new compiler now and make sure that the failure's there too.
Comment 11 Bill Wendling 2006-09-21 23:48:31 PDT
Holy crap! When "--enable-checking" is used during configuration with non-LLVM gcc, we get the same 
ICE.

Hott!

I'll submit the patch.
Comment 12 Chris Lattner 2006-09-22 00:11:15 PDT
Whoa, that even makes sense! :)

Thanks Bill,

-Chris
Comment 13 Bill Wendling 2006-09-22 00:37:14 PDT
Fixed:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20060918/038091.html

Also patched llvm-gcc.
Comment 14 Chris Lattner 2006-09-22 12:24:22 PDT
Thanks Bill!