blob: 0c73f5386ffd00b1982f96bd722b47368271f2f5 (
plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
From patchwork Thu Dec 27 14:59:09 2018
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [4/8] c/c++, asm: Write the asm-qualifier loop without "done" boolean
X-Patchwork-Submitter: Segher Boessenkool <segher@kernel.crashing.org>
X-Patchwork-Id: 13821
Message-Id: <5bbbd04162b8546d9c72da11cf33e6e61d1128d7.1545922222.git.segher@kernel.crashing.org>
To: gcc-patches@gcc.gnu.org
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Date: Thu, 27 Dec 2018 14:59:09 +0000
From: Segher Boessenkool <segher@kernel.crashing.org>
List-Id: <gcc-patches.gcc.gnu.org>
As suggested by Jason.
Segher
2018-12-10 Segher Boessenkool <segher@kernel.crashing.org>
c/
* c-parser.c (c_parser_asm_statement): Rewrite the loop to work without
"done" boolean variable.
cp/
* parser.c (cp_parser_asm_definition): Rewrite the loop to work without
"done" boolean variable.
---
gcc/c/c-parser.c | 65 +++++++++++++++++++++++++--------------------------
gcc/cp/parser.c | 71 +++++++++++++++++++++++++-------------------------------
2 files changed, 62 insertions(+), 74 deletions(-)
--
1.8.3.1
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index e45f70b..b632f68 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6304,40 +6304,37 @@ c_parser_asm_statement (c_parser *parser)
is_volatile = false;
is_inline = false;
is_goto = false;
- for (bool done = false; !done; )
- switch (c_parser_peek_token (parser)->keyword)
- {
- case RID_VOLATILE:
- if (!is_volatile)
- {
- is_volatile = true;
- quals = c_parser_peek_token (parser)->value;
- c_parser_consume_token (parser);
- }
- else
- done = true;
- break;
- case RID_INLINE:
- if (!is_inline)
- {
- is_inline = true;
- c_parser_consume_token (parser);
- }
- else
- done = true;
- break;
- case RID_GOTO:
- if (!is_goto)
- {
- is_goto = true;
- c_parser_consume_token (parser);
- }
- else
- done = true;
- break;
- default:
- done = true;
- }
+ for (;;)
+ {
+ switch (c_parser_peek_token (parser)->keyword)
+ {
+ case RID_VOLATILE:
+ if (is_volatile)
+ break;
+ is_volatile = true;
+ quals = c_parser_peek_token (parser)->value;
+ c_parser_consume_token (parser);
+ continue;
+
+ case RID_INLINE:
+ if (is_inline)
+ break;
+ is_inline = true;
+ c_parser_consume_token (parser);
+ continue;
+
+ case RID_GOTO:
+ if (is_goto)
+ break;
+ is_goto = true;
+ c_parser_consume_token (parser);
+ continue;
+
+ default:
+ break;
+ }
+ break;
+ }
/* ??? Follow the C++ parser rather than using the
lex_untranslated_string kludge. */
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3fd9a02..7660565 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -19124,47 +19124,38 @@ cp_parser_asm_definition (cp_parser* parser)
cp_function_chain->invalid_constexpr = true;
}
- /* See if the next token is `volatile'. */
+ /* Handle the asm-qualifier-list. */
if (cp_parser_allow_gnu_extensions_p (parser))
- for (bool done = false; !done ; )
- switch (cp_lexer_peek_token (parser->lexer)->keyword)
- {
- case RID_VOLATILE:
- if (!volatile_p)
- {
- /* Remember that we saw the `volatile' keyword. */
- volatile_p = true;
- /* Consume the token. */
- cp_lexer_consume_token (parser->lexer);
- }
- else
- done = true;
- break;
- case RID_INLINE:
- if (!inline_p && parser->in_function_body)
- {
- /* Remember that we saw the `inline' keyword. */
- inline_p = true;
- /* Consume the token. */
- cp_lexer_consume_token (parser->lexer);
- }
- else
- done = true;
- break;
- case RID_GOTO:
- if (!goto_p && parser->in_function_body)
- {
- /* Remember that we saw the `goto' keyword. */
- goto_p = true;
- /* Consume the token. */
- cp_lexer_consume_token (parser->lexer);
- }
- else
- done = true;
- break;
- default:
- done = true;
- }
+ for (;;)
+ {
+ switch (cp_lexer_peek_token (parser->lexer)->keyword)
+ {
+ case RID_VOLATILE:
+ if (volatile_p)
+ break;
+ volatile_p = true;
+ cp_lexer_consume_token (parser->lexer);
+ continue;
+
+ case RID_INLINE:
+ if (inline_p || !parser->in_function_body)
+ break;
+ inline_p = true;
+ cp_lexer_consume_token (parser->lexer);
+ continue;
+
+ case RID_GOTO:
+ if (goto_p || !parser->in_function_body)
+ break;
+ goto_p = true;
+ cp_lexer_consume_token (parser->lexer);
+ continue;
+
+ default:
+ break;
+ }
+ break;
+ }
/* Look for the opening `('. */
if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
|