This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Track VLA bounds in VTA (PR debug/43150)


Hi!

Now that we have VLA debuginfo at -O0 fixed again, I think
it wouldn't hurt to have at least in most cases proper debug info
also for VLAs at -O1 and above.  Thanks to VTA this is achievable,
we just need to tell var-tracking that it should track such vars,
and gimplifier to clear DECL_IGNORED_P on the artificial vars not
just at -O0, but always.  It doesn't change generated optimized code,
just allows debug info to be emitted.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-02-23  Jakub Jelinek  <jakub@redhat.com>

	PR debug/43150
	* gimplify.c (gimplify_type_sizes): Clear DECL_IGNORED_P for VLA
	bounds even for -O+.
	* var-tracking.c (track_expr_p): If !need_rtl, don't mandate
	expr needs to have DECL_NAME set.

	* gcc.dg/guality/vla-1.c: New test.

--- gcc/gimplify.c.jj	2010-02-23 12:15:50.000000000 +0100
+++ gcc/gimplify.c	2010-02-23 14:00:53.000000000 +0100
@@ -7367,9 +7367,10 @@ gimplify_type_sizes (tree type, gimple_s
       /* These types may not have declarations, so handle them here.  */
       gimplify_type_sizes (TREE_TYPE (type), list_p);
       gimplify_type_sizes (TYPE_DOMAIN (type), list_p);
-      /* When not optimizing, ensure VLA bounds aren't removed.  */
-      if (!optimize
-	  && TYPE_DOMAIN (type)
+      /* Ensure VLA bounds aren't removed, for -O0 they should be variables
+	 with assigned stack slots, for -O1+ -g they should be tracked
+	 by VTA.  */
+      if (TYPE_DOMAIN (type)
 	  && INTEGRAL_TYPE_P (TYPE_DOMAIN (type)))
 	{
 	  t = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
--- gcc/var-tracking.c.jj	2010-02-23 12:15:38.000000000 +0100
+++ gcc/var-tracking.c	2010-02-23 13:56:42.000000000 +0100
@@ -4150,7 +4150,7 @@ track_expr_p (tree expr, bool need_rtl)
     return 0;
 
   /* It also must have a name...  */
-  if (!DECL_NAME (expr))
+  if (!DECL_NAME (expr) && need_rtl)
     return 0;
 
   /* ... and a RTL assigned to it.  */
--- gcc/testsuite/gcc.dg/guality/vla-1.c.jj	2010-02-23 14:26:01.000000000 +0100
+++ gcc/testsuite/gcc.dg/guality/vla-1.c	2010-02-23 14:16:47.000000000 +0100
@@ -0,0 +1,36 @@
+/* PR debug/43150 */
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+void __attribute__((noinline))
+bar (short *p)
+{
+  __builtin_memset (p, '\0', 17 * sizeof (*p));
+  asm volatile ("" : : "r" (p) : "memory");
+}
+
+int __attribute__((noinline))
+f1 (int i)
+{
+  char a[i + 1];
+  a[0] = 5;		/* { dg-final { gdb-test 17 "i" "5" } } */
+  return a[0];		/* { dg-final { gdb-test 17 "sizeof (a)" "6" } } */
+}
+
+int __attribute__((noinline))
+f2 (int i)
+{
+  short a[i * 2 + 7];	/* { dg-final { gdb-test 24 "i" "5" } } */
+  bar (a);		/* { dg-final { gdb-test 24 "sizeof (a)" "17 * sizeof (short)" } } */
+  return a[i + 4];
+}
+
+int
+main ()
+{
+  int i = 5;
+  asm volatile ("" : "=r" (i) : "0" (i));
+  f1 (i);
+  f2 (i);
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]