Bug 19771 - VLA deallocation
Summary: VLA deallocation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on: 23848
Blocks: 16989
  Show dependency treegraph
 
Reported: 2005-02-03 01:38 UTC by Joseph S. Myers
Modified: 2009-04-19 20:21 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0
Known to fail: 3.3.3 4.0.0
Last reconfirmed: 2005-12-18 01:38:47


Attachments
Always create a new BIND_EXPR for VLA decls (1.43 KB, patch)
2009-03-29 22:36 UTC, Steven Bosscher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph S. Myers 2005-02-03 01:38:53 UTC
VLAs should be deallocated on a jump to before their definition, including
a jump to a label in an inner scope.

void *volatile p;
   
int
main (void)
{
  int n = 0;
  if (0)
    {
    lab:;
    }
  int x[n % 1000 + 1];
  x[0] = 1;
  x[n % 1000] = 2;
  p = x;
  n++;
  if (n < 1000000)
    goto lab;
  return 0;
}  

should execute successfully.

(Mentioned in <http://gcc.gnu.org/ml/gcc-patches/2004-08/msg00738.html>.)
Comment 1 Andrew Pinski 2005-02-03 02:35:43 UTC
Confirmed.
Comment 2 Richard Henderson 2005-02-12 00:09:27 UTC
The problem here is that the C front end is not creating a new BIND_EXPR
for the scope starting at the declaration for X.  Insert one by hand and
you'll see that the tree optimizers are doing the right thing.
Comment 3 Steven Bosscher 2009-03-29 22:36:57 UTC
Created attachment 17557 [details]
Always create a new BIND_EXPR for VLA decls

I tried to make use of scopes: If a label is defined in a parent scope, start a new BIND_EXPR.  This did not work.

So the attached patch takes the brute-force approach.  When optimizing, this _should_ not hurt, but we get two __builtin_stack_restore calls now.  Apparently Jakub's PR23848 fix doesn't work for our case.

Anyway, this patch does, of course, make the test case of comment #0 run.
Comment 4 Steven Bosscher 2009-03-29 22:38:05 UTC
Jakub, this is what we discussed last night.
Comment 5 Joseph S. Myers 2009-04-19 20:20:12 UTC
Subject: Bug 19771

Author: jsm28
Date: Sun Apr 19 20:19:54 2009
New Revision: 146358

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146358
Log:
	PR c/19771
	* c-semantics.c (pop_stmt_list): Propagate
	STATEMENT_LIST_HAS_LABEL to parent statement list.

testsuite:
	* gcc.c-torture/execute/vla-dealloc-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/vla-dealloc-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-semantics.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Joseph S. Myers 2009-04-19 20:21:16 UTC
Fixed for 4.5.