aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2025-07-15 12:04:53 -0400
committerArthur Cohen <arthur.cohen@embecosm.com>2025-08-05 16:37:03 +0200
commit9938133aca92cdab34b9c979162f3626244e57a6 (patch)
treecd944fd97ceec849cc6595c5ff503e5a87303181
parent95c619976ff94dff1b84a5cff7e65a640d667996 (diff)
downloadgcc-9938133aca92cdab34b9c979162f3626244e57a6.zip
gcc-9938133aca92cdab34b9c979162f3626244e57a6.tar.gz
gcc-9938133aca92cdab34b9c979162f3626244e57a6.tar.bz2
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 <powerboat9.gamer@gmail.com>
-rw-r--r--gcc/rust/expand/rust-macro-builtins-helpers.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-helpers.cc b/gcc/rust/expand/rust-macro-builtins-helpers.cc
index 19af5df..ee01f65 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<AST::LiteralExpr>
try_extract_string_literal_from_fragment (const location_t &parent_locus,
std::unique_ptr<AST::Expr> &node)
{
- auto maybe_lit = static_cast<AST::LiteralExpr *> (node.get ());
if (!node || !node->is_literal ()
- || maybe_lit->get_lit_type () != AST::Literal::STRING)
+ || static_cast<AST::LiteralExpr &> (*node).get_lit_type ()
+ != AST::Literal::STRING)
{
rust_error_at (parent_locus, "argument must be a string literal");
if (node)