Skip to content

Commit bde99d2

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 <[email protected]>
1 parent 39882bd commit bde99d2

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

gcc/rust/ast/rust-expr.h

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

56895689
std::vector<TupleTemplateStr> &get_templates () { return templates; }
5690+
const std::vector<TupleTemplateStr> &get_templates () const
5691+
{
5692+
return templates;
5693+
}
56905694

56915695
Expr::Kind get_expr_kind () const override
56925696
{
@@ -5705,9 +5709,12 @@ class LlvmInlineAsm : public ExprWithoutBlock
57055709
void set_outputs (std::vector<LlvmOperand> operands) { outputs = operands; }
57065710

57075711
std::vector<LlvmOperand> &get_inputs () { return inputs; }
5712+
const std::vector<LlvmOperand> &get_inputs () const { return inputs; }
57085713
std::vector<LlvmOperand> &get_outputs () { return outputs; }
5714+
const std::vector<LlvmOperand> &get_outputs () const { return outputs; }
57095715

57105716
std::vector<TupleClobber> &get_clobbers () { return clobbers; }
5717+
const std::vector<TupleClobber> &get_clobbers () const { return clobbers; }
57115718
};
57125719

57135720
} // 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)