public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug exp/26875] New: Incorrect value printed for address of first element of zero-length array
@ 2020-11-13  9:32 vries at gcc dot gnu.org
  2020-11-13 10:33 ` [Bug exp/26875] " vries at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-13  9:32 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26875

            Bug ID: 26875
           Summary: Incorrect value printed for address of first element
                    of zero-length array
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: exp
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider test-case gdb.base/arrayidx.exp, augmented with fedora patch
https://src.fedoraproject.org/rpms/gdb/blob/master/f/gdb-archer-vla-tests.patch:
...
diff --git a/gdb/testsuite/gdb.base/arrayidx.c
b/gdb/testsuite/gdb.base/arrayidx.c
--- a/gdb/testsuite/gdb.base/arrayidx.c
+++ b/gdb/testsuite/gdb.base/arrayidx.c
@@ -17,6 +17,13 @@

 int array[] = {1, 2, 3, 4};

+#ifdef __GNUC__
+struct
+  {
+    int a[0];
+  } unbound;
+#endif
+
 int
 main (void)
 {
diff --git a/gdb/testsuite/gdb.base/arrayidx.exp
b/gdb/testsuite/gdb.base/arrayidx.exp
--- a/gdb/testsuite/gdb.base/arrayidx.exp
+++ b/gdb/testsuite/gdb.base/arrayidx.exp
@@ -49,4 +49,12 @@ gdb_test "print array" \
          "\\{\\\[0\\\] = 1, \\\[1\\\] = 2, \\\[2\\\] = 3, \\\[3\\\] = 4\\}" \
          "print array with array-indexes on"

-
+set test "p unbound.a == &unbound.a\[0\]"
+gdb_test_multiple $test $test {
+    -re " = 1\r\n$gdb_prompt $" {
+       pass $test
+    }
+    -re "No symbol \"unbound\" in current context.\r\n$gdb_prompt $" {
+       unsupported "$test (no GCC)"
+    }
+}
...

We run into this FAIL:
...
p unbound.a == &unbound.a[0]^M
$7 = 0^M
(gdb) FAIL: gdb.base/arrayidx.exp: p unbound.a == &unbound.a[0]
...

A bit more probing:
...
(gdb) p unbound
$3 = {a = 0x601044}
(gdb) p &unbound
$4 = (struct {...} *) 0x601044
(gdb) p unbound.a
$5 = 0x601044
(gdb) p &unbound.a[0]
$6 = (int *) 0xffffffffefc93d84^M
...
reveals that we have a problem printing the address of the first element of a
zero length array.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-10-13 14:22 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13  9:32 [Bug exp/26875] New: Incorrect value printed for address of first element of zero-length array vries at gcc dot gnu.org
2020-11-13 10:33 ` [Bug exp/26875] " vries at gcc dot gnu.org
2020-11-13 10:53 ` vries at gcc dot gnu.org
2020-11-13 14:47 ` vries at gcc dot gnu.org
2020-11-13 16:52 ` vries at gcc dot gnu.org
2020-11-14 11:45 ` vries at gcc dot gnu.org
2020-11-14 12:04 ` vries at gcc dot gnu.org
2020-11-20 18:00 ` simark at simark dot ca
2020-11-20 18:03 ` simark at simark dot ca
2020-11-20 18:07 ` simark at simark dot ca
2020-11-20 18:17 ` simark at simark dot ca
2020-11-20 22:16 ` vries at gcc dot gnu.org
2020-11-20 22:25 ` simark at simark dot ca
2020-11-23 16:25 ` simark at simark dot ca
2020-12-09 18:53 ` cvs-commit at gcc dot gnu.org
2020-12-09 21:34 ` cvs-commit at gcc dot gnu.org
2020-12-09 22:11 ` simark at simark dot ca
2021-10-13 14:22 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).