Skip to content

Commit 3de6255

Browse files
committed
Refactor inline assembly constructor
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_asm): Simplify expression. (parse_llvm_asm): Likewise. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
1 parent 5b7a0d7 commit 3de6255

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,8 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
880880
// context.
881881
if (resulting_context)
882882
{
883-
auto node = (*resulting_context).inline_asm.clone_expr_without_block ();
883+
auto resulting_ctx = resulting_context.value ();
884+
auto node = resulting_ctx.inline_asm.clone_expr_without_block ();
884885

885886
std::vector<AST::SingleASTNode> single_vec = {};
886887

@@ -1177,25 +1178,27 @@ parse_llvm_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
11771178

11781179
auto asm_ctx = LlvmAsmContext (llvm_asm, parser, last_token_id);
11791180

1180-
auto resulting_context
1181+
tl::optional<LlvmAsmContext> resulting_context
11811182
= parse_llvm_templates (asm_ctx).and_then (parse_llvm_arguments);
11821183

11831184
if (resulting_context)
11841185
{
1185-
auto node = (*resulting_context).llvm_asm.clone_expr_without_block ();
1186+
auto resulting_ctx = resulting_context.value ();
1187+
auto node = resulting_ctx.llvm_asm.clone_expr_without_block ();
11861188

11871189
std::vector<AST::SingleASTNode> single_vec = {};
11881190

11891191
// If the macro invocation has a semicolon (`asm!("...");`), then we
11901192
// need to make it a statement. This way, it will be expanded
11911193
// properly.
11921194
if (semicolon == AST::InvocKind::Semicoloned)
1193-
single_vec.emplace_back (AST::SingleASTNode (
1194-
std::make_unique<AST::ExprStmt> (std::move (node), invoc_locus,
1195-
semicolon
1196-
== AST::InvocKind::Semicoloned)));
1195+
{
1196+
single_vec.emplace_back (
1197+
std::make_unique<AST::ExprStmt> (std::move (node), invoc_locus,
1198+
true /* has semicolon */));
1199+
}
11971200
else
1198-
single_vec.emplace_back (AST::SingleASTNode (std::move (node)));
1201+
single_vec.emplace_back (std::move (node));
11991202

12001203
AST::Fragment fragment_ast
12011204
= AST::Fragment (single_vec,

0 commit comments

Comments
 (0)