Bug 23426 - [4.0/4.1 Regression] Too large array problem gives two error message
Summary: [4.0/4.1 Regression] Too large array problem gives two error message
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P2 minor
Target Milestone: 4.0.3
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: diagnostic, patch
: 23461 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-08-16 18:43 UTC by Jim Wilson
Modified: 2005-10-28 14:57 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0
Known to fail: 4.0.0 4.1.0
Last reconfirmed: 2005-10-28 03:57:06


Attachments
Patch to partially fix problem with too large arrays. (480 bytes, patch)
2005-08-16 18:45 UTC, Jim Wilson
Details | Diff
Testcase for too large array problem. (211 bytes, text/plain)
2005-08-16 18:46 UTC, Jim Wilson
Details
corrected testcase for too large array problem (210 bytes, text/plain)
2005-08-17 22:40 UTC, Jim Wilson
Details
corrected patch to partially fix problem with too large arrays (490 bytes, patch)
2005-08-17 23:00 UTC, Jim Wilson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Wilson 2005-08-16 18:43:52 UTC
A testcase that has an array larger than half the address space and smaller than
the address space will trigger an abort in tree_int_cst_low.

The problem here is that we have a TREE_OVERFLOW (TYPE_SIZE (...)) check in the
C++ front end.  This no longer works now that TYPE_SIZE is computed as
bitsizetype which has extra precision.  We must use TYPE_SIZE_UNIT instead. 
This is trivial to fix, but now the testcase gets two errors instead of the
expected one error.  I don't know if this is intended behaviour, or whether this
is a latent bug in the C++ front end.  Either way, my testcase doesn't work for
the testsuite because of this problem, so a C++ front end maintainer will have
to decide what to do.

Result without the patch
large-size-array.cc: In function ‘int main()’:
large-size-array.cc:17: internal compiler error: in tree_low_cst, at tree.c:4270

Result with the patch
large-size-array.cc: In function ‘int main()’:
large-size-array.cc:19: error: size of array ‘a’ is too large
large-size-array.cc:20: error: ‘a’ was not declared in this scope

Both of these results are wrong.
Comment 1 Jim Wilson 2005-08-16 18:45:48 UTC
Created attachment 9504 [details]
Patch to partially fix problem with too large arrays.
Comment 2 Jim Wilson 2005-08-16 18:46:49 UTC
Created attachment 9505 [details]
Testcase for too large array problem.
Comment 3 Andrew Pinski 2005-08-17 02:40:11 UTC
Confirmed.  A regression from 3.4.0.

Note there is a typo in the test, USHORT_MAX should be USHRT_MAX.
Comment 4 Jim Wilson 2005-08-17 22:40:56 UTC
Created attachment 9524 [details]
corrected testcase for too large array problem

Fix typo in testcase.
Comment 5 Jim Wilson 2005-08-17 23:00:22 UTC
Created attachment 9525 [details]
corrected patch to partially fix problem with too large arrays
Comment 6 Andrew Pinski 2005-08-18 15:59:31 UTC
*** Bug 23461 has been marked as a duplicate of this bug. ***
Comment 7 Mark Mitchell 2005-08-22 05:03:24 UTC
I think the knock-on error message is a latent bug in the C++ front end, so your
patch is fine.
Comment 8 GCC Commits 2005-08-22 23:56:34 UTC
Subject: Bug 23426

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	wilson@gcc.gnu.org	2005-08-22 23:56:30

Modified files:
	gcc/cp         : ChangeLog 

Log message:
	Correct PR number in last patch checked in.
	PR tree-optimization/23426
	* decl.c (grokdeclarator): Use TYPE_SIZE_UNIT not TYPE_SIZE for
	array size check.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4855&r2=1.4856

Comment 9 GCC Commits 2005-08-23 00:08:28 UTC
Subject: Bug 23426

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	wilson@gcc.gnu.org	2005-08-23 00:07:48

Modified files:
	gcc/cp         : ChangeLog decl.c 

Log message:
	Partial fix for too large array problem.
	PR tree-optimization/23426
	* decl.c (grokdeclarator): Use TYPE_SIZE_UNIT not TYPE_SIZE for
	array size check.
	Backport from mainline
	2005-06-14  Roger Sayle  <roger@eyesopen.com>
	* decl.c (grokdeclarator): Only check TREE_OVERFLOW on INTEGER_CST.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.79&r2=1.4648.2.80
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1371.2.18&r2=1.1371.2.19

Comment 10 Jim Wilson 2005-08-23 00:10:45 UTC
I've added my patch to mainline and the gcc-4.0.x branch, but there is still the
problem that my testcase generates two errors when it should only generate one.
Comment 11 Andrew Pinski 2005-08-23 11:44:52 UTC
earth:~>gcc t.cc
t.cc: In function ‘int main()’:
t.cc:19: error: size of array ‘a’ is too large
t.cc:20: error: ‘a’ was not declared in this scope
earth:~>~/ia32_linux_gcc3_4/bin/gcc t.cc
t.cc: In function `int main()':
t.cc:19: error: size of variable 'a' is too large
earth:~>gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /home/peshtigo/pinskia/src/gnu/gcc/src/configure --target=i686-pc-linux-gnu --
host=i686-pc-linux-gnu --enable-__cxa_atexit --enable-languages=c++,objc,java,f95 --prefix=/
home/gates/pinskia/linux --enable-threads=posix --enable-shared
Thread model: posix
gcc version 4.1.0 20050823 (experimental)

So the error message is also a regression but that makes this minor as the first error message is 
correct.
Comment 12 Andrew Pinski 2005-10-27 01:56:00 UTC
I might have a fix for the two error messages, though it might also cause other issues, let see what happens in the test results.
Comment 13 Andrew Pinski 2005-10-27 14:01:17 UTC
(In reply to comment #12)
> I might have a fix for the two error messages, though it might also cause other
> issues, let see what happens in the test results.

It did not work.
Comment 14 Andrew Pinski 2005-10-28 03:57:06 UTC
Actually I figured out how to fix the problem with my patch, just moving around error mark node is what is needed here.
Comment 15 Andrew Pinski 2005-10-28 04:18:19 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2005-10/msg01599.html
Comment 16 Andrew Pinski 2005-10-28 14:50:59 UTC
Subject: Bug 23426

Author: pinskia
Date: Fri Oct 28 14:50:53 2005
New Revision: 105934

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=105934
Log:
2005-10-28  Andrew Pinski  <pinskia@physics.uc.edu>

	PR C++/23426
	* decl.c (start_decl): Check that the decl is an
	error_mark_node before getting the type.
	Remove the check for the decl's type being an
	error_mark_node.  

2005-10-28  Andrew Pinski  <pinskia@physics.uc.edu>

        PR C++/23426
        * g++.dg/other/large-size-array.C: New test.


Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/other/large-size-array.C
Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/decl.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 17 Andrew Pinski 2005-10-28 14:57:36 UTC
Subject: Bug 23426

Author: pinskia
Date: Fri Oct 28 14:57:30 2005
New Revision: 105936

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=105936
Log:
2005-10-28  Andrew Pinski  <pinskia@physics.uc.edu>

	PR C++/23426
	* decl.c (start_decl): Check that the decl is an
	error_mark_node before getting the type.
	Remove the check for the decl's type being an
	error_mark_node.  

2005-10-28  Andrew Pinski  <pinskia@physics.uc.edu>

        PR C++/23426
        * g++.dg/other/large-size-array.C: New test.


Added:
    trunk/gcc/testsuite/g++.dg/other/large-size-array.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog

Comment 18 Andrew Pinski 2005-10-28 14:57:57 UTC
Fixed in 4.0.3.