https://gcc.gnu.org/g:b814745a97265b29fb307e04a21ebe6a34e13892
commit r17-5151-gb814745a97265b29fb307e04a21ebe6a34e13892 Author: Yap Zhi Heng <[email protected]> Date: Sun Sep 20 23:03:39 2026 +0800 gccrs: Remove -frust-c-style-string-literals flag This is replaced with -frust-compat-version=<1.64 instead. gcc/rust/ChangeLog: * lang.opt: Remove frust-c-style-string-literals option. * rust-session-manager.h (Session): New should_support_cstr_parsing function. * parse/rust-parse-impl-expr.hxx (Parser<ManagedTokenSource>::parse_literal_expr): Replace old flag_c_style_string_literals check with should_support_cstr_parsing. (Parser<ManagedTokenSource>::null_denotation_not_path): Likewise. * parse/rust-parse.h: Import rust-session-manager.h to access Session class. gcc/testsuite/ChangeLog: * rust/compile/c_string_null_byte_check.rs: Remove frust-c-style-string-literals from compilation options. * rust/execute/torture/c_string_ensure_null_term.rs: Likewise. * rust/execute/torture/c_string.rs: Likewise. Signed-off-by: Yap Zhi Heng <[email protected]> Diff: --- gcc/rust/lang.opt | 4 ---- gcc/rust/parse/rust-parse-impl-expr.hxx | 8 ++++---- gcc/rust/parse/rust-parse.h | 1 + gcc/rust/rust-session-manager.h | 5 +++++ gcc/testsuite/rust/compile/c_string_null_byte_check.rs | 2 +- gcc/testsuite/rust/execute/torture/c_string.rs | 2 +- gcc/testsuite/rust/execute/torture/c_string_ensure_null_term.rs | 2 +- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gcc/rust/lang.opt b/gcc/rust/lang.opt index f996ec0f0a58..a94fd0f893b0 100644 --- a/gcc/rust/lang.opt +++ b/gcc/rust/lang.opt @@ -237,8 +237,4 @@ frust-unused-check-2.0 Rust Var(flag_unused_check_2_0) Use the new unused variable check implementation. -frust-c-style-string-literals -Rust Var(flag_c_style_string_literals) -Enable parsing and compilation of C-styled string literals. - ; This comment is to ensure we retain the blank line above. diff --git a/gcc/rust/parse/rust-parse-impl-expr.hxx b/gcc/rust/parse/rust-parse-impl-expr.hxx index 127b2c7a2fd7..f42bf9a13cf2 100644 --- a/gcc/rust/parse/rust-parse-impl-expr.hxx +++ b/gcc/rust/parse/rust-parse-impl-expr.hxx @@ -344,7 +344,7 @@ Parser<ManagedTokenSource>::parse_literal_expr (AST::AttrVec outer_attrs) break; case C_STRING_LITERAL: { - if (flag_c_style_string_literals) + if (Session::get_instance ().should_support_cstr_parsing ()) { type = AST::Literal::C_STRING; literal_value = t->get_str (); @@ -356,7 +356,7 @@ Parser<ManagedTokenSource>::parse_literal_expr (AST::AttrVec outer_attrs) Error (t->get_locus (), "unexpected token %qs when parsing literal expression - " "C-style string literals require " - "%<-frust-c-style-string-literals%> to be enabled", + "%<-frust-compat-version%> to be set to least 1.64", t->get_token_description ())); return tl::unexpected<Parse::Error::Node> ( Parse::Error::Node::MALFORMED); @@ -2134,7 +2134,7 @@ Parser<ManagedTokenSource>::null_denotation_not_path ( new AST::LiteralExpr (tok->get_str (), AST::Literal::RAW_STRING, tok->get_type_hint (), {}, tok->get_locus ())); case C_STRING_LITERAL: - if (flag_c_style_string_literals) + if (Session::get_instance ().should_support_cstr_parsing ()) { return std::unique_ptr<AST::LiteralExpr> ( new AST::LiteralExpr (tok->get_str (), AST::Literal::C_STRING, @@ -2145,7 +2145,7 @@ Parser<ManagedTokenSource>::null_denotation_not_path ( { Error error (tok->get_locus (), "C-style string literals require " - "%<-frust-c-style-string-literals%> to be enabled"); + "%<-frust-compat-version%> to be set to least 1.64"); add_error (std::move (error)); return tl::unexpected<Parse::Error::Expr> ( Parse::Error::Expr::MALFORMED); diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 7b0da58c5cbb..4b389a827642 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. If not see #include "rust-parse-utils.h" #include "rust-feature.h" #include "rust-feature-store.h" +#include "rust-session-manager.h" #include "expected.h" #include "options.h" diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h index 9f0209b90fdd..6a0acda7c1a2 100644 --- a/gcc/rust/rust-session-manager.h +++ b/gcc/rust/rust-session-manager.h @@ -507,6 +507,11 @@ public: int get_compat_version () const { return options.get_compat_version (); } + bool should_support_cstr_parsing () const + { + return get_compat_version () >= 64; + } + bool should_support_offset_of () const { return get_compat_version () >= 71; } bool should_support_cfg_select () const diff --git a/gcc/testsuite/rust/compile/c_string_null_byte_check.rs b/gcc/testsuite/rust/compile/c_string_null_byte_check.rs index 57dfe8623cae..2b4f4bdd1c71 100644 --- a/gcc/testsuite/rust/compile/c_string_null_byte_check.rs +++ b/gcc/testsuite/rust/compile/c_string_null_byte_check.rs @@ -1,4 +1,4 @@ -// { dg-additional-options "-frust-c-style-string-literals -frust-compat-version=1.90" } +// { dg-additional-options "-frust-compat-version=1.90" } #![feature(no_core, lang_items)] #![no_core] diff --git a/gcc/testsuite/rust/execute/torture/c_string.rs b/gcc/testsuite/rust/execute/torture/c_string.rs index be90e4e1c34c..b8d60cac87d6 100644 --- a/gcc/testsuite/rust/execute/torture/c_string.rs +++ b/gcc/testsuite/rust/execute/torture/c_string.rs @@ -1,4 +1,4 @@ -// { dg-additional-options "-frust-c-style-string-literals -frust-compat-version=1.90" } +// { dg-additional-options "-frust-compat-version=1.90" } // { dg-output "gccrs" } #![feature(no_core, lang_items)] #![no_core] diff --git a/gcc/testsuite/rust/execute/torture/c_string_ensure_null_term.rs b/gcc/testsuite/rust/execute/torture/c_string_ensure_null_term.rs index 488d9fdcd5a4..2ba0d06efe92 100644 --- a/gcc/testsuite/rust/execute/torture/c_string_ensure_null_term.rs +++ b/gcc/testsuite/rust/execute/torture/c_string_ensure_null_term.rs @@ -1,4 +1,4 @@ -// { dg-additional-options "-frust-c-style-string-literals -frust-compat-version=1.90" } +// { dg-additional-options "-frust-compat-version=1.90" } #![feature(no_core, intrinsics, staged_api, lang_items)] #![no_core]
