Bug 20760 - cast to variable-length array type combined with switch statement gives segv
Summary: cast to variable-length array type combined with switch statement gives segv
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 4.0.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2005-04-04 21:58 UTC by eabaltz
Modified: 2005-06-01 18:59 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-04-05 20:50:04


Attachments
preprocessed source (6.21 KB, application/x-tar)
2005-04-04 22:00 UTC, eabaltz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description eabaltz 2005-04-04 21:58:56 UTC
gcc -v:
Configured with: ../gcc-3.4.3/configure --prefix=/u/ki/eabaltz/usr/i386
Thread model: posix
gcc version 3.4.3

command line:
gcc -Wall --save-temps bug.c

this works:
./a.out 1

matrix[0][]:    1.0 -2.0 -3.0
matrix[1][]:    2.0  4.0 -6.0
matrix[2][]:    3.0  6.0  9.0

matrix[0][]:    1.0 -2.0 -3.0
matrix[1][]:    2.0  4.0 -6.0
matrix[2][]:    3.0  6.0  9.0

---

this doesn't:
./a.out 2

matrix[0][]:    1.0 -2.0 -3.0
matrix[1][]:    2.0  4.0 -6.0
matrix[2][]:    3.0  6.0  9.0

Segmentation fault (core dumped)
Comment 1 eabaltz 2005-04-04 22:00:28 UTC
Created attachment 8533 [details]
preprocessed source

Preprocessed source file illustrating the bug.
Comment 2 Andrew Pinski 2005-04-04 23:25:44 UTC
<L17>:;
  D.1897 = N - 1;
  D.1898 = (unsigned int) D.1897;
  N.23 = N;
  N.24 = (long unsigned int) N.23;
  D.1901 = D.1898 * N.24;
  D.1902 = D.1901 * 8;
  D.1903 = (double[0:(long unsigned int) (SAVE_EXPR <N.23> - 1)] *) D.1902;
  D.1904 = D.1903 + mp;
  param = (*D.1904)[0];
  goto <bb 20> (<L19>);

<L18>:;
  D.1905 = N - 1;
  D.1906 = (unsigned int) D.1905;
  N.25 = (long unsigned int) N.23;
  D.1908 = D.1906 * N.25;
  D.1909 = D.1908 * 8;
  D.1910 = (double[0:(long unsigned int) (SAVE_EXPR <N.23> - 1)] *) D.1909;
  D.1911 = D.1910 + mp;
  param = (*D.1911)[0];

See how N.23 is used in the second case but not defined.
Comment 3 Joseph S. Myers 2005-04-05 20:50:04 UTC
I'd like to get rid of the use of SAVE_EXPR for VLA sizes in C, but there may
well be a smaller local fix for this bug.
Comment 4 GCC Commits 2005-06-01 10:23:29 UTC
Subject: Bug 20760

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-06-01 10:23:17

Modified files:
	gcc            : ChangeLog gimplify.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: 20050527-1.c 

Log message:
	PR c/21536
	PR c/20760
	* gimplify.c (gimplify_decl_expr): Call gimplify_type_sizes
	on variable sizes types if a decl is a pointer to a VLA.
	(gimplify_type_sizes): Handle POINTER_TYPE and REFERENCE_TYPE.
	Call gimplify_type_sizes on aggregate fields.  Prevent infinite
	recursion.
	
	* gcc.dg/20050527-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8979&r2=2.8980
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&r1=2.129&r2=2.130
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5572&r2=1.5573
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20050527-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 GCC Commits 2005-06-01 10:36:01 UTC
Subject: Bug 20760

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	jakub@gcc.gnu.org	2005-06-01 10:35:49

Modified files:
	gcc            : ChangeLog gimplify.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: 20050527-1.c 

Log message:
	PR c/21536
	PR c/20760
	* gimplify.c (gimplify_decl_expr): Call gimplify_type_sizes
	on variable sizes types if a decl is a pointer to a VLA.
	(gimplify_type_sizes): Handle POINTER_TYPE and REFERENCE_TYPE.
	Call gimplify_type_sizes on aggregate fields.  Prevent infinite
	recursion.
	
	* gcc.dg/20050527-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.273&r2=2.7592.2.274
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.113.2.4&r2=2.113.2.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.216&r2=1.5084.2.217
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20050527-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 6 Andrew Pinski 2005-06-01 18:59:26 UTC
Fixed.