annotate gcc/c/c-errors.c @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Various diagnostic subroutines for the GNU C language.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "tm.h"
kono
parents:
diff changeset
25 #include "c-tree.h"
kono
parents:
diff changeset
26 #include "opts.h"
kono
parents:
diff changeset
27
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
28 /* Issue an ISO C11 pedantic warning MSGID if -pedantic outside C2X mode,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
29 otherwise issue warning MSGID if -Wc11-c2X-compat is specified.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
30 This function is supposed to be used for matters that are allowed in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
31 ISO C2X but not supported in ISO C11, thus we explicitly don't pedwarn
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
32 when C2X is specified. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
33
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
34 bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
35 pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
36 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
37 diagnostic_info diagnostic;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
38 va_list ap;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
39 bool warned = false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
40 rich_location richloc (line_table, location);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
41
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
42 va_start (ap, gmsgid);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
43 /* If desired, issue the C11/C2X compat warning, which is more specific
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
44 than -pedantic. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
45 if (warn_c11_c2x_compat > 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
46 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
47 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
48 (pedantic && !flag_isoc2x)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
49 ? DK_PEDWARN : DK_WARNING);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
50 diagnostic.option_index = OPT_Wc11_c2x_compat;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53 /* -Wno-c11-c2x-compat suppresses even the pedwarns. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
54 else if (warn_c11_c2x_compat == 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55 ;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 /* For -pedantic outside C2X, issue a pedwarn. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 else if (pedantic && !flag_isoc2x)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
58 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60 diagnostic.option_index = opt;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
61 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
62 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
63 va_end (ap);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
64 return warned;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
66
111
kono
parents:
diff changeset
67 /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
kono
parents:
diff changeset
68 otherwise issue warning MSGID if -Wc99-c11-compat is specified.
kono
parents:
diff changeset
69 This function is supposed to be used for matters that are allowed in
kono
parents:
diff changeset
70 ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
kono
parents:
diff changeset
71 when C11 is specified. */
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 bool
kono
parents:
diff changeset
74 pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
kono
parents:
diff changeset
75 {
kono
parents:
diff changeset
76 diagnostic_info diagnostic;
kono
parents:
diff changeset
77 va_list ap;
kono
parents:
diff changeset
78 bool warned = false;
kono
parents:
diff changeset
79 rich_location richloc (line_table, location);
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 va_start (ap, gmsgid);
kono
parents:
diff changeset
82 /* If desired, issue the C99/C11 compat warning, which is more specific
kono
parents:
diff changeset
83 than -pedantic. */
kono
parents:
diff changeset
84 if (warn_c99_c11_compat > 0)
kono
parents:
diff changeset
85 {
kono
parents:
diff changeset
86 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
kono
parents:
diff changeset
87 (pedantic && !flag_isoc11)
kono
parents:
diff changeset
88 ? DK_PEDWARN : DK_WARNING);
kono
parents:
diff changeset
89 diagnostic.option_index = OPT_Wc99_c11_compat;
kono
parents:
diff changeset
90 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents:
diff changeset
91 }
kono
parents:
diff changeset
92 /* -Wno-c99-c11-compat suppresses even the pedwarns. */
kono
parents:
diff changeset
93 else if (warn_c99_c11_compat == 0)
kono
parents:
diff changeset
94 ;
kono
parents:
diff changeset
95 /* For -pedantic outside C11, issue a pedwarn. */
kono
parents:
diff changeset
96 else if (pedantic && !flag_isoc11)
kono
parents:
diff changeset
97 {
kono
parents:
diff changeset
98 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
kono
parents:
diff changeset
99 diagnostic.option_index = opt;
kono
parents:
diff changeset
100 warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents:
diff changeset
101 }
kono
parents:
diff changeset
102 va_end (ap);
kono
parents:
diff changeset
103 return warned;
kono
parents:
diff changeset
104 }
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
kono
parents:
diff changeset
107 otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
kono
parents:
diff changeset
108 a specific option such as -Wlong-long is specified.
kono
parents:
diff changeset
109 This function is supposed to be used for matters that are allowed in
kono
parents:
diff changeset
110 ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
kono
parents:
diff changeset
111 when C99 is specified. (There is no flag_c90.) */
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 bool
kono
parents:
diff changeset
114 pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
kono
parents:
diff changeset
115 {
kono
parents:
diff changeset
116 diagnostic_info diagnostic;
kono
parents:
diff changeset
117 va_list ap;
kono
parents:
diff changeset
118 bool warned = false;
kono
parents:
diff changeset
119 rich_location richloc (line_table, location);
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 va_start (ap, gmsgid);
kono
parents:
diff changeset
122 /* Warnings such as -Wvla are the most specific ones. */
kono
parents:
diff changeset
123 if (opt != OPT_Wpedantic)
kono
parents:
diff changeset
124 {
kono
parents:
diff changeset
125 int opt_var = *(int *) option_flag_var (opt, &global_options);
kono
parents:
diff changeset
126 if (opt_var == 0)
kono
parents:
diff changeset
127 goto out;
kono
parents:
diff changeset
128 else if (opt_var > 0)
kono
parents:
diff changeset
129 {
kono
parents:
diff changeset
130 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
kono
parents:
diff changeset
131 (pedantic && !flag_isoc99)
kono
parents:
diff changeset
132 ? DK_PEDWARN : DK_WARNING);
kono
parents:
diff changeset
133 diagnostic.option_index = opt;
kono
parents:
diff changeset
134 diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents:
diff changeset
135 warned = true;
kono
parents:
diff changeset
136 goto out;
kono
parents:
diff changeset
137 }
kono
parents:
diff changeset
138 }
kono
parents:
diff changeset
139 /* Maybe we want to issue the C90/C99 compat warning, which is more
kono
parents:
diff changeset
140 specific than -pedantic. */
kono
parents:
diff changeset
141 if (warn_c90_c99_compat > 0)
kono
parents:
diff changeset
142 {
kono
parents:
diff changeset
143 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
kono
parents:
diff changeset
144 (pedantic && !flag_isoc99)
kono
parents:
diff changeset
145 ? DK_PEDWARN : DK_WARNING);
kono
parents:
diff changeset
146 diagnostic.option_index = OPT_Wc90_c99_compat;
kono
parents:
diff changeset
147 diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents:
diff changeset
148 }
kono
parents:
diff changeset
149 /* -Wno-c90-c99-compat suppresses the pedwarns. */
kono
parents:
diff changeset
150 else if (warn_c90_c99_compat == 0)
kono
parents:
diff changeset
151 ;
kono
parents:
diff changeset
152 /* For -pedantic outside C99, issue a pedwarn. */
kono
parents:
diff changeset
153 else if (pedantic && !flag_isoc99)
kono
parents:
diff changeset
154 {
kono
parents:
diff changeset
155 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
kono
parents:
diff changeset
156 diagnostic.option_index = opt;
kono
parents:
diff changeset
157 diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents:
diff changeset
158 warned = true;
kono
parents:
diff changeset
159 }
kono
parents:
diff changeset
160 out:
kono
parents:
diff changeset
161 va_end (ap);
kono
parents:
diff changeset
162 return warned;
kono
parents:
diff changeset
163 }