329bfe1
From 30c13da4efe18f43ee34aa4b29bc86e1a53de548 Mon Sep 17 00:00:00 2001
329bfe1
From: Jan Kratochvil <jkratoch@host1.dyn.jankratochvil.net>
329bfe1
Date: Thu, 11 Jun 2009 00:23:54 +0200
329bfe1
Subject: [PATCH] cherry-pick: Fix dereferencing unbound C arrays (RHBZ#505163).
329bfe1
329bfe1
gdb/
329bfe1
	* gdbtypes.c (get_discrete_bounds): Remove the VLA-introduced check for
329bfe1
	TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED and
329bfe1
	TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED.
329bfe1
329bfe1
gdb/testsuite/
329bfe1
	* gdb.base/arrayidx.c (unbound): New variable.
329bfe1
	* gdb.base/arrayidx.exp (p unbound.a == &unbound.a[0]): New test.
329bfe1
---
329bfe1
 gdb/gdbtypes.c                      |    3 ---
329bfe1
 gdb/testsuite/gdb.base/arrayidx.c   |    7 +++++++
329bfe1
 gdb/testsuite/gdb.base/arrayidx.exp |   10 +++++++++-
329bfe1
 3 files changed, 16 insertions(+), 4 deletions(-)
329bfe1
329bfe1
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
329bfe1
index 012485c..9899727 100644
329bfe1
--- a/gdb/gdbtypes.c
329bfe1
+++ b/gdb/gdbtypes.c
329bfe1
@@ -769,9 +769,6 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
329bfe1
   switch (TYPE_CODE (type))
329bfe1
     {
329bfe1
     case TYPE_CODE_RANGE:
329bfe1
-      if (TYPE_RANGE_UPPER_BOUND_IS_UNDEFINED (type) 
329bfe1
-	  || TYPE_RANGE_LOWER_BOUND_IS_UNDEFINED (type))
329bfe1
-	return -1;
329bfe1
       *lowp = TYPE_LOW_BOUND (type);
329bfe1
       *highp = TYPE_HIGH_BOUND (type);
329bfe1
       return 1;
329bfe1
diff --git a/gdb/testsuite/gdb.base/arrayidx.c b/gdb/testsuite/gdb.base/arrayidx.c
329bfe1
index 98d4d35..f98a656 100644
329bfe1
--- a/gdb/testsuite/gdb.base/arrayidx.c
329bfe1
+++ b/gdb/testsuite/gdb.base/arrayidx.c
329bfe1
@@ -17,6 +17,13 @@
329bfe1
 
329bfe1
 int array[] = {1, 2, 3, 4};
329bfe1
 
329bfe1
+#ifdef __GNUC__
329bfe1
+struct
329bfe1
+  {
329bfe1
+    int a[0];
329bfe1
+  } unbound;
329bfe1
+#endif
329bfe1
+
329bfe1
 int
329bfe1
 main (void)
329bfe1
 {
329bfe1
diff --git a/gdb/testsuite/gdb.base/arrayidx.exp b/gdb/testsuite/gdb.base/arrayidx.exp
329bfe1
index 71ce4aa..af0e5f8 100644
329bfe1
--- a/gdb/testsuite/gdb.base/arrayidx.exp
329bfe1
+++ b/gdb/testsuite/gdb.base/arrayidx.exp
329bfe1
@@ -59,4 +59,12 @@ gdb_test "print array" \
329bfe1
          "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
329bfe1
          "Print array with array-indexes on"
329bfe1
 
329bfe1
-
329bfe1
+set test "p unbound.a == &unbound.a\[0\]"
329bfe1
+gdb_test_multiple $test $test {
329bfe1
+    -re " = 1\r\n$gdb_prompt $" {
329bfe1
+	pass $test
329bfe1
+    }
329bfe1
+    -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
329bfe1
+	unsupported "$test (no GCC)"
329bfe1
+    }
329bfe1
+}
329bfe1
-- 
329bfe1
1.6.0.6
329bfe1