@@ -39,16 +39,28 @@ std::map<AST::InlineAsmOption, std::string> InlineAsmOptionMap{
39
39
std::set<std::string> potentially_nonpromoted_keywords
40
40
= {" in" , " out" , " lateout" , " inout" , " inlateout" , " const" , " sym" , " label" };
41
41
42
+ // Helper function strips the beginning and ending double quotes from a
43
+ // string.
42
44
std::string
43
45
strip_double_quotes (const std::string &str)
44
46
{
45
- // Helper function strips the beginning and ending double quotes from a
46
- // string.
47
47
std::string result = str;
48
48
49
+ rust_assert (!str.empty ());
50
+
51
+ rust_assert (str.front () == ' \" ' );
52
+ rust_assert (str.back () == ' \" ' );
53
+
54
+ // we have to special case empty strings which just contain a set of quotes
55
+ // so, if the string is "\"\"", just return ""
56
+ if (result.size () == 2 )
57
+ return " " ;
58
+
49
59
rust_assert (result.size () >= 3 );
60
+
50
61
result.erase (0 , 1 );
51
62
result.erase (result.size () - 1 , 1 );
63
+
52
64
return result;
53
65
}
54
66
@@ -240,12 +252,10 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
240
252
// Loop over and execute the parsing functions, if the parser successfullly
241
253
// parses or if the parser fails to parse while it has committed to a token,
242
254
// we propogate the result.
243
- int count = 0 ;
244
255
tl::expected<InlineAsmContext, InlineAsmParseError> parsing_operand (
245
256
inline_asm_ctx);
246
257
for (auto &parse_func : parse_funcs)
247
258
{
248
- count++;
249
259
auto result = parsing_operand.and_then (parse_func);
250
260
251
261
// Per rust's asm.rs's structure
@@ -323,14 +333,14 @@ parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
323
333
// We are sure to be failing a test here, based on asm.rs
324
334
// https://github.com/rust-lang/rust/blob/a330e49593ee890f9197727a3a558b6e6b37f843/compiler/rustc_builtin_macros/src/asm.rs#L112
325
335
rust_unreachable ();
326
- return tl::unexpected<InlineAsmParseError> (COMMITTED);
336
+ // return tl::unexpected<InlineAsmParseError> (COMMITTED);
327
337
}
328
338
329
339
auto expr = parser.parse_expr ();
330
340
331
341
// TODO: When we've succesfully parse an expr, remember to clone_expr()
332
342
// instead of nullptr
333
- struct AST ::InlineAsmOperand::In in (reg, std::move (expr));
343
+ AST::InlineAsmOperand::In in (reg, std::move (expr));
334
344
inline_asm_ctx.inline_asm .operands .emplace_back (in, locus);
335
345
return inline_asm_ctx;
336
346
}
@@ -354,7 +364,7 @@ parse_reg_operand_out (InlineAsmContext inline_asm_ctx)
354
364
355
365
// TODO: When we've succesfully parse an expr, remember to clone_expr()
356
366
// instead of nullptr
357
- struct AST ::InlineAsmOperand::Out out (reg, false , std::move (expr));
367
+ AST::InlineAsmOperand::Out out (reg, false , std::move (expr));
358
368
359
369
inline_asm_ctx.inline_asm .operands .emplace_back (out, locus);
360
370
0 commit comments