Bug 12913 - [4.0 Regression] Jumps into variable length array scope not rejected
Summary: [4.0 Regression] Jumps into variable length array scope not rejected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: 4.0.1
Assignee: Joseph S. Myers
URL:
Keywords: accepts-invalid, diagnostic, wrong-code
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2003-11-05 17:23 UTC by Falk Hueffner
Modified: 2005-04-22 14:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-19 23:53:18


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Falk Hueffner 2003-11-05 17:23:27 UTC
gcc does not reject jumps over the declaration of a variable length array:

void f(int l) { 
  goto label; 
  int a[l]; 
 label:; 
} 
    
void g (int l) {
  switch (l) {
  case 1:;
    int a[l];
  default:;
  }
}

gcc 3.3 rejects at least the first case with the pretty misleading error message

test.c:4: error: label `label' used before containing binding contour

but mainline accepts both.
Comment 1 Andrew Pinski 2003-11-08 16:44:17 UTC
In fact c++ front-end rejects only first one in 3.4 also.
Comment 2 Dara Hazeghi 2003-11-14 16:33:18 UTC
Mainline (20031107) has the same error message you got in 3.3. I certainly didn't find the 
message helpful though. Does mainline still accept this for you?
Comment 3 Falk Hueffner 2003-11-15 16:12:05 UTC
Mainline gives an error message for f1 now, but still not for f2.
Comment 4 Falk Hueffner 2003-11-15 16:15:56 UTC
Erm, I meant f and g, of course. And the misleading diagnostic worries me much
less than the accepts-invalid, which most likely will do something the user
didn't intend...
Comment 5 Andrew Pinski 2004-03-07 01:43:34 UTC
It is even worse (at least as I can see) on the tree-ssa because it will produce the 
following code:
  int a[l.1 * 4];
  void * saved_stack.3;
  long unsigned int T.2;
  long unsigned int l.1;
  int l.0;

<bb 0>:
  switch (l)
    {
      case 1: goto <L0>;
      default : goto <L1>;
    }

<L0>:;
  l.0 = 1;
  l.1 = (long unsigned int)l.0;
  T.2 = l.1 * 4;
  __builtin_stack_alloc (&a, T.2);

<L1>:;
  __builtin_stack_restore (saved_stack.3);
  return;

so it will try do restore even though it did not save anything.
Comment 6 Joseph S. Myers 2005-04-19 23:53:18 UTC
Testing a fix.  Note that the first case is a regression in 4.0 relative to
previous releases, so I'll propose the fix for 4.0.1.
Comment 7 CVS Commits 2005-04-20 16:42:13 UTC
Subject: Bug 12913

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2005-04-20 16:41:48

Modified files:
	gcc            : ChangeLog c-decl.c c-tree.h c-typeck.c 
	gcc/objc       : ChangeLog objc-act.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: c99-vla-jump-1.c c99-vla-jump-2.c 
	                      c99-vla-jump-3.c c99-vla-jump-4.c 
	                      c99-vla-jump-5.c 

Log message:
	PR c/12913
	* c-tree.h (struct c_label_list): Update comment.
	(struct c_label_context): Rename to struct c_label_context_se.
	(label_context_stack): Rename to label_context_stack_se.
	(C_DECL_UNJUMPABLE_VM, C_DECL_UNDEFINABLE_VM, struct
	c_label_context_vm, label_context_stack_vm, c_begin_vm_scope,
	c_end_vm_scope): New.
	(C_DECL_DECLARED_BUILTIN, C_DECL_USED): Use FUNCTION_DECL_CHECK.
	* c-decl.c (pop_scope): Call c_end_vm_scope.
	(pushdecl): Call c_begin_vm_scope for variably modified
	declarations.
	(define_label): Check for jumping into scope of identifier with
	variably modified type.  Push label on stack for those defined at
	current context of identifiers with variably modified type.
	(start_function): Create stack level for context of identifiers
	with variably modified type.
	(finish_function): Pop stack level for context of identifiers with
	variably modified type.
	* c-typeck.c (label_context_stack): Rename to
	label_context_stack_se.
	(label_context_stack_vm, c_begin_vm_scope, c_end_vm_scope): New.
	(c_finish_goto_label): Check for jumping into scope of identifier
	with variably modified type.  Push label on stack for those jumped
	to from current context of identifiers with variably modified
	type.
	(struct c_switch): Add blocked_vm.
	(c_start_case): Initialize blocked_vm.
	(do_case): Check blocked_vm.
	(c_finish_case): Add comment.
	(c_begin_stmt_expr, c_finish_stmt_expr): Update for renamed
	variable label_context_stack.
	
	objc:
	* objc-act.c (objc_start_function): Create stack level for context
	of identifiers with variably modified type.
	
	testsuite:
	* gcc.dg/c99-vla-jump-1.c, gcc.dg/c99-vla-jump-2.c,
	gcc.dg/c99-vla-jump-3.c, gcc.dg/c99-vla-jump-4.c,
	gcc.dg/c99-vla-jump-5.c: New tests.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8375&r2=2.8376
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.646&r2=1.647
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-tree.h.diff?cvsroot=gcc&r1=1.200&r2=1.201
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.433&r2=1.434
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/ChangeLog.diff?cvsroot=gcc&r1=1.32&r2=1.33
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/objc-act.c.diff?cvsroot=gcc&r1=1.269&r2=1.270
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5375&r2=1.5376
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-4.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-5.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 CVS Commits 2005-04-22 12:59:16 UTC
Subject: Bug 12913

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	jsm28@gcc.gnu.org	2005-04-22 12:58:43

Modified files:
	gcc            : ChangeLog c-decl.c c-tree.h c-typeck.c 
	gcc/objc       : ChangeLog objc-act.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: c99-vla-jump-1.c c99-vla-jump-2.c 
	                      c99-vla-jump-3.c c99-vla-jump-4.c 
	                      c99-vla-jump-5.c 

Log message:
	PR c/12913
	* c-tree.h (struct c_label_list): Update comment.
	(struct c_label_context): Rename to struct c_label_context_se.
	(label_context_stack): Rename to label_context_stack_se.
	(C_DECL_UNJUMPABLE_VM, C_DECL_UNDEFINABLE_VM, struct
	c_label_context_vm, label_context_stack_vm, c_begin_vm_scope,
	c_end_vm_scope): New.
	(C_DECL_DECLARED_BUILTIN, C_DECL_USED): Use FUNCTION_DECL_CHECK.
	* c-decl.c (pop_scope): Call c_end_vm_scope.
	(pushdecl): Call c_begin_vm_scope for variably modified
	declarations.
	(define_label): Check for jumping into scope of identifier with
	variably modified type.  Push label on stack for those defined at
	current context of identifiers with variably modified type.
	(start_function): Create stack level for context of identifiers
	with variably modified type.
	(finish_function): Pop stack level for context of identifiers with
	variably modified type.
	* c-typeck.c (label_context_stack): Rename to
	label_context_stack_se.
	(label_context_stack_vm, c_begin_vm_scope, c_end_vm_scope): New.
	(c_finish_goto_label): Check for jumping into scope of identifier
	with variably modified type.  Push label on stack for those jumped
	to from current context of identifiers with variably modified
	type.
	(struct c_switch): Add blocked_vm.
	(c_start_case): Initialize blocked_vm.
	(do_case): Check blocked_vm.
	(c_finish_case): Add comment.
	(c_begin_stmt_expr, c_finish_stmt_expr): Update for renamed
	variable label_context_stack.
	
	objc:
	* objc-act.c (objc_start_function): Create stack level for context
	of identifiers with variably modified type.
	
	testsuite:
	* gcc.dg/c99-vla-jump-1.c, gcc.dg/c99-vla-jump-2.c,
	gcc.dg/c99-vla-jump-3.c, gcc.dg/c99-vla-jump-4.c,
	gcc.dg/c99-vla-jump-5.c: New tests.

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.175&r2=2.7592.2.176
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.630.6.6&r2=1.630.6.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.193.4.2&r2=1.193.4.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.419.2.1&r2=1.419.2.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.29.8.2&r2=1.29.8.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/objc-act.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.266.6.1&r2=1.266.6.2
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.131&r2=1.5084.2.132
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-2.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-3.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-4.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-vla-jump-5.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 9 Andrew Pinski 2005-04-22 14:07:44 UTC
Fixed.