Skip to content

Conversation

@Harishankar14
Copy link
Contributor

This patch fixes two Internal Compiler Errors (ICEs) encountered during compilation.

First, it resolves a crash in CompilePatternLet::visit where the backend panicked upon encountering an error_mark node within a tuple pattern. A check was added to handle erroneous types gracefully.

Second, it fixes a crash in the MarkLive lint pass. Previously, visiting a TypeAlias could trigger rust_unreachable() if the AST-to-HIR mapping lookup failed. This assertion has been removed to allow the compiler to continue execution when the mapping is missing.

Fixes #4161

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternLet::visit): Check for error_mark_node before processing tuple patterns.
* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Remove rust_unreachable() assertion to prevent ICE on missing mappings.

gcc/testsuite/ChangeLog:

* rust/compile/issue-4161.rs: New test.

Thank you for making Rust GCC better!

If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.

Here is a checklist to help you with your PR.

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

@Harishankar14 Harishankar14 changed the title gccrs: Fix ICEs in CompilePatternLet and MarkLive liveness analysis gccrs: fix(type-check): Resolve 'exceptional' error_mark in visit pattern compilation Jan 13, 2026
Copy link
Member

@P-E-P P-E-P left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% confident because I'm not too familiar with that part of the codebase but it feels like you're trying here to fix the symptoms rather than the source of the problem.

@Harishankar14 Harishankar14 force-pushed the fix_segfault branch 2 times, most recently from 816cbd4 to 23add0c Compare January 17, 2026 08:57
The compiler was throwing an ICE when a Type Alias was used as a value
in a LetStmt (e.g., `let () = ::X = ();`). This occurred because the
backend pattern compiler received an `error_mark_node` for the
initialization expression and failed to handle it.

This patch adds a check in `CompileStmt` to detect if the initialization
expression is an `error_mark_node`. To prevent regression failures in
other tests (excess errors), this check is restricted specifically to
`TuplePattern`, which was the source of the crash. If detected, we now
emit a proper error message and exit early.

Fixes Rust-GCC#4161
gcc/rust/ChangeLog:

	* backend/rust-compile-stmt.cc (CompileStmt::visit): Check for
	error_mark_node in init expression for TuplePatterns and exit
	early if found.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4161.rs: New test.

Signed-off-by: Harishankar P P <harishankarpp7@gmail.com>
@Harishankar14

This comment was marked as outdated.

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right place to check for this case, it should be in the PathInExpression piece it hits the code there for a more general case i think to start off to investigate there

if (stmt.get_pattern ().get_pattern_type ()
== HIR::Pattern::PatternType::TUPLE)
{
if (!seen_error ())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt the right place to check for this i've loioked into this before there is a more general case we should be trying to catch this its during path code gen not stmt.

Also in your git commit subject you mention type-check.. this is not the type check pass.

@Harishankar14
Copy link
Contributor Author

@philberty Interesting !! Thanks for the pointer on the previous iteration! I’ve reverted the changes in rust-compile-stmt.cc and moved the logic to the PathInExpression handling as you suggested, the flow was bit confusing to understand.

It turned into a bit of a chain reaction to get this fully stable, but here is what I ended up doing:

  1. The Core Fix: I modified ResolvePathRef::resolve_with_node_id (in rust-compile-resolve-path.cc) to handle cases where the type lookup fails (returning false). Instead of asserting/crashing there, I added a check to print a backend error and return error_mark_node so the compiler can recover.

  2. Fixing Downstream ICEs: Once I let the error propagate, it triggered crashes further down the pipeline that I also had to patch:

  • Pattern Compilation: rust-compile-pattern.cc was crashing because TYPE_MAIN_VARIANT tried to access the error_mark_node. I added a guard clause in CompilePatternLet::visit to return early if the init expression is invalid.
  • Linter/Dead Code: The MarkLive pass was asserting when it couldn't look up the HIR ID for the broken Type Alias. I updated rust-lint-marklive.cc to simply skip marking the item as live if the lookup fails, rather than hitting rust_unreachable().

3.Now the issue, which am facing is that it doesn't really throw up an error tbh, it let's it reside silently, which is indeed a huge issue.

I will mark this as draft for now, and will let you know.

@Harishankar14 Harishankar14 marked this pull request as draft January 21, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in visit, at rust/backend/rust-compile-pattern.cc:1255

3 participants