Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch/rfc] Test struct0
@ 2004-02-04  0:06 Andrew Cagney
  2004-02-04  0:46 ` Daniel Jacobowitz
  2004-02-10 21:07 ` Andrew Cagney
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Cagney @ 2004-02-04  0:06 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

Hello,

This adds a test for:

	struct foo0 { };

to the structs.exp testcase (I'm assuming that this is legal ISO-C), it 
passes on PPC with stabs with:

> (gdb) PASS: gdb.base/structs.exp: ptype foo1; structs-tc
> p/c fun0()
> $1 = {<No data fields>}

Tt was intended for completness, however with a dwarf2 compiler:

amd64$ gcc --version
gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-24)

> (gdb) PASS: gdb.base/structs.exp: ptype foo1; structs-tc
> p/c fun0()
> $1 = <incomplete type>

I guess I should file a bug report and kfail it?

Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 2696 bytes --]

2004-02-03  Andrew Cagney  <cagney@redhat.com>

	* gdb.base/structs.c (struct struct0): Define.
	(foo0, L0): New variables.
	(fun0, Fun0): New functions.
	(main): Call fun0 and Fun0.
	* gdb.base/structs.exp: Test zero sized structure.
	(foo): Add output from an empty struct.  

Index: testsuite/gdb.base/structs.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/structs.c,v
retrieving revision 1.5
diff -u -r1.5 structs.c
--- testsuite/gdb.base/structs.c	20 Nov 2003 17:11:55 -0000	1.5
+++ testsuite/gdb.base/structs.c	3 Feb 2004 23:34:47 -0000
@@ -86,6 +86,7 @@
 typedef tQ tR;
 #endif
 
+struct  struct0 {};
 struct  struct1 {tA a;};
 struct  struct2 {tA a; tB b;};
 struct  struct3 {tA a; tB b; tC c; };
@@ -105,6 +106,7 @@
 struct struct17 {tA a; tB b; tC c; tD d; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; tM m; tN n; tO o; tP p; tQ q; };
 struct struct18 {tA a; tB b; tC c; tD d; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; tM m; tN n; tO o; tP p; tQ q; tR r; };
 
+struct  struct0  foo0 = {}, L0;
 struct  struct1  foo1 = {'1'}, L1;
 struct  struct2  foo2 = {'a','2'}, L2;
 struct  struct3  foo3 = {'1','b','3'}, L3;
@@ -124,6 +126,10 @@
 struct struct17 foo17 = {'1','b','3','d','5','f','7','h','9','j','B','l','D','n','F','p','H'}, L17;
 struct struct18 foo18 = {'a','2','c','4','e','6','g','8','i','A','k','C','m','E','o','G','q','I'}, L18;
 
+struct struct0  fun0()
+{
+  return foo0;  
+}
 struct struct1  fun1()
 {
   return foo1;  
@@ -198,6 +204,15 @@
 }
 
 #ifdef PROTOTYPES
+void Fun0(struct struct0 foo0)
+#else
+void Fun0(foo0)
+     struct struct0 foo0;
+#endif
+{
+  L0 = foo0;
+}
+#ifdef PROTOTYPES
 void Fun1(struct struct1 foo1)
 #else
 void Fun1(foo1)
@@ -408,6 +423,7 @@
 #endif
   int i;
 
+  Fun0(foo0);	
   Fun1(foo1);	
   Fun2(foo2);	
   Fun3(foo3);	
@@ -435,6 +451,7 @@
   while (1)
     {
       zed ();
+      L0  = fun0();	
       L1  = fun1();	
       L2  = fun2();	
       L3  = fun3();	
Index: testsuite/gdb.base/structs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/structs.exp,v
retrieving revision 1.17
diff -u -r1.17 structs.exp
--- testsuite/gdb.base/structs.exp	4 Jan 2004 15:04:41 -0000	1.17
+++ testsuite/gdb.base/structs.exp	3 Feb 2004 23:34:47 -0000
@@ -118,7 +118,7 @@
 
 proc foo { n } {
     return [lindex {
-	"{}"
+	"{<No data fields>}"
 	"{a = 49 '1'}"
 	"{a = 97 'a', b = 50 '2'}"
 	"{a = 49 '1', b = 98 'b', c = 51 '3'}"
@@ -481,6 +481,7 @@
 # original "structs" test was doing.
 
 start_structs_test { tc }
+test_struct_calls 0
 test_struct_calls 1
 test_struct_calls 2
 test_struct_calls 3

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

* Re: [patch/rfc] Test struct0
  2004-02-04  0:06 [patch/rfc] Test struct0 Andrew Cagney
@ 2004-02-04  0:46 ` Daniel Jacobowitz
  2004-02-04  1:34   ` Joel Brobecker
  2004-02-04 15:52   ` Andrew Cagney
  2004-02-10 21:07 ` Andrew Cagney
  1 sibling, 2 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2004-02-04  0:46 UTC (permalink / raw)
  To: gdb-patches

On Tue, Feb 03, 2004 at 07:06:47PM -0500, Andrew Cagney wrote:
> Hello,
> 
> This adds a test for:
> 
> 	struct foo0 { };
> 
> to the structs.exp testcase (I'm assuming that this is legal ISO-C), it 

Nope.

      struct-or-union-specifier:
           struct-or-union identifier-opt { struct-declaration-list }
           struct-or-union identifier

      struct-or-union:
           struct
           union

      struct-declaration-list:
           struct-declaration
           struct-declaration-list struct-declaration

      struct-declaration:
           specifier-qualifier-list struct-declarator-list ;

So there must be a minimum of one declarator and trailing semicolon
inside the braces.  GCC will warn about this if you ask it to - it's
probably -ansi, or -std=c89 -ansi -pedantic.

While it's not legal C, I believe that it is legal C++.

> passes on PPC with stabs with:
> 
> >(gdb) PASS: gdb.base/structs.exp: ptype foo1; structs-tc
> >p/c fun0()
> >$1 = {<No data fields>}
> 
> Tt was intended for completness, however with a dwarf2 compiler:
> 
> amd64$ gcc --version
> gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-24)
> 
> >(gdb) PASS: gdb.base/structs.exp: ptype foo1; structs-tc
> >p/c fun0()
> >$1 = <incomplete type>
> 
> I guess I should file a bug report and kfail it?

If you want to add the test anyway and run it where it compiles, then
yeah.  I assume this runs afoul of the handling for declarations/opaque
types.  It would be nice to support it even if it's a GNU extension.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: [patch/rfc] Test struct0
  2004-02-04  0:46 ` Daniel Jacobowitz
@ 2004-02-04  1:34   ` Joel Brobecker
  2004-02-04 15:52   ` Andrew Cagney
  1 sibling, 0 replies; 6+ messages in thread
From: Joel Brobecker @ 2004-02-04  1:34 UTC (permalink / raw)
  To: gdb-patches

> While it's not legal C, I believe that it is legal C++.

And the equivalent is legal in Ada too.

    (We have two equivalent forms:

           type Empty is record
           end record;

     or a shorter version:

           type Empty is null record;
    )

I was about to have a look at this for us, actually. So if we
open a PR, it can be assigned to me.

-- 
Joel


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

* Re: [patch/rfc] Test struct0
  2004-02-04  0:46 ` Daniel Jacobowitz
  2004-02-04  1:34   ` Joel Brobecker
@ 2004-02-04 15:52   ` Andrew Cagney
  2004-02-04 15:59     ` Daniel Jacobowitz
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2004-02-04 15:52 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

> On Tue, Feb 03, 2004 at 07:06:47PM -0500, Andrew Cagney wrote:
> 
>> Hello,
>> 
>> This adds a test for:
>> 
>> 	struct foo0 { };
>> 
>> to the structs.exp testcase (I'm assuming that this is legal ISO-C), it 
> 
> 
> Nope.

I guess I misunderstood Jim's comments.
http://sources.redhat.com/ml/gdb-patches/2004-01/msg00717.html

>       struct-or-union-specifier:
>            struct-or-union identifier-opt { struct-declaration-list }
>            struct-or-union identifier
> 
>       struct-or-union:
>            struct
>            union
> 
>       struct-declaration-list:
>            struct-declaration
>            struct-declaration-list struct-declaration
> 
>       struct-declaration:
>            specifier-qualifier-list struct-declarator-list ;
> 
> So there must be a minimum of one declarator and trailing semicolon
> inside the braces.  GCC will warn about this if you ask it to - it's
> probably -ansi, or -std=c89 -ansi -pedantic.

> While it's not legal C, I believe that it is legal C++.

But are you sure?  :-)  If it's legal C++ then it, along with some other 
wierd-o edge cases should probably be added to a gdb.cp/struct0 test 
(someone with less rusty C++ than me can probably come up with a list).

Trying to include it in structs.exp would just be too messy.

Andrew



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

* Re: [patch/rfc] Test struct0
  2004-02-04 15:52   ` Andrew Cagney
@ 2004-02-04 15:59     ` Daniel Jacobowitz
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2004-02-04 15:59 UTC (permalink / raw)
  To: gdb-patches

On Wed, Feb 04, 2004 at 10:52:09AM -0500, Andrew Cagney wrote:
> >On Tue, Feb 03, 2004 at 07:06:47PM -0500, Andrew Cagney wrote:
> >
> >>Hello,
> >>
> >>This adds a test for:
> >>
> >>	struct foo0 { };
> >>
> >>to the structs.exp testcase (I'm assuming that this is legal ISO-C), it 
> >
> >
> >Nope.
> 
> I guess I misunderstood Jim's comments.
> http://sources.redhat.com/ml/gdb-patches/2004-01/msg00717.html

Hmm, the comment isn't very clear.  Yes, this is a GNU extension
(though not many people seem to know it).

> >      struct-or-union-specifier:
> >           struct-or-union identifier-opt { struct-declaration-list }
> >           struct-or-union identifier
> >
> >      struct-or-union:
> >           struct
> >           union
> >
> >      struct-declaration-list:
> >           struct-declaration
> >           struct-declaration-list struct-declaration
> >
> >      struct-declaration:
> >           specifier-qualifier-list struct-declarator-list ;
> >
> >So there must be a minimum of one declarator and trailing semicolon
> >inside the braces.  GCC will warn about this if you ask it to - it's
> >probably -ansi, or -std=c89 -ansi -pedantic.
> 
> >While it's not legal C, I believe that it is legal C++.
> 
> But are you sure?  :-)  If it's legal C++ then it, along with some other 
> wierd-o edge cases should probably be added to a gdb.cp/struct0 test 
> (someone with less rusty C++ than me can probably come up with a list).
> 
> Trying to include it in structs.exp would just be too messy.

Yeah.  Of course, there's the interesting property that zero-element
structures have non-zero size in C++.  That's because they're a
first-class part of the language.  Consider:

struct foo { };
struct foo bar[10];

int baz = sizeof (bar);

In GNU C, baz is initialized to zero.  In GNU C++ (i386-linux, but I
think all targets since the v3 ABI covers this), baz is initialized to
ten.  One byte per zero-sized struct is wasted in order to preserve
monotonically increasing array element addresses.  Then, in some cases
(all dealing with base classes), the one byte is optimized away again.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: [patch/rfc] Test struct0
  2004-02-04  0:06 [patch/rfc] Test struct0 Andrew Cagney
  2004-02-04  0:46 ` Daniel Jacobowitz
@ 2004-02-10 21:07 ` Andrew Cagney
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Cagney @ 2004-02-10 21:07 UTC (permalink / raw)
  To: gdb-patches

> Hello,
> 
> This adds a test for:
> 
>     struct foo0 { };
> 
> to the structs.exp testcase (I'm assuming that this is legal ISO-C), it passes on PPC with stabs with:
> 
> (gdb) PASS: gdb.base/structs.exp: ptype foo1; structs-tc
> p/c fun0()
> $1 = {<No data fields>}
> 
> Tt was intended for completness, however with a dwarf2 compiler:
> 
> amd64$ gcc --version
> gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-24)
> 
> (gdb) PASS: gdb.base/structs.exp: ptype foo1; structs-tc
> p/c fun0()
> $1 = <incomplete type>
> 
> I guess I should file a bug report and kfail it?

I'm dropping this patch - it isn't valid C.  If someone want's to come 
up with a C++ equivalent, feel free.

Andrew



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

end of thread, other threads:[~2004-02-10 21:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-04  0:06 [patch/rfc] Test struct0 Andrew Cagney
2004-02-04  0:46 ` Daniel Jacobowitz
2004-02-04  1:34   ` Joel Brobecker
2004-02-04 15:52   ` Andrew Cagney
2004-02-04 15:59     ` Daniel Jacobowitz
2004-02-10 21:07 ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox