Skip to content

Commit 58fa050

Browse files
committed
inline-asm: Fix some warnings
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (strip_double_quotes): Special case empty strings ("\"\""). (parse_reg_operand): Remove use of the `struct` keyword. (parse_reg_operand_in): Likewise. (parse_reg_operand_out): Likewise. * expand/rust-macro-builtins.cc: Add llvm_asm! built-in macro as an alias to asm!.
1 parent d3c9821 commit 58fa050

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

gcc/rust/expand/rust-macro-builtins-asm.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,28 @@ std::map<AST::InlineAsmOption, std::string> InlineAsmOptionMap{
3939
std::set<std::string> potentially_nonpromoted_keywords
4040
= {"in", "out", "lateout", "inout", "inlateout", "const", "sym", "label"};
4141

42+
// Helper function strips the beginning and ending double quotes from a
43+
// string.
4244
std::string
4345
strip_double_quotes (const std::string &str)
4446
{
45-
// Helper function strips the beginning and ending double quotes from a
46-
// string.
4747
std::string result = str;
4848

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+
4959
rust_assert (result.size () >= 3);
60+
5061
result.erase (0, 1);
5162
result.erase (result.size () - 1, 1);
63+
5264
return result;
5365
}
5466

@@ -240,12 +252,10 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
240252
// Loop over and execute the parsing functions, if the parser successfullly
241253
// parses or if the parser fails to parse while it has committed to a token,
242254
// we propogate the result.
243-
int count = 0;
244255
tl::expected<InlineAsmContext, InlineAsmParseError> parsing_operand (
245256
inline_asm_ctx);
246257
for (auto &parse_func : parse_funcs)
247258
{
248-
count++;
249259
auto result = parsing_operand.and_then (parse_func);
250260

251261
// Per rust's asm.rs's structure
@@ -323,14 +333,14 @@ parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
323333
// We are sure to be failing a test here, based on asm.rs
324334
// https://github.com/rust-lang/rust/blob/a330e49593ee890f9197727a3a558b6e6b37f843/compiler/rustc_builtin_macros/src/asm.rs#L112
325335
rust_unreachable ();
326-
return tl::unexpected<InlineAsmParseError> (COMMITTED);
336+
// return tl::unexpected<InlineAsmParseError> (COMMITTED);
327337
}
328338

329339
auto expr = parser.parse_expr ();
330340

331341
// TODO: When we've succesfully parse an expr, remember to clone_expr()
332342
// instead of nullptr
333-
struct AST::InlineAsmOperand::In in (reg, std::move (expr));
343+
AST::InlineAsmOperand::In in (reg, std::move (expr));
334344
inline_asm_ctx.inline_asm.operands.emplace_back (in, locus);
335345
return inline_asm_ctx;
336346
}
@@ -354,7 +364,7 @@ parse_reg_operand_out (InlineAsmContext inline_asm_ctx)
354364

355365
// TODO: When we've succesfully parse an expr, remember to clone_expr()
356366
// instead of nullptr
357-
struct AST::InlineAsmOperand::Out out (reg, false, std::move (expr));
367+
AST::InlineAsmOperand::Out out (reg, false, std::move (expr));
358368

359369
inline_asm_ctx.inline_asm.operands.emplace_back (out, locus);
360370

gcc/rust/expand/rust-macro-builtins.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const BiMap<std::string, BuiltinMacro> MacroBuiltin::builtins = {{
6262
{"concat_idents", BuiltinMacro::ConcatIdents},
6363
{"module_path", BuiltinMacro::ModulePath},
6464
{"asm", BuiltinMacro::Asm},
65+
// FIXME: Is that okay
66+
{"llvm_asm", BuiltinMacro::Asm},
6567
{"global_asm", BuiltinMacro::GlobalAsm},
6668
{"log_syntax", BuiltinMacro::LogSyntax},
6769
{"trace_macros", BuiltinMacro::TraceMacros},
@@ -119,6 +121,8 @@ std::unordered_map<std::string, AST::MacroTranscriberFunc>
119121
{"format_args", format_args_maker (AST::FormatArgs::Newline::No)},
120122
{"format_args_nl", format_args_maker (AST::FormatArgs::Newline::Yes)},
121123
{"asm", inline_asm_maker (AST::AsmKind::Inline)},
124+
// FIXME: Is that okay?
125+
{"llvm_asm", inline_asm_maker (AST::AsmKind::Inline)},
122126
{"global_asm", inline_asm_maker (AST::AsmKind::Global)},
123127
{"option_env", MacroBuiltin::option_env_handler},
124128
/* Unimplemented macro builtins */

0 commit comments

Comments
 (0)