Skip to content

Conversation

@Villosse
Copy link
Contributor

Fixes #4187

@Villosse Villosse force-pushed the 4187 branch 2 times, most recently from 8806a34 to 8248a16 Compare December 17, 2025 10:49
Fixes Rust-GCC#4187

We don't want to insert a nullpointer in the invocation map.
Also, the check for rules_def marked for strip is not safe as it could
be refering to a dangling pointer.

gcc/rust/ChangeLog:

	* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Remove unsafe check.
	(MacroExpander::expand_invoc): Check if rdef is null.
	* util/rust-hir-map.cc (Mappings::insert_macro_invocation): We
	stop to insert nullpointers to the invocation map.

Signed-off-by: lenny.chiadmi-delage <[email protected]>
Adds Tests of the issue 4187.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4187-1.rs: New test.
	* rust/compile/issue-4187-2.rs: New test.

Signed-off-by: lenny.chiadmi-delage <[email protected]>
@Villosse Villosse force-pushed the 4187 branch 2 times, most recently from 4905f0c to 9a20b54 Compare December 17, 2025 15:12
Comment on lines -43 to 51
rust_assert (!rules_def.is_marked_for_strip ());
/* Note: We can't safely check if rules_def is marked for strip here because
* rules_def might be a dangling pointer to a deleted macro definition.
* This can happen when a macro definition has an invalid attribute (such as
* #[x] where x is not an attribute macro), causing the item to be deleted
* during attribute processing, but the pointer in in the invocation map still
* exists.
*/
// rust_assert (!rules_def.is_marked_for_strip ());
rust_assert (rules_def.get_macro_rules ().size () > 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably should prevent rules_def from becoming a dangling pointer (somehow). Maybe by delaying the insertion of names corresponding to macro rules definitions into namespaces until after attributes on the definitions have been processed?

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.

segfault DefaultHIRVisitor, macros

2 participants