From: Owen Avery Date: Tue, 15 Jul 2025 16:04:53 +0000 (-0400) Subject: gccrs: Remove undefined behavior with static_cast X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9938133aca92cdab34b9c979162f3626244e57a6;p=thirdparty%2Fgcc.git gccrs: Remove undefined behavior with static_cast gcc/rust/ChangeLog: * expand/rust-macro-builtins-helpers.cc (try_extract_string_literal_from_fragment): Perform static_cast to AST::LiteralExpr only after it's verified that an AST::Expr is a literal. Signed-off-by: Owen Avery --- diff --git a/gcc/rust/expand/rust-macro-builtins-helpers.cc b/gcc/rust/expand/rust-macro-builtins-helpers.cc index 19af5df4a68..ee01f65d8a1 100644 --- a/gcc/rust/expand/rust-macro-builtins-helpers.cc +++ b/gcc/rust/expand/rust-macro-builtins-helpers.cc @@ -111,9 +111,9 @@ std::unique_ptr try_extract_string_literal_from_fragment (const location_t &parent_locus, std::unique_ptr &node) { - auto maybe_lit = static_cast (node.get ()); if (!node || !node->is_literal () - || maybe_lit->get_lit_type () != AST::Literal::STRING) + || static_cast (*node).get_lit_type () + != AST::Literal::STRING) { rust_error_at (parent_locus, "argument must be a string literal"); if (node)