From patchwork Wed Jul 8 00:30:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gerris.rs@gmail.com X-Patchwork-Id: 138696 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C0FDF4BA2E22 for ; Wed, 8 Jul 2026 00:31:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0FDF4BA2E22 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=NA08sOIG X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id D4BD74BA2E15 for ; Wed, 8 Jul 2026 00:30:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D4BD74BA2E15 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D4BD74BA2E15 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783470645; cv=none; b=UMdrTpy9sKT++vlF/jzJw+lLhtRkR64sRCv8d7WZBhUBg3GE7RviE+aro5E5hVFRNOI5/5KQGAbeTqfpPAMt/G/HwgLnlZZRzowVclNQkSgS89CRGNfK6r7uitecr2H8iSiOLvMY2gYSEwscspziM3S+TJqBMGOzSJGPN3ekyUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783470645; c=relaxed/simple; bh=xPnFA15AQ5ZoFDDhyXbgqFOeGEBg9NOxcPVmnWoup3E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J+PRmZImdJ7GbuX8IGZRWAvEQky2RpXlZKwGrOWsdlKVu3lhWkdyqeN0GgJu8nDj1p8n1HWkiBCLVqhjManYx3sERKbxREEV3kt8R/rHcN6jIBLnkZbr4B1wZOA+iYEmM9Z1PQaR2abPn1Nuk1Bm/AAF/bqxkMDaeMGUgLUKwG4= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=NA08sOIG DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4BD74BA2E15 Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-8eeadbc5e21so851166d6.3 for ; Tue, 07 Jul 2026 17:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783470645; x=1784075445; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=ak45Xev/2kJXOqOddFG/F5N+IQzgih1hw9yIs+xgYZw=; b=NA08sOIGpugyuXpxfBKcS08YVvEFH7VwYaNGobPiIVOJEhG2wyrqAO9FwyQ/7iwhEp 5UqRfqIjf/6Ga+E9AJ4YcqUwa6lvVwhbLbZjTZCt/uThpu3k6a6V88hCQ7TILgZGFXjK dBclRttCIm0GX2mIOtPItFuFfyWBU+LvHFp0cbQRdud9I9bUuqYk6WZYiF1Q+f6OuQsq RmmRAijaogGBDAB2+34SmjQghymoNOIexnYFVzDT4pksdV5GKM/65w0LJcq9YZU3hm2h Y0zI3UWVJY1XNtLx+26WxuIDJTaHkI16Rp/A/VDASLqxsHzB9ybQF7UHtfZybNchp3hn F4/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783470645; x=1784075445; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ak45Xev/2kJXOqOddFG/F5N+IQzgih1hw9yIs+xgYZw=; b=flMXX3G7dQJOW6bwk6VaMOzOaeJIzhCb/2bfefSuC3yHc730vkd/swirNGFoTRL4/4 Ly0V4+qjrXa8tUpsIpjW1a4alg4Zww9bQLL2ingidSjQy5Qh6k5csL45RVJVLH0+/g1w vy3qwmrg10DPmBHDoSbR6AS11SQe8Ipx/xY0FoWNo6CecZhJlSDPcVOmNPBD7chWF5tQ vsXzqd8F9PO2u0l4SNW6dqJwKwdAqOGJsd4fA7hpVhP6zvEYBKqW1fOrQ4uAq3atjGMP 6tETBx55frWfPVUjqrRBxcRJtfJ4lUI67vMYsEfLbhdUVGp+y3Iv1S+HjQ75h5qo/Je/ cqNw== X-Gm-Message-State: AOJu0YwO+vHzOPz0Q+zXpo2bRZwXT+B+wgZAgk5VrFqm0NduJN8ekXkC sCAIIOsa+YGpfpUtickl0EoweJ3i7XHOyOf1G73Ylbh03HXHvoVxFpxchirM6g== X-Gm-Gg: AfdE7cnLgT7XwVmRzPdQD+gS6qYDlm/42mVfbp7ildlTxcrZxnAyDRYSiNRuwsy/xdy 19szTeMnuQ8oPF1S2LFo5t0uQGhsukeIQbM66TiLaNVt6UQtgMQW8mHXxoU6e+EAKAKUFdfKJVR odCiEb17y1IW2oEk9S8/xNGHYZpoSAFWvB+rR9831XhAza1FJnlLJ7E188vuGCqQe+l1qWRfe4K 1l1lL/YcpkJOUrMLUdUXrTO3zco9IBrfmt9bcrVxC2v1AB5p4LUe3kGSynhaGKudVlNNnRoHxtq 7mUcAYzRJz0xtSAaUG96S8xKayxeNyk3VA8lRt2dGkth6YUgLF9oEHBC2f4q0bzLuq1hXBLy1dn YTGySfhAkyt59vHg/BFs8hvN4rS1TgC6SWTPZ75ObAsZ7w3PlJPbr1gvgLJQ8MpeSe67FKiw4Pw UXIs6vJ9UCYZ27W7KSvqIzCjljziHW5YO2ze20SqU/HnMoK+Ne2Sy2QtOA67wbmT5+KyR2agmIb 2ewD0AKKzo2 X-Received: by 2002:a05:6214:3d0f:b0:8f0:b50f:dd1 with SMTP id 6a1803df08f44-8fec07d3d65mr190316d6.5.1783470645091; Tue, 07 Jul 2026 17:30:45 -0700 (PDT) Received: from runnervmkkn4f.m5kpmtvhf15edb5qvthl1r1zqf.ex.internal.cloudapp.net ([135.232.200.20]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8f471813d49sm169403376d6.27.2026.07.07.17.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 17:30:44 -0700 (PDT) From: gerris.rs@gmail.com To: gcc-patches@gcc.gnu.org, gcc-rust@gcc.gnu.org Cc: pierre-emmanuel.patry@embecosm.com, arthur.cohen@embecosm.com, dkm+gccrs@kataplop.net, Owen Avery Subject: [gccrs COMMIT] gccrs: Add compatible version option Date: Wed, 8 Jul 2026 00:30:43 +0000 Message-ID: <20260708003043.3092-1-gerris.rs@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Owen Avery GCCRS targets version 1.49 of rust. However, rust for linux expects rust 1.78 or later (soon 1.85 or later) and we will want to bump our main target version from 1.49 eventually. This patch adds an option for the user to specify a rust version to target for compatibility, so that we can account for backwards incompatible behavior between rust versions. This should allow libcore 1.49 to compile without explicitly enabling post-1.49 features. gcc/rust/ChangeLog: * checks/errors/feature/rust-feature-collector.cc: Include "rust-session-manager.h". (FeatureCollector::collect): Automatically enable EXTENDED_KEY_VALUE_ATTRIBUTES when targeting compatibility with rust versions before 1.50. * expand/rust-macro-expand.cc: Include "rust-session-manager.h". (MacroExpander::expand_invoc): Use Session to determine whether offset_of is supported. * lang.opt (frust-assume-builtin-offset-of): Remove option, superseded by... (frust-compat-version): ...new option. * resolve/rust-early-name-resolver-2.0.cc: Include "rust-session-manager.h". (Early::visit (MacroInvocation)): Use Session to determine whether offset_of is supported. * rust-session-manager.cc (Session::handle_option): Handle frust-compat-version. * rust-session-manager.h (CompileOptions::compat_version): New member variable. (CompileOptions::set_compat_version): New member function. (CompileOptions::get_compat_version): Likewise. (Session::get_compat_version): Likewise. (Session::should_support_offset_of): Likewise. gcc/testsuite/ChangeLog: * rust/compile/early_feature_gate_in_macro.rs: Change test options. * rust/compile/offset_of1.rs: Likewise. * rust/compile/offset_of2.rs: Likewise. * rust/compile/parse_time_feature_gate.rs: Likewise. * rust/execute/torture/offset_of1.rs: Likewise. Signed-off-by: Owen Avery --- 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/5d40f402ffe51bbea5746bab076b8d02e452db30 The commit has NOT been mentioned in any issue. The commit has been mentioned in the following pull-request(s): - https://github.com/Rust-GCC/gccrs/pull/4659 .../errors/feature/rust-feature-collector.cc | 6 ++++ gcc/rust/expand/rust-macro-expand.cc | 3 +- gcc/rust/lang.opt | 6 ++-- .../resolve/rust-early-name-resolver-2.0.cc | 5 ++-- gcc/rust/rust-session-manager.cc | 3 ++ gcc/rust/rust-session-manager.h | 30 +++++++++++++++++++ .../compile/early_feature_gate_in_macro.rs | 1 + gcc/testsuite/rust/compile/offset_of1.rs | 2 +- gcc/testsuite/rust/compile/offset_of2.rs | 2 +- .../rust/compile/parse_time_feature_gate.rs | 1 + .../rust/execute/torture/offset_of1.rs | 2 +- 11 files changed, 52 insertions(+), 9 deletions(-) base-commit: 836bd832f52d2becdfaf6c2103cada5bf7054e1b diff --git a/gcc/rust/checks/errors/feature/rust-feature-collector.cc b/gcc/rust/checks/errors/feature/rust-feature-collector.cc index 6a3a14792..bd5a910d9 100644 --- a/gcc/rust/checks/errors/feature/rust-feature-collector.cc +++ b/gcc/rust/checks/errors/feature/rust-feature-collector.cc @@ -18,6 +18,7 @@ #include "rust-feature-collector.h" #include "rust-attribute-values.h" +#include "rust-session-manager.h" namespace Rust { namespace Features { @@ -32,6 +33,11 @@ FeatureCollector::collect (AST::Crate &crate) features.valid_lib_features.clear (); features.crate_id = crate.get_node_id (); + // TODO: this is a hack, remove when possible + if (Session::get_instance ().get_compat_version () < 50) + features.valid_lang_features.insert ( + Feature::Name::EXTENDED_KEY_VALUE_ATTRIBUTES); + visit (crate); return features; diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index c06290cdf..2ab9d2541 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -29,6 +29,7 @@ #include "rust-cfg-strip.h" #include "rust-proc-macro.h" #include "rust-token-tree-desugar.h" +#include "rust-session-manager.h" namespace Rust { @@ -311,7 +312,7 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, // We special case the `offset_of!()` macro if the flag is here and manually // resolve to the builtin transcriber we have specified auto assume_builtin_offset_of - = flag_assume_builtin_offset_of + = Session::get_instance ().should_support_offset_of () && (invoc.get_invoc_data ().get_path ().as_string () == "offset_of") && !rules_def; diff --git a/gcc/rust/lang.opt b/gcc/rust/lang.opt index 1d38fec86..f996ec0f0 100644 --- a/gcc/rust/lang.opt +++ b/gcc/rust/lang.opt @@ -229,9 +229,9 @@ frust-overflow-checks Rust Var(flag_overflow_checks) Init(1) Enable the overflow checks in code generation. -frust-assume-builtin-offset-of -Rust Var(flag_assume_builtin_offset_of) -Define a built-in offset_of macro in the compiler and assume it is present. +frust-compat-version= +Rust Joined RejectNegative Var(flag_rust_compat_version) +Select a version of rust to target for compatibility. Must be of form '1.x' or 'max'. frust-unused-check-2.0 Rust Var(flag_unused_check_2_0) diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc index 0c5422d2c..854102ff9 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -30,6 +30,7 @@ #include "rust-finalize-imports-2.0.h" #include "rust-attribute-values.h" #include "rust-identifier-path.h" +#include "rust-session-manager.h" namespace Rust { namespace Resolver2_0 { @@ -318,8 +319,8 @@ Early::visit (AST::MacroInvocation &invoc) // We special case the `offset_of!()` macro if the flag is here, otherwise // we accept whatever `offset_of!()` definition we resolved to. - auto resolve_offset_of - = flag_assume_builtin_offset_of && (path.as_string () == "offset_of"); + auto resolve_offset_of = Session::get_instance ().should_support_offset_of () + && (path.as_string () == "offset_of"); if (invoc.get_kind () == AST::MacroInvocation::InvocKind::Builtin) for (auto &pending_invoc : invoc.get_pending_eager_invocations ()) diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 011ca8b99..6a56c956d 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -289,6 +289,9 @@ Session::handle_option ( case OPT_frust_edition_: options.set_edition (flag_rust_edition); break; + case OPT_frust_compat_version_: + options.set_compat_version (flag_rust_compat_version); + break; case OPT_frust_compile_until_: options.set_compile_step (flag_rust_compile_until); break; diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h index 930012a7b..af5a700b8 100644 --- a/gcc/rust/rust-session-manager.h +++ b/gcc/rust/rust-session-manager.h @@ -242,6 +242,8 @@ struct CompileOptions bool debug_assertions = false; std::string metadata_output_path; + int compat_version = 49; + /** Structure containing additional attributes to be injected within the * compiled crate from the command line instead of the source code. * @@ -344,6 +346,30 @@ struct CompileOptions const Edition &get_edition () const { return edition; } + void set_compat_version (const char *version) + { + if (!strcmp (version, "max")) + { + compat_version = INT_MAX; + return; + } + + long res; + char *end_ptr; + if (version[0] != '1' || version[1] != '.' || version[2] == '\0' + || (res = strtol (version + 2, &end_ptr, 10), *end_ptr) || res < 0 + || res > INT_MAX) + { + rust_error_at (UNKNOWN_LOCATION, + "compat version must be of form 1.x or be \"max\""); + return; + } + + compat_version = res; + } + + int get_compat_version () const { return compat_version; } + void set_crate_type (int raw_type) { target_data.set_crate_type (raw_type); } bool is_proc_macro () const @@ -474,6 +500,10 @@ public: tl::expected load_extern_crate (const std::string &crate_name, location_t locus); + int get_compat_version () const { return options.get_compat_version (); } + + bool should_support_offset_of () const { return get_compat_version () >= 71; } + private: Session () : mappings (Analysis::Mappings::get ()) {} void compile_crate (const char *filename); diff --git a/gcc/testsuite/rust/compile/early_feature_gate_in_macro.rs b/gcc/testsuite/rust/compile/early_feature_gate_in_macro.rs index 9e2a51027..dd68b920e 100644 --- a/gcc/testsuite/rust/compile/early_feature_gate_in_macro.rs +++ b/gcc/testsuite/rust/compile/early_feature_gate_in_macro.rs @@ -1,3 +1,4 @@ +// { dg-additional-options "-frust-compat-version=1.50" } #![feature(rustc_attrs)] #![feature(lang_items)] #![feature(no_core)] diff --git a/gcc/testsuite/rust/compile/offset_of1.rs b/gcc/testsuite/rust/compile/offset_of1.rs index 2fca6d5ee..ff1bd4a21 100644 --- a/gcc/testsuite/rust/compile/offset_of1.rs +++ b/gcc/testsuite/rust/compile/offset_of1.rs @@ -1,4 +1,4 @@ -// { dg-additional-options "-frust-compile-until=lowering -frust-assume-builtin-offset-of" } +// { dg-additional-options "-frust-compile-until=lowering -frust-compat-version=1.71" } #![feature(no_core)] #![no_core] diff --git a/gcc/testsuite/rust/compile/offset_of2.rs b/gcc/testsuite/rust/compile/offset_of2.rs index 2f2fa00a3..143aab1e0 100644 --- a/gcc/testsuite/rust/compile/offset_of2.rs +++ b/gcc/testsuite/rust/compile/offset_of2.rs @@ -1,4 +1,4 @@ -// { dg-additional-options "-frust-compile-until=compilation -frust-assume-builtin-offset-of" } +// { dg-additional-options "-frust-compile-until=compilation -frust-compat-version=1.71" } #![feature(no_core)] #![no_core] diff --git a/gcc/testsuite/rust/compile/parse_time_feature_gate.rs b/gcc/testsuite/rust/compile/parse_time_feature_gate.rs index 907ac0c51..1affcd81a 100644 --- a/gcc/testsuite/rust/compile/parse_time_feature_gate.rs +++ b/gcc/testsuite/rust/compile/parse_time_feature_gate.rs @@ -1,3 +1,4 @@ +// { dg-additional-options "-frust-compat-version=1.50" } #![feature(no_core)] #![no_core] #![feature(rustc_attrs)] diff --git a/gcc/testsuite/rust/execute/torture/offset_of1.rs b/gcc/testsuite/rust/execute/torture/offset_of1.rs index d8ab9eba4..9d17b2bb2 100644 --- a/gcc/testsuite/rust/execute/torture/offset_of1.rs +++ b/gcc/testsuite/rust/execute/torture/offset_of1.rs @@ -1,5 +1,5 @@ // { dg-do run { target x86_64*-*-* } } -// { dg-additional-options "-frust-assume-builtin-offset-of" } +// { dg-additional-options "-frust-compat-version=1.71" } #![feature(no_core)] #![no_core]