From: jayant chauhan <[email protected]>
The parse_anon_const function triggered an assertion failure (ICE) when
receiving a success Result containing a null expression pointer. This
occurred because null_denotation_path directly returned the result of
parse_macro_invocation_partial (which returns a raw pointer) without
checking for failure.
When parse_macro_invocation_partial failed (returning nullptr), it was
wrapped into a tl::expected success state containing nullptr, rather than
an error state.
This patch adds a check in null_denotation_path to verify if the parsed
macro invocation is null. If it is, it now returns a tl::unexpected error,
ensuring that invalid expressions are correctly reported as errors
upstream.
Fixes Rust-GCC#4412
gcc/rust/ChangeLog:
* parse/rust-parse-impl-expr.hxx (null_denotation_path): Check
if macro invocation returns null and return error.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4412.rs: New test.
Signed-off-by: Jayant Chauhan <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/cb12ae0400cf3b4419c9b9fe145e82440355e1d3
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4420
gcc/rust/parse/rust-parse-impl-expr.hxx | 12 +++++++++---
gcc/testsuite/rust/compile/issue-4412.rs | 9 +++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-4412.rs
diff --git a/gcc/rust/parse/rust-parse-impl-expr.hxx
b/gcc/rust/parse/rust-parse-impl-expr.hxx
index 4de5599d6..2a2d844b7 100644
--- a/gcc/rust/parse/rust-parse-impl-expr.hxx
+++ b/gcc/rust/parse/rust-parse-impl-expr.hxx
@@ -1957,9 +1957,15 @@ Parser<ManagedTokenSource>::null_denotation_path (
switch (t->get_id ())
{
case EXCLAM:
- // macro
- return parse_macro_invocation_partial (std::move (path),
- std::move (outer_attrs));
+ {
+ // macro
+ auto macro = parse_macro_invocation_partial (std::move (path),
+ std::move (outer_attrs));
+ if (macro == nullptr)
+ return tl::unexpected<Parse::Error::Expr> (
+ Parse::Error::Expr::CHILD_ERROR);
+ return std::unique_ptr<AST::Expr> (std::move (macro));
+ }
case LEFT_CURLY:
{
bool not_a_block = lexer.peek_token (1)->get_id () == IDENTIFIER
diff --git a/gcc/testsuite/rust/compile/issue-4412.rs
b/gcc/testsuite/rust/compile/issue-4412.rs
new file mode 100644
index 000000000..6ed93d0d7
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4412.rs
@@ -0,0 +1,9 @@
+// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use" }
+#![feature(no_core)]
+#![no_core]
+struct Bug([u8; panic!"\t"]);
+// { dg-error "unexpected token" "" { target *-*-* } .-1 }
+// { dg-error "failed to parse" "" { target *-*-* } .-2 }
+// { dg-error "could not parse" "" { target *-*-* } .-3 }
+// { dg-error "expecting" "" { target *-*-* } .-4 }
+fn main() {}
\ No newline at end of file
base-commit: 3ecd7b90c984f5f15b1a1313b943af36893f4199
--
2.52.0