Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d7a1f71
gccrs: Clean up of obsolete nr2 command line option
fisnikhasani Apr 2, 2026
15138d8
gccrs: Fix corrupted GIMPLE for CompoundAssignmentExpr in const context
Islam-Imad Apr 11, 2026
d4eb9ed
gccrs: Fix ICE in get_function_expr when cfg'd return type inside macro
Harishankar14 Apr 17, 2026
5d88f22
gccrs: Recognize warn and deny as built in attributes
powerboat9 Apr 18, 2026
05a6963
gccrs: Fix ICE cloning trait functions without return types
Lishin1215 Apr 20, 2026
c13a1b8
gccrs: Add assert macro handler
P-E-P Apr 3, 2026
bdeb2cd
gccrs: nr: Move path resolution from ForeverStack to NRCtx
CohenArthur Mar 23, 2026
385f8b8
gccrs: nr: Do first part of path resolution in types NS
CohenArthur Mar 23, 2026
9a851aa
gccrs: Defer literal suffix validation to parser and preserve source …
nsvke Apr 6, 2026
0ac51f0
gccrs: lex: Emit E0768 for empty non-decimal literals
nsvke Apr 29, 2026
8cfe060
gccrs: Add feature gate for rustc_const_stable attribute
P-E-P Apr 30, 2026
d5c84de
gccrs: testsuite: Add a testcase for issue 3537
Harishankar14 May 6, 2026
a4092fa
gccrs: util: Switch VisType to an enum class and rename variants.
CohenArthur May 18, 2026
4ba3ba9
gccrs: testsuite: Add a testcase for issue 4158
Harishankar14 May 7, 2026
6abd89e
gccrs: testsuite: Add a testcase for issue 4159
Harishankar14 May 7, 2026
1246802
gccrs: Support labeled block value breaks in HIR lowering
Islam-Imad Apr 21, 2026
6c0c79f
gccrs: Fix intrinsic error location
Jean-Christian-Cirstea May 12, 2026
ca8ad0f
gccrs: register the Drop lang item
Lishin1215 May 26, 2026
cf5db6e
gccrs: Fix ICE when parsing empty path expression
Polygonalr May 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,20 @@ TokenCollector::visit (Token &tok)
push (Rust::Token::make_identifier (tok.get_locus (), std::move (data)));
break;
case INT_LITERAL:
push (Rust::Token::make_int (tok.get_locus (), std::move (data),
tok.get_type_hint ()));
break;
case FLOAT_LITERAL:
push (Rust::Token::make_float (tok.get_locus (), std::move (data),
{
auto suffix_start = data.length ();
push (Rust::Token::make_int (tok.get_locus (), std::move (data),
suffix_start, IntegerLiteralBase::Decimal,
tok.get_type_hint ()));
break;
break;
}
case FLOAT_LITERAL:
{
auto suffix_start = data.length ();
push (Rust::Token::make_float (tok.get_locus (), std::move (data),
suffix_start, tok.get_type_hint ()));
break;
}
case STRING_LITERAL:
push (Rust::Token::make_string (tok.get_locus (), std::move (data)));
break;
Expand Down Expand Up @@ -857,13 +864,20 @@ TokenCollector::visit (Literal &lit, location_t locus)
push (Rust::Token::make_raw_string (locus, std::move (value)));
break;
case Literal::LitType::INT:
push (
Rust::Token::make_int (locus, std::move (value), lit.get_type_hint ()));
break;
case Literal::LitType::FLOAT:
push (Rust::Token::make_float (locus, std::move (value),
{
auto val_len = value.length ();
push (Rust::Token::make_int (locus, std::move (value), val_len,
IntegerLiteralBase::Decimal,
lit.get_type_hint ()));
break;
break;
}
case Literal::LitType::FLOAT:
{
auto val_len = value.length ();
push (Rust::Token::make_float (locus, std::move (value), val_len,
lit.get_type_hint ()));
break;
}
case Literal::LitType::BOOL:
{
if (value == Values::Keywords::FALSE_LITERAL)
Expand Down Expand Up @@ -1237,8 +1251,10 @@ TokenCollector::visit (TupleIndexExpr &expr)
describe_node (std::string ("TupleIndexExpr"), [this, &expr] () {
visit (expr.get_tuple_expr ());
push (Rust::Token::make (DOT, expr.get_locus ()));
push (Rust::Token::make_int (UNDEF_LOCATION,
std::to_string (expr.get_tuple_index ())));
auto str = std::to_string (expr.get_tuple_index ());
auto suffix_start = str.length ();
push (Rust::Token::make_int (UNDEF_LOCATION, str, suffix_start,
IntegerLiteralBase::Decimal));
});
}

Expand Down Expand Up @@ -1277,8 +1293,10 @@ TokenCollector::visit (StructExprFieldIndexValue &expr)
{
describe_node (std::string ("StructExprFieldIndexValue"), [this, &expr] () {
visit_items_as_lines (expr.get_outer_attrs ());
push (Rust::Token::make_int (expr.get_locus (),
std::to_string (expr.get_index ())));
auto str = std::to_string (expr.get_index ());
auto suffix_start = str.length ();
push (Rust::Token::make_int (expr.get_locus (), str, suffix_start,
IntegerLiteralBase::Decimal));
push (Rust::Token::make (COLON, UNDEF_LOCATION));
visit (expr.get_value ());
});
Expand Down Expand Up @@ -2885,8 +2903,10 @@ TokenCollector::visit (StructPatternFieldTuplePat &pattern)
describe_node (std::string ("StructPatternFieldTuplePat"), [this,
&pattern] () {
visit_items_as_lines (pattern.get_outer_attrs ());
push (Rust::Token::make_int (pattern.get_locus (),
std::to_string (pattern.get_index ())));
auto str = std::to_string (pattern.get_index ());
auto suffix_start = str.length ();
push (Rust::Token::make_int (pattern.get_locus (), str, suffix_start,
IntegerLiteralBase::Decimal));
push (Rust::Token::make (COLON, pattern.get_locus ()));
visit (pattern.get_index_pattern ());
});
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/backend/rust-compile-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ HIRCompileBase::setup_fndecl (tree fndecl, bool is_main_entry_point,
{
// if its the main fn or pub visibility mark its as DECL_PUBLIC
// please see https://github.com/Rust-GCC/gccrs/pull/137
bool is_pub = visibility.get_vis_type () == HIR::Visibility::VisType::PUBLIC;
bool is_pub = visibility.get_vis_type () == HIR::Visibility::VisType::Public;
if (is_main_entry_point || (is_pub && !is_generic_fn))
{
TREE_PUBLIC (fndecl) = 1;
Expand Down
117 changes: 95 additions & 22 deletions gcc/rust/backend/rust-compile-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "rust-compile-expr.h"
#include "rust-backend.h"
#include "rust-compile-context.h"
#include "rust-compile-type.h"
#include "rust-compile-struct-field-expr.h"
#include "rust-compile-pattern.h"
Expand All @@ -32,6 +33,7 @@
#include "realmpfr.h"
#include "convert.h"
#include "print-tree.h"
#include "rust-hir-bound.h"
#include "rust-hir-expr.h"
#include "rust-system.h"
#include "rust-tree.h"
Expand Down Expand Up @@ -192,9 +194,9 @@ void
CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
{
auto op = expr.get_expr_type ();
auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx);

tree lhs = CompileExpr::Compile (expr.get_lhs (), ctx);
tree rhs = CompileExpr::Compile (expr.get_rhs (), ctx);
tree compound_assignment = NULL_TREE;
// this might be an operator overload situation lets check
TyTy::FnType *fntype;
bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload (
Expand All @@ -203,38 +205,37 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr)
{
auto lang_item_type = LangItem::CompoundAssignmentOperatorToLangItem (
expr.get_expr_type ());
auto compound_assignment
compound_assignment
= resolve_operator_overload (lang_item_type, expr, lhs, rhs,
expr.get_lhs (), expr.get_rhs ());
ctx->add_statement (compound_assignment);

return;
}

if (ctx->in_fn () && !ctx->const_context_p ())
else if (ctx->in_fn () && !ctx->const_context_p ())
{
auto tmp = NULL_TREE;
tree tmp = NULL_TREE;
Bvariable *receiver
= Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
TREE_TYPE (lhs), lhs, true,
expr.get_locus (), &tmp);
auto check
tree check
= Backend::arithmetic_or_logical_expression_checked (op, lhs, rhs,
expr.get_locus (),
receiver);
ctx->add_statement (check);

translated
compound_assignment
= Backend::assignment_statement (lhs,
receiver->get_tree (expr.get_locus ()),
expr.get_locus ());
}
else
{
translated
tree expr_tree
= Backend::arithmetic_or_logical_expression (op, lhs, rhs,
expr.get_locus ());
compound_assignment
= Backend::assignment_statement (lhs, expr_tree, expr.get_locus ());
}
ctx->add_statement (compound_assignment);
translated = unit_expression (expr.get_locus ());
}

void
Expand Down Expand Up @@ -437,12 +438,6 @@ CompileExpr::visit (HIR::IfExprConseqElse &expr)
void
CompileExpr::visit (HIR::BlockExpr &expr)
{
if (expr.has_label ())
{
rust_error_at (expr.get_locus (), "labeled blocks are not supported");
return;
}

TyTy::BaseType *block_tyty = nullptr;
if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (),
&block_tyty))
Expand All @@ -455,18 +450,31 @@ CompileExpr::visit (HIR::BlockExpr &expr)
fncontext fnctx = ctx->peek_fn ();
tree enclosing_scope = ctx->peek_enclosing_scope ();
tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
tree block_label = NULL_TREE;

bool is_address_taken = false;
tree ret_var_stmt = nullptr;
tmp = Backend::temporary_variable (fnctx.fndecl, enclosing_scope, block_type,
NULL, is_address_taken, expr.get_locus (),
&ret_var_stmt);

ctx->add_statement (ret_var_stmt);

if (expr.has_label ())
{
ctx->insert_var_decl (
expr.get_label ().get_lifetime ().get_mappings ().get_hirid (), tmp);
block_label = construct_block_label (expr);
}

auto block_stmt = CompileBlock::compile (expr, ctx, tmp);
rust_assert (TREE_CODE (block_stmt) == BIND_EXPR);
ctx->add_statement (block_stmt);

if (block_label != NULL_TREE)
{
ctx->add_statement (block_label);
}
translated = Backend::var_expression (tmp, expr.get_locus ());
}

Expand Down Expand Up @@ -854,11 +862,25 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr)
void
CompileExpr::visit (HIR::BreakExpr &expr)
{
if (expr.has_break_expr () && expr.has_label ())
{
HIR::Lifetime &label = expr.get_label ();
auto tvar = lookup_temp_var (label.get_mappings ().get_nodeid ());
tree value = CompileExpr::Compile (expr.get_expr (), ctx);
tree assign
= Backend::assignment_statement (tvar->get_tree (label.get_locus ()),
value, label.get_locus ());
tree block_label = lookup_label (label.get_mappings ().get_nodeid ());
tree go_to = Backend::goto_statement (block_label, label.get_locus ());
ctx->add_statement (assign);
ctx->add_statement (go_to);
return;
}
if (expr.has_break_expr ())
{
tree compiled_expr = CompileExpr::Compile (expr.get_expr (), ctx);

translated = error_mark_node;

if (!ctx->have_loop_context ())
return;

Expand Down Expand Up @@ -892,7 +914,6 @@ CompileExpr::visit (HIR::BreakExpr &expr)
expr.get_label ().get_mappings ().as_string ().c_str ());
return;
}

tl::optional<HirId> hid
= ctx->get_mappings ().lookup_node_to_hir (resolved_node_id);
if (!hid.has_value ())
Expand Down Expand Up @@ -2759,5 +2780,57 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr,
return true;
}

tree
CompileExpr::construct_block_label (HIR::BlockExpr &expr)
{
if (expr.has_label ())
{
fncontext fnctx = ctx->peek_fn ();
HIR::LoopLabel &label = expr.get_label ();
std::string label_name = label.get_lifetime ().get_name ();
HirId label_id = label.get_lifetime ().get_mappings ().get_hirid ();
tree label_decl
= Backend::label (fnctx.fndecl, label_name, label.get_locus ());
tree label_expr = Backend::label_definition_statement (label_decl);
ctx->insert_label_decl (label_id, label_decl);
return label_expr;
}
return NULL_TREE;
}

tree
CompileExpr::lookup_label (NodeId to_be_resolved)
{
HirId ref = resolve_NodeId (to_be_resolved);
tree label = NULL_TREE;
rust_assert (ctx->lookup_label_decl (ref, &label)
&& "failed to lookup a label");
return label;
}

Bvariable *
CompileExpr::lookup_temp_var (NodeId to_be_resolved)
{
HirId ref = resolve_NodeId (to_be_resolved);
Bvariable *ltemp = nullptr;
rust_assert (ctx->lookup_var_decl (ref, &ltemp)
&& "failed to lookup a temp var");
return ltemp;
}

HirId
CompileExpr::resolve_NodeId (NodeId to_be_resolved)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

NodeId resolved_node_id;
resolved_node_id = nr_ctx.lookup (to_be_resolved).value ();

HirId ref
= ctx->get_mappings ().lookup_node_to_hir (resolved_node_id).value ();
return ref;
}

} // namespace Compile
} // namespace Rust
7 changes: 7 additions & 0 deletions gcc/rust/backend/rust-compile-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#define RUST_COMPILE_EXPR

#include "rust-compile-base.h"
#include "rust-gcc.h"
#include "rust-hir-expr.h"
#include "rust-hir-visitor.h"

namespace Rust {
Expand Down Expand Up @@ -151,6 +153,11 @@ class CompileExpr : private HIRCompileBase, protected HIR::HIRExpressionVisitor
bool generate_possible_fn_trait_call (HIR::CallExpr &expr, tree receiver,
tree *result);

tree construct_block_label (HIR::BlockExpr &expr);
tree lookup_label (NodeId to_be_resolved);
Bvariable *lookup_temp_var (NodeId to_be_resolved);
HirId resolve_NodeId (NodeId to_be_resolved);

private:
CompileExpr (Context *ctx);

Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/backend/rust-compile-implitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
= nr_ctx.to_canonical_path (func.get_mappings ().get_nodeid ());

// FIXME: How do we get the proper visibility here?
auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
auto vis = HIR::Visibility (HIR::Visibility::VisType::Public);
HIR::TraitFunctionDecl &function = func.get_decl ();
tree fndecl
= compile_function (false, function.get_function_name ().as_string (),
Expand Down
Loading