Skip to content

Commit 0c3761b

Browse files
committed
Emit an error message on unsupported llvm_asm
llvm_asm was never meant to be completely supported since it has been replaced with the asm macro but we still need it to compile some parts of libcore, previously the compiler was aborting when an unsupported llvm_asm construct was found. gcc/rust/ChangeLog: * ast/rust-expr.h: Add const getters to llvm members. * hir/rust-ast-lower-expr.cc (check_llvm_asm_support): Check llvm_asm usage validity. (ASTLoweringExpr::visit): Emit an error message instead of aborting. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
1 parent 34ad192 commit 0c3761b

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

gcc/rust/ast/rust-expr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5669,6 +5669,10 @@ class LlvmInlineAsm : public ExprWithoutBlock
56695669
}
56705670

56715671
std::vector<TupleTemplateStr> &get_templates () { return templates; }
5672+
const std::vector<TupleTemplateStr> &get_templates () const
5673+
{
5674+
return templates;
5675+
}
56725676

56735677
Expr::Kind get_expr_kind () const override
56745678
{
@@ -5687,9 +5691,12 @@ class LlvmInlineAsm : public ExprWithoutBlock
56875691
void set_outputs (std::vector<LlvmOperand> operands) { outputs = operands; }
56885692

56895693
std::vector<LlvmOperand> &get_inputs () { return inputs; }
5694+
const std::vector<LlvmOperand> &get_inputs () const { return inputs; }
56905695
std::vector<LlvmOperand> &get_outputs () { return outputs; }
5696+
const std::vector<LlvmOperand> &get_outputs () const { return outputs; }
56915697

56925698
std::vector<TupleClobber> &get_clobbers () { return clobbers; }
5699+
const std::vector<TupleClobber> &get_clobbers () const { return clobbers; }
56935700
};
56945701

56955702
} // namespace AST

gcc/rust/hir/rust-ast-lower-expr.cc

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,23 @@ ASTLoweringExpr::visit (AST::InlineAsm &expr)
994994
expr.get_options (), mapping);
995995
}
996996

997+
namespace {
998+
// We're not really supporting llvm_asm, only the bare minimum for libcore's
999+
// blackbox
1000+
// llvm_asm!("" : : "r"(&mut dummy) : "memory" : "volatile");
1001+
bool
1002+
check_llvm_asm_support (const std::vector<LlvmOperand> &inputs,
1003+
const std::vector<LlvmOperand> &outputs,
1004+
const AST::LlvmInlineAsm &expr)
1005+
{
1006+
return outputs.size () == 0 && inputs.size () <= 1
1007+
&& expr.get_clobbers ().size () <= 1
1008+
&& expr.get_templates ().size () == 1
1009+
&& expr.get_templates ()[0].symbol == "";
1010+
}
1011+
1012+
} // namespace
1013+
9971014
void
9981015
ASTLoweringExpr::visit (AST::LlvmInlineAsm &expr)
9991016
{
@@ -1026,13 +1043,15 @@ ASTLoweringExpr::visit (AST::LlvmInlineAsm &expr)
10261043
expr.is_stack_aligned (),
10271044
expr.get_dialect ()};
10281045

1029-
// We're not really supporting llvm_asm, only the bare minimum
1030-
// we're quite conservative here as the current code support more usecase.
1031-
rust_assert (outputs.size () == 0);
1032-
rust_assert (inputs.size () <= 1);
1033-
rust_assert (expr.get_clobbers ().size () <= 1);
1034-
rust_assert (expr.get_templates ().size () == 1);
1035-
rust_assert (expr.get_templates ()[0].symbol == "");
1046+
if (!check_llvm_asm_support (inputs, outputs, expr))
1047+
{
1048+
rust_error_at (expr.get_locus (), "unsupported %qs construct",
1049+
"llvm_asm");
1050+
rust_inform (
1051+
expr.get_locus (),
1052+
"%<llvm_asm%> has been replaced with %<asm%>, gccrs only supports a "
1053+
"subset of %<llvm_asm%> to compile libcore");
1054+
}
10361055

10371056
translated
10381057
= new HIR::LlvmInlineAsm (expr.get_locus (), inputs, outputs,

0 commit comments

Comments
 (0)