]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
CTF: handle forward reference type
authorWeimin Pan <weimin.pan@oracle.com>
Sun, 16 May 2021 22:24:14 +0000 (18:24 -0400)
committerWeimin Pan <weimin.pan@oracle.com>
Sun, 16 May 2021 22:24:14 +0000 (18:24 -0400)
The problems can be illustrated, with any program, below:

(gdb) print main
$1 = {main} 0x0

The return type was incorrectly set in read_func_kind_type, with
the name of the function, which leads c_type_print_base_1 to print
it. In addition, the address of a new function needs to be set with
that info in its minimal symtab entry, when the new function is added.

After the fix:

(gdb) print main
$1 = {int ()} 0x4004b7 <main>

A new test, gdb.ctf/funcreturn.exp, is added to the testsuite.

gdb/ChangeLog:
        * ctfread.c (new_symbol): Set function address.
        (read_func_kind_type): Remove incorrect type name setting.
        Don't copy name returned from ctf_type_ame_raw throughout file.

gdb/testsuite/ChangeLog:
        * gdb.ctf/funcreturn.exp: New file.
        * gdb.ctf/whatis.c: Copy from gdb.base.

gdb/ChangeLog
gdb/ctfread.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ctf/funcreturn.exp [new file with mode: 0644]
gdb/testsuite/gdb.ctf/whatis.c [new file with mode: 0644]

index 8e1e00250b89477f81ea41652ec2bc92ae014218..81e9dd5a29cd65acb149cd26fba23ff2b6de1138 100644 (file)
@@ -1,3 +1,9 @@
+2021-05-16  Weimin Pan  <weimin.pan@oracle.com>
+
+       * ctfread.c (new_symbol): Set function address.
+       (read_func_kind_type): Remove incorrect type name setting.
+       Don't copy name returned from ctf_type_ame_raw throughout file.
+
 2021-05-14  Tom Tromey  <tom@tromey.com>
 
        * rust-lang.c (rust_language::val_print_struct)
index e2b65b622de20d6f5a0268931a64371264fba101..23e859a3b1ce92e9dff6d2b7c26a6cd289420d8b 100644 (file)
@@ -462,14 +462,14 @@ new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
   ctf_dict_t *fp = ccp->fp;
   struct symbol *sym = nullptr;
 
-  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
+  const char *name = ctf_type_name_raw (fp, tid);
   if (name != nullptr)
     {
       sym = new (&objfile->objfile_obstack) symbol;
       OBJSTAT (objfile, n_syms++);
 
       sym->set_language (language_c, &objfile->objfile_obstack);
-      sym->compute_and_set_names (name.get (), true, objfile->per_bfd);
+      sym->compute_and_set_names (name, false, objfile->per_bfd);
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
 
@@ -487,6 +487,7 @@ new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
            break;
          case CTF_K_FUNCTION:
            SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
+           set_symbol_address (objfile, sym, sym->linkage_name ());
            break;
          case CTF_K_CONST:
            if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_VOID)
@@ -525,7 +526,7 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid)
   ctf_dict_t *fp = ccp->fp;
   ctf_encoding_t cet;
   struct type *type = nullptr;
-  char *name;
+  const char *name;
   uint32_t kind;
 
   if (ctf_type_encoding (fp, tid, &cet))
@@ -535,16 +536,14 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid)
       return nullptr;
     }
 
-  gdb::unique_xmalloc_ptr<char> copied_name (ctf_type_aname_raw (fp, tid));
-  if (copied_name == nullptr || strlen (copied_name.get ()) == 0)
+  name = ctf_type_name_raw (fp, tid);
+  if (name == nullptr || strlen (name) == 0)
     {
       name = ctf_type_aname (fp, tid);
       if (name == nullptr)
        complaint (_("ctf_type_aname read_base_type failed - %s"),
                   ctf_errmsg (ctf_errno (fp)));
     }
-  else
-    name = obstack_strdup (&of->objfile_obstack, copied_name.get ());
 
   kind = ctf_type_kind (fp, tid);
   if (kind == CTF_K_INTEGER)
@@ -623,9 +622,9 @@ read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
 
   type = alloc_type (of);
 
-  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != nullptr && strlen (name.get ()) != 0)
-    type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
+  const char *name = ctf_type_name_raw (fp, tid);
+  if (name != nullptr && strlen (name) != 0)
+    type->set_name (name);
 
   kind = ctf_type_kind (fp, tid);
   if (kind == CTF_K_UNION)
@@ -682,10 +681,6 @@ read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid)
 
   type = alloc_type (of);
 
-  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != nullptr && strlen (name.get ()) != 0)
-    type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
-
   type->set_code (TYPE_CODE_FUNC);
   ctf_func_type_info (fp, tid, &cfi);
   rettype = fetch_tid_type (ccp, cfi.ctc_return);
@@ -734,9 +729,9 @@ read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
 
   type = alloc_type (of);
 
-  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != nullptr && strlen (name.get ()) != 0)
-    type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
+  const char *name = ctf_type_name_raw (fp, tid);
+  if (name != nullptr && strlen (name) != 0)
+    type->set_name (name);
 
   type->set_code (TYPE_CODE_ENUM);
   TYPE_LENGTH (type) = ctf_type_size (fp, tid);
@@ -972,9 +967,9 @@ read_forward_type (struct ctf_context *ccp, ctf_id_t tid)
 
   type = alloc_type (of);
 
-  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != NULL && strlen (name.get()) != 0)
-    type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
+  const char *name = ctf_type_name_raw (fp, tid);
+  if (name != nullptr && strlen (name) != 0)
+    type->set_name (name);
 
   kind = ctf_type_kind_forwarded (fp, tid);
   if (kind == CTF_K_UNION)
@@ -1017,9 +1012,9 @@ read_type_record (struct ctf_context *ccp, ctf_id_t tid)
        break;
       case CTF_K_TYPEDEF:
        {
-         gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
+         const char *name = ctf_type_name_raw (fp, tid);
          btid = ctf_type_reference (fp, tid);
-         type = read_typedef_type (ccp, tid, btid, name.get ());
+         type = read_typedef_type (ccp, tid, btid, name);
        }
        break;
       case CTF_K_VOLATILE:
@@ -1444,7 +1439,6 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
   short section = -1;
 
   ccp = (struct ctf_context *) arg;
-  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (ccp->fp, tid));
 
   domain_enum domain = UNDEF_DOMAIN;
   enum address_class aclass = LOC_UNDEF;
@@ -1486,10 +1480,11 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
        return 0;
     }
 
-  if (name == nullptr || strlen (name.get ()) == 0)
+  const char *name = ctf_type_name_raw (ccp->fp, tid);
+  if (name == nullptr || strlen (name) == 0)
     return 0;
 
-  ccp->pst->add_psymbol (name.get (), true,
+  ccp->pst->add_psymbol (name, false,
                         domain, aclass, section,
                         psymbol_placement::GLOBAL,
                         0, language_c, ccp->partial_symtabs, ccp->of);
@@ -1545,7 +1540,7 @@ scan_partial_symbols (ctf_dict_t *cfp, psymtab_storage *partial_symtabs,
        else
          continue;
        }
-      gdb::unique_xmalloc_ptr<char> tname (ctf_type_aname_raw (cfp, tid));
+      const char *tname = ctf_type_name_raw (cfp, tid);
       uint32_t kind = ctf_type_kind (cfp, tid);
       address_class aclass;
       domain_enum tdomain;
@@ -1568,7 +1563,7 @@ scan_partial_symbols (ctf_dict_t *cfp, psymtab_storage *partial_symtabs,
       else
        aclass = LOC_TYPEDEF;
 
-      pst->add_psymbol (tname.get (), true,
+      pst->add_psymbol (tname, false,
                        tdomain, aclass, -1,
                        psymbol_placement::STATIC,
                        0, language_c, partial_symtabs, of);
index c7e7152eee08f46982cd3302e5bd4b8da9b10b47..0a8e5b202b0237bc2c9dbf91ecd1b0a0aa827d10 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-16  Weimin Pan  <weimin.pan@oracle.com>
+
+       * gdb.ctf/funcreturn.exp: New file.
+       * gdb.ctf/whatis.c: Copy from gdb.base.
+
 2021-05-14  Tom Tromey  <tom@tromey.com>
 
        * gdb.rust/pp.exp: New file.
diff --git a/gdb/testsuite/gdb.ctf/funcreturn.exp b/gdb/testsuite/gdb.ctf/funcreturn.exp
new file mode 100644 (file)
index 0000000..874160e
--- /dev/null
@@ -0,0 +1,190 @@
+# Copyright 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if [skip_ctf_tests] {
+    unsupported "no CTF debug format support, or CTF disabled in GDB"
+    return 0
+}
+
+if [target_info exists no_long_long] {
+    set exec_opts [list debug additional_flags=-DNO_LONG_LONG]
+} else {
+    set exec_opts [list debug]
+}
+
+standard_testfile whatis.c
+
+# Using `-gt` generates full-fledged CTF debug information.
+set opts "additional_flags=-gt -Wl,--export-dynamic"
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+         [list $srcfile] [list $opts nowarnings]] } {
+    return 0
+}
+
+# Create and source the file that provides information about the compiler
+# used to compile the test case.
+if [get_compiler_info] {
+    return -1
+}
+
+# test print command with functions return type
+set void "(void|)"
+gdb_test "print v_char_func" \
+    "$decimal = \{char \\(\\)\} 0x\[0-9a-z\]+ <v_char_func>.*" \
+    "print char function"
+
+gdb_test "print v_signed_char_func" \
+    "$decimal = \{signed char \\(\\)\} 0x\[0-9a-z\]+ <v_signed_char_func>.*" \
+    "print signed char function"
+
+gdb_test "print v_unsigned_char_func" \
+    "$decimal = \{unsigned char \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_char_func>.*" \
+    "print unsigned char function"
+
+gdb_test "print v_short_func" \
+    "$decimal = \{short \\(\\)\} 0x\[0-9a-z\]+ <v_short_func>.*" \
+    "print short function"
+
+gdb_test "print v_signed_short_func" \
+    "$decimal = \{signed short|short \\(\\)\} 0x\[0-9a-z\]+ <v_signed_short_func>.*" \
+    "print signed short function"
+
+gdb_test "print v_unsigned_short_func" \
+    "$decimal = \{unsigned short \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_short_func>.*" \
+    "print unsigned short function"
+
+gdb_test "print v_int_func" \
+    "$decimal = \{int \\(\\)\} 0x\[0-9a-z\]+ <v_int_func>.*" \
+    "print int function"
+
+gdb_test "print v_signed_int_func" \
+    "$decimal = \{signed int|int \\(\\)\} 0x\[0-9a-z\]+ <v_signed_int_func>.*" \
+    "print signed int function"
+
+gdb_test "print v_unsigned_int_func" \
+    "$decimal = \{unsigned int \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_int_func>.*" \
+    "print unsigned int function"
+
+gdb_test "print v_long_func" \
+    "$decimal = \{long \\(\\)\} 0x\[0-9a-z\]+ <v_long_func>.*" \
+    "print long function"
+
+gdb_test "print v_signed_long_func" \
+    "$decimal = \{signed long|long \\(\\)\} 0x\[0-9a-z\]+ <v_signed_long_func>.*" \
+    "print signed long function"
+
+gdb_test "print v_unsigned_long_func" \
+    "$decimal = \{unsigned long|long \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_long_func>.*" \
+    "print unsigned long function"
+
+if ![target_info exists no_long_long] {
+    gdb_test "print v_long_long_func" \
+           "$decimal = \{long long \\(\\)\} 0x\[0-9a-z\]+ <v_long_long_func>.*" \
+               "print long long function"
+
+    gdb_test "print v_signed_long_long_func" \
+           "$decimal = \{long long \\(\\)\} 0x\[0-9a-z\]+ <v_signed_long_long_func>.*" \
+               "print signed long long function"
+
+    gdb_test "print v_unsigned_long_long_func" \
+           "$decimal = \{unsigned long long \\(\\)\} 0x\[0-9a-z\]+ <v_unsigned_long_long_func>.*" \
+               "print unsigned long long function"
+}
+
+# Sun /bin/cc calls this a function returning double.
+if {!$gcc_compiled} then {setup_xfail "*-sun-sunos4*"}
+       gdb_test "print v_float_func" \
+           "$decimal = \{float \\(\\)\} 0x\[0-9a-z\]+.*" \
+           "print float function"
+
+       gdb_test "print v_double_func" \
+           "$decimal = \{double \\(\\)\} 0x\[0-9a-z\]+.*" \
+           "print double function" \
+}
+
+# test whatis command with functions return type
+gdb_test "whatis v_char_func" \
+    "type = (signed |unsigned |)char \\($void\\)" \
+    "whatis char function"
+
+gdb_test "whatis v_signed_char_func" \
+    "type = (signed |unsigned |)char \\($void\\)" \
+    "whatis signed char function"
+
+gdb_test "whatis v_unsigned_char_func" \
+    "type = unsigned char \\($void\\)" \
+    "whatis unsigned char function"
+
+gdb_test "whatis v_short_func" \
+    "type = short (int |)\\($void\\)" \
+    "whatis short function"
+
+gdb_test "whatis v_signed_short_func" \
+    "type = (signed |)short (int |)\\($void\\)" \
+    "whatis signed short function"
+
+gdb_test "whatis v_unsigned_short_func" \
+    "type = (unsigned short|short unsigned int) \\($void\\)" \
+    "whatis unsigned short function"
+
+gdb_test "whatis v_int_func" \
+    "type = int \\($void\\)" \
+    "whatis int function"
+
+gdb_test "whatis v_signed_int_func" \
+    "type = (signed |)int \\($void\\)" \
+    "whatis signed int function"
+
+gdb_test "whatis v_unsigned_int_func" \
+    "type = unsigned int \\($void\\)" \
+    "whatis unsigned int function"
+
+gdb_test "whatis v_long_func" \
+    "type = (long|int|long int) \\($void\\)" \
+    "whatis long function"
+
+gdb_test "whatis v_signed_long_func" \
+    "type = (signed |)(int|long|long int) \\($void\\)" \
+    "whatis signed long function"
+
+gdb_test "whatis v_unsigned_long_func" \
+    "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
+    "whatis unsigned long function"
+
+if ![target_info exists no_long_long] {
+    gdb_test "whatis v_long_long_func" \
+       "type = long long(| int) \\($void\\)" \
+       "whatis long long function"
+
+    gdb_test "whatis v_signed_long_long_func" \
+       "type = (signed |)long long(| int) \\($void\\)" \
+       "whatis signed long long function"
+
+    gdb_test "whatis v_unsigned_long_long_func" \
+       "type = (unsigned long long(| int)|long long unsigned int) \\($void\\)" \
+       "whatis unsigned long long function"
+}
+
+# Sun /bin/cc calls this a function returning double.
+if {!$gcc_compiled} then {setup_xfail "*-sun-sunos4*"}
+       gdb_test "whatis v_float_func" \
+           "type = float \\($void\\)" \
+           "whatis float function"
+
+       gdb_test "whatis v_double_func" \
+           "type = double \\($void\\)" \
+           "whatis double function" \
+}
diff --git a/gdb/testsuite/gdb.ctf/whatis.c b/gdb/testsuite/gdb.ctf/whatis.c
new file mode 100644 (file)
index 0000000..c321fed
--- /dev/null
@@ -0,0 +1,339 @@
+/* This test program is part of GDB, the GNU debugger.
+
+   Copyright 1992-2021 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/*
+ *     Test file with lots of different types, for testing the
+ *     "whatis" command.
+ */
+
+/*
+ *     First the basic C types.
+ */
+
+char           v_char;
+signed char    v_signed_char;
+unsigned char  v_unsigned_char;
+
+short          v_short;
+signed short   v_signed_short;
+unsigned short v_unsigned_short;
+
+int            v_int;
+signed int     v_signed_int;
+unsigned int   v_unsigned_int;
+
+long           v_long;
+signed long    v_signed_long;
+unsigned long  v_unsigned_long;
+
+#ifndef NO_LONG_LONG
+long long              v_long_long;
+signed long long       v_signed_long_long;
+unsigned long long     v_unsigned_long_long;
+#endif
+
+float          v_float;
+double         v_double;
+
+/*
+ *     Now some derived types, which are arrays, functions-returning,
+ *     pointers, structures, unions, and enumerations.
+ */
+
+/**** arrays *******/
+
+char           v_char_array[2];
+signed char    v_signed_char_array[2];
+unsigned char  v_unsigned_char_array[2];
+
+short          v_short_array[2];
+signed short   v_signed_short_array[2];
+unsigned short v_unsigned_short_array[2];
+
+int            v_int_array[2];
+signed int     v_signed_int_array[2];
+unsigned int   v_unsigned_int_array[2];
+
+long           v_long_array[2];
+signed long    v_signed_long_array[2];
+unsigned long  v_unsigned_long_array[2];
+
+#ifndef NO_LONG_LONG
+long long              v_long_long_array[2];
+signed long long       v_signed_long_long_array[2];
+unsigned long long     v_unsigned_long_long_array[2];
+#endif
+
+float          v_float_array[2];
+double         v_double_array[2];
+
+/**** pointers *******/
+
+/* Make sure they still print as pointer to foo even there is a typedef
+   for that type.  Test this not just for char *, which might be
+   a special case kludge in GDB (Unix system include files like to define
+   caddr_t), but for a variety of types.  */
+typedef char *char_addr;
+char_addr a_char_addr;
+typedef unsigned short *ushort_addr;
+ushort_addr a_ushort_addr;
+typedef signed long *slong_addr;
+slong_addr a_slong_addr;
+#ifndef NO_LONG_LONG
+typedef signed long long *slong_long_addr;
+slong_long_addr a_slong_long_addr;
+#endif
+
+char           *v_char_pointer;
+signed char    *v_signed_char_pointer;
+unsigned char  *v_unsigned_char_pointer;
+
+short          *v_short_pointer;
+signed short   *v_signed_short_pointer;
+unsigned short *v_unsigned_short_pointer;
+
+int            *v_int_pointer;
+signed int     *v_signed_int_pointer;
+unsigned int   *v_unsigned_int_pointer;
+
+long           *v_long_pointer;
+signed long    *v_signed_long_pointer;
+unsigned long  *v_unsigned_long_pointer;
+
+#ifndef NO_LONG_LONG
+long long              *v_long_long_pointer;
+signed long long       *v_signed_long_long_pointer;
+unsigned long long     *v_unsigned_long_long_pointer;
+#endif
+
+float          *v_float_pointer;
+double         *v_double_pointer;
+
+/**** structs *******/
+
+struct t_struct {
+    char       v_char_member;
+    short      v_short_member;
+    int                v_int_member;
+    long       v_long_member;
+#ifndef NO_LONG_LONG
+    long long  v_long_long_member;
+#endif
+    float      v_float_member;
+    double     v_double_member;
+} v_struct1, *v_struct_ptr1;
+
+struct {
+    char       v_char_member;
+    short      v_short_member;
+    int                v_int_member;
+    long       v_long_member;
+#ifndef NO_LONG_LONG
+    long long  v_long_long_member;
+#endif
+    float      v_float_member;
+    double     v_double_member;
+} v_struct2, *v_struct_ptr2;
+
+/**** unions *******/
+
+union t_union {
+    char       v_char_member;
+    short      v_short_member;
+    int                v_int_member;
+    long       v_long_member;
+#ifndef NO_LONG_LONG
+    long long  v_long_long_member;
+#endif
+    float      v_float_member;
+    double     v_double_member;
+} v_union, *v_union_ptr;
+
+union {
+    char       v_char_member;
+    short      v_short_member;
+    int                v_int_member;
+    long       v_long_member;
+#ifndef NO_LONG_LONG
+    long long  v_long_long_member;
+#endif
+    float      v_float_member;
+    double     v_double_member;
+} v_union2, *v_union_ptr2;
+
+/*** Functions returning type ********/
+
+char           v_char_func () { return(0); }
+signed char    v_signed_char_func () { return (0); }
+unsigned char  v_unsigned_char_func () { return (0); }
+
+short          v_short_func () { return (0); }
+signed short   v_signed_short_func () { return (0); }
+unsigned short v_unsigned_short_func () { return (0); }
+
+int            v_int_func () { return (0); }
+signed int     v_signed_int_func () { return (0); }
+unsigned int   v_unsigned_int_func () { return (0); }
+
+long           v_long_func () { return (0); }
+signed long    v_signed_long_func () { return (0); }
+unsigned long  v_unsigned_long_func () { return (0); }
+
+#ifndef NO_LONG_LONG
+long long              v_long_long_func () { return (0); }
+signed long long       v_signed_long_long_func () { return (0); }
+unsigned long long     v_unsigned_long_long_func () { return (0); }
+#endif
+
+float          v_float_func () { return (0.0); }
+double         v_double_func () { return (0.0); }
+
+/**** Some misc more complicated things *******/
+
+struct link {
+       struct link *next;
+#ifdef __STDC__
+       struct link *(*linkfunc) (struct link *self, int flags);
+#else
+       struct link *(*linkfunc) ();
+#endif
+       struct t_struct stuff[1][2][3];
+} *s_link;
+
+union tu_link {
+       struct link *next;
+#ifdef __STDC__
+       struct link *(*linkfunc) (struct link *self, int flags);
+#else
+       struct link *(*linkfunc) ();
+#endif
+       struct t_struct stuff[1][2][3];
+} u_link;
+
+struct outer_struct {
+       int outer_int;
+       struct inner_struct {
+               int inner_int;
+               long inner_long;
+       }inner_struct_instance;
+       union inner_union {
+               int inner_union_int;
+               long inner_union_long;
+       }inner_union_instance;
+       long outer_long;
+} nested_su;
+
+/**** Enumerations *******/
+
+enum colors {red, green, blue} color;
+enum cars {chevy, ford, porsche} clunker;
+
+/***********/
+
+int main ()
+{
+  /* Some linkers (e.g. on AIX) remove unreferenced variables,
+     so make sure to reference them. */
+  v_char = 0;
+  v_signed_char = 1;
+  v_unsigned_char = 2;
+
+  v_short = 3;
+  v_signed_short = 4;
+  v_unsigned_short = 5;
+
+  v_int = 6;
+  v_signed_int = 7;
+  v_unsigned_int = 8;
+
+  v_long = 9;
+  v_signed_long = 10;
+  v_unsigned_long = 11;
+
+#ifndef NO_LONG_LONG
+  v_long_long = 12;
+  v_signed_long_long = 13;
+  v_unsigned_long_long = 14;
+#endif
+
+  v_float = 100.0;
+  v_double = 200.0;
+
+
+  v_char_array[0] = v_char;
+  v_signed_char_array[0] = v_signed_char;
+  v_unsigned_char_array[0] = v_unsigned_char;
+
+  v_short_array[0] = v_short;
+  v_signed_short_array[0] = v_signed_short;
+  v_unsigned_short_array[0] = v_unsigned_short;
+
+  v_int_array[0] = v_int;
+  v_signed_int_array[0] = v_signed_int;
+  v_unsigned_int_array[0] = v_unsigned_int;
+
+  v_long_array[0] = v_long;
+  v_signed_long_array[0] = v_signed_long;
+  v_unsigned_long_array[0] = v_unsigned_long;
+
+#ifndef NO_LONG_LONG
+  v_long_long_array[0] = v_long_long;
+  v_signed_long_long_array[0] = v_signed_long_long;
+  v_unsigned_long_long_array[0] = v_unsigned_long_long;
+#endif
+
+  v_float_array[0] = v_float;
+  v_double_array[0] = v_double;
+
+  v_char_pointer = &v_char;
+  v_signed_char_pointer = &v_signed_char;
+  v_unsigned_char_pointer = &v_unsigned_char;
+
+  v_short_pointer = &v_short;
+  v_signed_short_pointer = &v_signed_short;
+  v_unsigned_short_pointer = &v_unsigned_short;
+
+  v_int_pointer = &v_int;
+  v_signed_int_pointer = &v_signed_int;
+  v_unsigned_int_pointer = &v_unsigned_int;
+
+  v_long_pointer = &v_long;
+  v_signed_long_pointer = &v_signed_long;
+  v_unsigned_long_pointer = &v_unsigned_long;
+
+#ifndef NO_LONG_LONG
+  v_long_long_pointer = &v_long_long;
+  v_signed_long_long_pointer = &v_signed_long_long;
+  v_unsigned_long_long_pointer = &v_unsigned_long_long;
+#endif
+
+  v_float_pointer = &v_float;
+  v_double_pointer = &v_double;
+
+  color = red;
+  clunker = porsche;
+
+  u_link.next = s_link;
+
+  v_union2.v_short_member = v_union.v_short_member;
+
+  v_struct1.v_char_member = 0;
+  v_struct2.v_char_member = 0;
+
+  nested_su.outer_int = 0;
+  return 0;
+}