Skip to content

gccrs: avoid ICE when canonical path record is missing#4415

Open
shreyas-omkar wants to merge 1 commit intoRust-GCC:masterfrom
shreyas-omkar:ice-get-record-fix
Open

gccrs: avoid ICE when canonical path record is missing#4415
shreyas-omkar wants to merge 1 commit intoRust-GCC:masterfrom
shreyas-omkar:ice-get-record-fix

Conversation

@shreyas-omkar
Copy link

Fixes #4143

This fixes an Internal Compiler Error (ICE) in canonical path resolution triggered by const-generic expressions containing inline item definitions (e.g. structs inside const blocks).

Previously, CanonicalPathCtx::get_record unconditionally asserted that a canonical path record exists for a NodeId. However, not all AST nodes (e.g. inline items in const expressions) are guaranteed to have canonical paths, leading to an ICE.

Introduce optional canonical path lookup and update callers to handle the absence of a canonical path explicitly, avoiding the assertion failure.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h (CanonicalPathCtx::get_path_opt): New helper returning an optional canonical path.
* resolve/rust-name-resolution-context.cc: Use optional canonical path lookup instead of asserting on missing records.
* testsuite/rust/compile/issue-4143.rs: New regression test.

@shreyas-omkar shreyas-omkar force-pushed the ice-get-record-fix branch 6 times, most recently from ed34bbd to d943657 Compare February 6, 2026 14:11
@dkm
Copy link
Member

dkm commented Feb 6, 2026

Hello!

The changelog part should points to actual function/type:

* resolve/rust-name-resolution-context.cc: Use optional canonical
	path lookup instead of asserting on missing records.

You probably need to use (CanonicalPathCtx::get_path) after the .cc file entry :)

Also note that you're modifying the get_path in the .h (moving the definition in the .cc: you should also mention that :)

Thanks!

@shreyas-omkar
Copy link
Author

shreyas-omkar commented Feb 6, 2026

Thank You. :)

Also please can you take a look at the PR?

@shreyas-omkar shreyas-omkar force-pushed the ice-get-record-fix branch 3 times, most recently from 50107cb to ee52e7b Compare February 10, 2026 12:55
This fixes an Internal Compiler Error (ICE) in canonical path resolution
triggered by const-generic expressions containing inline item
definitions (e.g. structs inside const blocks).

Previously, CanonicalPathCtx::get_path unconditionally accessed a
canonical path record via get_record, asserting that such a record
always exists. However, some AST nodes (e.g. inline items inside const
expressions) are not guaranteed to have canonical paths, leading to an
ICE.

Update canonical path lookup to be optional and handle the absence of a
record explicitly, avoiding the assertion failure.

gcc/rust/ChangeLog:

	* resolve/rust-name-resolution-context.h
	(CanonicalPathCtx::get_path): Move implementation to source file.
	(CanonicalPathCtx::get_path_opt): New helper returning an optional
	canonical path.

	* resolve/rust-name-resolution-context.cc
	(CanonicalPathCtx::get_path): Use optional canonical path lookup
	and return empty path instead of asserting on missing records.

Signed-off-by: shreyas-omkar <shreyashegdeplus06@gmail.com>
@shreyas-omkar
Copy link
Author

Hi @dkm Please take a look at PR.

if (auto rec = get_record_opt (id))
return (*rec)->as_path (*nr_ctx);

return Resolver::CanonicalPath::create_empty ();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing canonical paths shouldn't be silently replaced with empty paths

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.

ICE in get_record, at rust/resolve/rust-name-resolution-context.h:370

3 participants