Use optab_libfunc to access sync_lock_test_and_set libfunc on hppa-linux.
[official-gcc.git] / libiberty / testsuite / demangler-fuzzer.c
blobaa733995aa16c30b6704e047693a8583df1b2a57
1 /* Demangler fuzzer.
3 Copyright (C) 2014-2021 Free Software Foundation, Inc.
5 This file is part of GNU libiberty.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <time.h>
24 #include "demangle.h"
26 #define MAXLEN 253
27 #define ALPMIN 33
28 #define ALPMAX 127
30 static char *program_name;
32 #define DEFAULT_MAXCOUNT 7500000
34 static void
35 print_usage (FILE *fp, int exit_value)
37 fprintf (fp, "Usage: %s [OPTION]...\n", program_name);
38 fprintf (fp, "Options:\n");
39 fprintf (fp, " -h Display this message.\n");
40 fprintf (fp, " -s SEED Select the random seed to be used.\n");
41 fprintf (fp, " The default is to base one on the");
42 fprintf (fp, " current time.\n");
43 fprintf (fp, " -m MAXCOUNT Exit after MAXCOUNT symbols.\n");
44 fprintf (fp, " The default is %d.", DEFAULT_MAXCOUNT);
45 fprintf (fp, " Set to `-1' for no limit.\n");
47 exit (exit_value);
50 int
51 main (int argc, char *argv[])
53 char symbol[2 + MAXLEN + 1] = "_Z";
54 int seed = -1, seed_set = 0;
55 int count = 0, maxcount = DEFAULT_MAXCOUNT;
56 int optchr;
58 program_name = argv[0];
62 optchr = getopt (argc, argv, "hs:m:t:");
63 switch (optchr)
65 case '?': /* Unrecognized option. */
66 print_usage (stderr, 1);
67 break;
69 case 'h':
70 print_usage (stdout, 0);
71 break;
73 case 's':
74 seed = atoi (optarg);
75 seed_set = 1;
76 break;
78 case 'm':
79 maxcount = atoi (optarg);
80 break;
83 while (optchr != -1);
85 if (!seed_set)
86 seed = time (NULL);
87 srand (seed);
88 printf ("%s: seed = %d\n", program_name, seed);
90 while (maxcount < 0 || count < maxcount)
92 char *buffer = symbol + 2;
93 int length, i;
95 length = rand () % MAXLEN;
96 for (i = 0; i < length; i++)
97 *buffer++ = (rand () % (ALPMAX - ALPMIN)) + ALPMIN;
99 *buffer++ = '\0';
101 cplus_demangle (symbol, DMGL_AUTO | DMGL_ANSI | DMGL_PARAMS);
103 count++;
106 printf ("%s: successfully demangled %d symbols\n", program_name, count);
107 exit (0);