File: multidim-array.c

package info (click to toggle)
binutils 2.46-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 417,664 kB
  • sloc: ansic: 1,487,508; asm: 829,455; cpp: 216,692; exp: 80,524; makefile: 73,157; sh: 24,213; yacc: 15,060; lisp: 13,632; perl: 13,404; lex: 1,714; ada: 1,681; pascal: 1,446; cs: 879; python: 637; java: 478; sed: 191; xml: 95; awk: 25
file content (108 lines) | stat: -rw-r--r-- 2,433 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "config.h"
#include <ctf-api.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static char *
insert_dimension (char *old_str, int num)
{
  char *bracket_ptr = strchr (old_str, '[');
  if (!bracket_ptr)
    {
      if (asprintf (&old_str, "int [%d]", num) < 0)
	return NULL;
    }
  else if (asprintf (&old_str, "int [%d]%s", num, bracket_ptr) < 0)
    return NULL;
  return old_str;
}

int
main (int argc, char *argv[])
{
  ctf_archive_t *ctf;
  ctf_dict_t *fp;
  int err;
  ctf_dump_state_t *dump_state = NULL;
  char *dumpstr;
  ctf_next_t *it = NULL;
  ctf_id_t type;
  int flagged = 0;
  const char *name = NULL;

  if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
    goto open_err;
  if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL)
    goto open_err;

  /* First, check for signs that the compiler is fixed but not emitting the
     relevant flag yet.  This combination is not expected to work right.  */

  while ((dumpstr = ctf_dump (fp, &dump_state, CTF_SECT_HEADER, NULL, NULL))
	 != NULL)
    {
      if (strstr (dumpstr, "CTF_F_ARRNELEMS") != NULL)
	flagged = 1;
      free (dumpstr);
    }

  if (!flagged)
    {
      ctf_arinfo_t ar;

      if ((type = ctf_lookup_by_symbol_name (fp, "a")) == CTF_ERR)
	goto unexpected;

      if (ctf_array_info (fp, type, &ar) < 0)
	goto unexpected;

      if (ar.ctr_nelems == 3)
	{
	  fprintf (stderr, "UNSUPPORTED: compiler has GCC PR114186 fixed but "
			   "no indicative flag\n");
	  return 0;
	}
    }

  /* Now check for the actual bug.  */
  if (flagged)
    {
      while ((type = ctf_type_next (fp, &it, NULL, 1)) != -1)
	if (ctf_type_kind (fp, type) == CTF_K_ARRAY)
	  printf ("%s\n", ctf_type_aname (fp, type));
    }

  else
    {
      while ((type = ctf_symbol_next (fp, &it, &name, 0)) != CTF_ERR)
	{
	  char *outstr = strdup ("int ");
	  while (ctf_type_kind (fp, type) == CTF_K_ARRAY)
	    {
	      ctf_arinfo_t ar;
	      if (ctf_array_info (fp, type, &ar) < 0)
		goto unexpected;
	      outstr = insert_dimension (outstr, ar.ctr_nelems);
	      printf ("%s\n", outstr);
	      type = ar.ctr_contents;
	    }
	  free (outstr);
	}
    }

  ctf_dict_close (fp);
  ctf_close (ctf);

  return 0;

open_err:
  fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
  return 1;

unexpected:
  fprintf (stderr,
	   "Cannot look up symbol to determine compiler bugginess: %s\n",
	   ctf_errmsg (ctf_errno (fp)));
  return 1;
}