{"id":2223273,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2223273/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260414231905.191063-9-arthur.cohen@embecosm.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.2/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260414231905.191063-9-arthur.cohen@embecosm.com>","list_archive_url":null,"date":"2026-04-14T23:18:30","name":"[COMMITTED,09/43] gccrs: Fix 128-bit non-decimal integer literal saturation","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"84f343adc3a7d8b4dda8feea514fe8f436aaa3ff","submitter":{"id":83476,"url":"http://patchwork.ozlabs.org/api/1.2/people/83476/?format=json","name":"Arthur Cohen","email":"arthur.cohen@embecosm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260414231905.191063-9-arthur.cohen@embecosm.com/mbox/","series":[{"id":499900,"url":"http://patchwork.ozlabs.org/api/1.2/series/499900/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=499900","date":"2026-04-14T23:18:24","name":"[COMMITTED,01/43] gccrs: testsuite:Add a testcase for setup_associated_types","version":1,"mbox":"http://patchwork.ozlabs.org/series/499900/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223273/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223273/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256\n header.s=google header.b=QS5dOpS5;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256\n header.s=google header.b=QS5dOpS5","sourceware.org;\n dmarc=none (p=none dis=none) header.from=embecosm.com","sourceware.org; spf=pass smtp.mailfrom=embecosm.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.128.67"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fwKtZ2lbSz1yHc\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 09:17:26 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 93AFE4BA23EF\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 23:17:24 +0000 (GMT)","from mail-wm1-f67.google.com (mail-wm1-f67.google.com\n [209.85.128.67])\n by sourceware.org (Postfix) with ESMTPS id 166754BA23D9\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 23:14:23 +0000 (GMT)","by mail-wm1-f67.google.com with SMTP id\n 5b1f17b1804b1-488af96f6b2so80924145e9.0\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 16:14:23 -0700 (PDT)","from platypus.localdomain (176-147-231-59.abo.bbox.fr.\n [176.147.231.59]) by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-488f1dd8806sm3325945e9.3.2026.04.14.16.14.20\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 14 Apr 2026 16:14:20 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 93AFE4BA23EF","OpenDKIM Filter v2.11.0 sourceware.org 166754BA23D9"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 166754BA23D9","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 166754BA23D9","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776208463; cv=none;\n b=efZVhb3tyi+NU2LQ3aALY+qvH8uKkWff6m7cGNSkNnfUf05UFyXIG7WOMF2zMkRlEMmM9wkgRaZoRchsNzvKqz6rZ+jkj8gsmxGAoIBz7TiEYUzNY8R1ByC39nlGK8A/NqoEwhmQ2AXI5nuPkW67VriUzTkscAnWNsumVvKaJ68=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776208463; c=relaxed/simple;\n bh=LArLlQ78bAJoX44/vLCmc5YCE7ZFPEu0lvPWtL+S4Mc=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=pdI/7KivW4dy0x8tqHl9Ehj5zl+76wSQsLVAnDwiBTe4oKIm/zyWvO4weSRz6wYLd6GKq+Q40Kkk7UmUUVwlZcnMt6Nt0CVrNVdn6gmCWFUE+MmjxZQ+c77zCUJbPPnzIgJgOclQbvWP87y8cmqMSNcqJRH9rSecGm2hAxdrFMw=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=embecosm.com; s=google; t=1776208462; x=1776813262; darn=gcc.gnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=W8F0hvTXc8LFbKBrOnL+MqnTutvMoePsUb5pWfpsoOk=;\n b=QS5dOpS5p3gQE72D86OE8tU81KlYjoghoGNNRJFyniCETnLlCfXla/SVVg79ArE9fK\n O0xwUBobKObC9pUNgiTBzNZtMLSVN6nhi+IRIdQjmY/5I5FP0AlVL1FkpRD/JdO2LEvp\n md4lUA0s8PFH+FhQPBzEdtnfvnkYugcXuK5Lg6gNWIsMfSuS8QkZcXto1FNV5FAKs588\n Ak/I1fxQE2v8aNTiRZgQIJiEpfhMY+Y5Xyc6iVzeerK/NBoqk6fshU3s8g8QMjrvqb4n\n COSt9/bC6BrNNAyAMpwyuDN/OB2KTn0zmr8uAOFMPLSLTIIhb7FmjEMpVghHGmbgEbCG\n VpoA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776208462; x=1776813262;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=W8F0hvTXc8LFbKBrOnL+MqnTutvMoePsUb5pWfpsoOk=;\n b=mBlsSrp2DpKhUgI1mpC3vdjvmp0ntD0BkoVDuN0sqULk/5jvy5AHBr0nFidN9Wd822\n m8whAzKxM7+t6Eff5eA0VA2kcr6GRVT65QJMneZHp6v/y2Q9ZafRH5ZcLviC6JOe2YZT\n jzEewxQQu92cijaWj6iY9xusrK8hz/vUYgaoogAcuIHI9RKcAkYd0/d0nLa1+6++osb3\n ucoqlJN2F359TcIo934oTha4M4Lz8pESYlvytciRivU6i2taFbdnWghmlaqKLT/NtrT3\n 3kGuAI3fS1WYV8+j2pYhs0B+3eO9WDfuCaz2zGlBwHmHWTwwjfSKrA3BMMAF+pswmqU9\n 26MQ==","X-Gm-Message-State":"AOJu0YyUyKeXKmixWgiI0IRWGd5Y8rFpgMzJ/D6JOpalz4NX1eDB84Fi\n XxJGtPeh37Et7srna0LXc7/IbTnWn13fUnaskLQGE5SOc3WlhGU9cpzFfvCEdZCYdXcphtcdQEg\n D01wUxhBB","X-Gm-Gg":"AeBDiesTxz6UU2UGnzo2tvPq4GMpRj1W2aXEs11bx377HusW7wQRRuWfgQEzX0rnzft\n noc9jyW/WsMfd17jIE+xfEsXjecrqVzb2px9nfL+3U7nUEjq0y6MmvXL/4DGys9G4pNzwEmz5ov\n GLtvMH/uRzXd9EkkFvw/gDkUa4qtsVwPvMKSNm1CddSqXw5VOgQXiKJ5O66Y0A71SK8kdPA79th\n yYKxZvhB55XFv7KwrYFDR82zHycLSvDtSitld25JtWBIen7AV3bM8cOyOOTLiL/ORxPeT+xYkdR\n 8bP6VzQit4F9SPC91yAn+O1QSzk6vi4PoeZdja67Hd4542iB1HdK3YGGurguLRiwedb9kP+jjpe\n unxQfkEf2DngyZU5MslUqcZ3mup87dCYoYJb7zmwEoH0ic3Cscm61N0kEmZoMV8bcnoCs7lrSmp\n lwj2D+GJ4A6LlphmKLRIzYX/wT0pKorHfZN4hp9INWYddgXg466osXNZrvP+he7nXx5xj/Q7ICT\n 6WiHvYqUTupYuiI","X-Received":"by 2002:a05:600c:19c8:b0:483:709e:f238 with SMTP id\n 5b1f17b1804b1-488d68ab2ccmr262200015e9.29.1776208461737;\n Tue, 14 Apr 2026 16:14:21 -0700 (PDT)","From":"arthur.cohen@embecosm.com","To":"gcc-patches@gcc.gnu.org","Cc":"gcc-rust@gcc.gnu.org,\n\tEnes Cevik <nsvke@proton.me>","Subject":"[COMMITTED 09/43] gccrs: Fix 128-bit non-decimal integer literal\n saturation","Date":"Wed, 15 Apr 2026 01:18:30 +0200","Message-ID":"<20260414231905.191063-9-arthur.cohen@embecosm.com>","X-Mailer":"git-send-email 2.50.1","In-Reply-To":"<20260414231905.191063-1-arthur.cohen@embecosm.com>","References":"<20260414231905.191063-1-arthur.cohen@embecosm.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"From: Enes Cevik <nsvke@proton.me>\n\nThis patch replaces std::strtol with GNU MP (GMP) for arbitrary-precision\nparsing to properly support 128-bit literals.\n\nAdditionally, it refactors the lexer by removing the redundant\n`existent_str` parameter from `parse_non_decimal_int_literal`. The base\nis now passed directly, and the parsed digits are collected internally,\nmaking the previous prefix-passing logic (\"0x\", \"0b\", \"0o\") obsolete\nand ensuring cleaner compatibility with mpz_set_str.\n\ngcc/rust/ChangeLog:\n\n\t* lex/rust-lex.cc (Lexer::parse_non_decimal_int_literal): Use GMP\n\tfor base conversion to support 128-bit literals. Remove existent_str\n\tparameter.\n\t(Lexer::parse_non_decimal_int_literals): Remove prefix string\n\tinitialization and update function calls.\n\t* lex/rust-lex.h (Lexer::parse_non_decimal_int_literal): Update\n\tfunction signature to remove existent_str.\n\ngcc/testsuite/ChangeLog:\n\n\t* rust/execute/non_decimal_128_saturation.rs: New test.\n\nSigned-off-by: Enes Cevik <nsvke@proton.me>\n---\n gcc/rust/lex/rust-lex.cc                      | 30 +++++++++----------\n gcc/rust/lex/rust-lex.h                       |  3 +-\n .../execute/non_decimal_128_saturation.rs     | 24 +++++++++++++++\n 3 files changed, 40 insertions(+), 17 deletions(-)\n create mode 100644 gcc/testsuite/rust/execute/non_decimal_128_saturation.rs","diff":"diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc\nindex 599358e44b3..681219160c5 100644\n--- a/gcc/rust/lex/rust-lex.cc\n+++ b/gcc/rust/lex/rust-lex.cc\n@@ -2239,8 +2239,10 @@ Lexer::parse_raw_string (location_t loc, int initial_hash_count)\n template <typename IsDigitFunc>\n TokenPtr\n Lexer::parse_non_decimal_int_literal (location_t loc, IsDigitFunc is_digit_func,\n-\t\t\t\t      std::string existent_str, int base)\n+\t\t\t\t      int base)\n {\n+  std::string raw_str;\n+\n   int length = 1;\n \n   skip_input ();\n@@ -2265,15 +2267,19 @@ Lexer::parse_non_decimal_int_literal (location_t loc, IsDigitFunc is_digit_func,\n       length++;\n \n       // add raw numbers\n-      existent_str += current_char;\n+      raw_str += current_char;\n       skip_input ();\n       current_char = peek_input ();\n     }\n \n   // convert value to decimal representation\n-  long dec_num = std::strtol (existent_str.c_str (), nullptr, base);\n-\n-  existent_str = std::to_string (dec_num);\n+  mpz_t dec_num;\n+  mpz_init (dec_num);\n+  mpz_set_str (dec_num, raw_str.c_str (), base);\n+  char *s = mpz_get_str (NULL, 10, dec_num);\n+  std::string dec_str = s;\n+  free (s);\n+  mpz_clear (dec_num);\n \n   // parse in type suffix if it exists\n   auto type_suffix_pair = parse_in_type_suffix ();\n@@ -2297,35 +2303,29 @@ Lexer::parse_non_decimal_int_literal (location_t loc, IsDigitFunc is_digit_func,\n \n   loc += length - 1;\n \n-  return Token::make_int (loc, std::move (existent_str), type_hint);\n+  return Token::make_int (loc, std::move (dec_str), type_hint);\n }\n \n // Parses a hex, binary or octal int literal.\n TokenPtr\n Lexer::parse_non_decimal_int_literals (location_t loc)\n {\n-  std::string str;\n-  str.reserve (16); // some sensible default\n-  str += current_char;\n-\n   current_char = peek_input ();\n \n   if (current_char == 'x')\n     {\n       // hex (integer only)\n-      return parse_non_decimal_int_literal (loc, is_x_digit, str + \"x\", 16);\n+      return parse_non_decimal_int_literal (loc, is_x_digit, 16);\n     }\n   else if (current_char == 'o')\n     {\n       // octal (integer only)\n-      return parse_non_decimal_int_literal (loc, is_octal_digit,\n-\t\t\t\t\t    std::move (str), 8);\n+      return parse_non_decimal_int_literal (loc, is_octal_digit, 8);\n     }\n   else if (current_char == 'b')\n     {\n       // binary (integer only)\n-      return parse_non_decimal_int_literal (loc, is_bin_digit, std::move (str),\n-\t\t\t\t\t    2);\n+      return parse_non_decimal_int_literal (loc, is_bin_digit, 2);\n     }\n   else\n     {\ndiff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h\nindex 31ba0921742..b14dffb2c9a 100644\n--- a/gcc/rust/lex/rust-lex.h\n+++ b/gcc/rust/lex/rust-lex.h\n@@ -154,8 +154,7 @@ private:\n \n   template <typename IsDigitFunc>\n   TokenPtr parse_non_decimal_int_literal (location_t loc,\n-\t\t\t\t\t  IsDigitFunc is_digit_func,\n-\t\t\t\t\t  std::string existent_str, int base);\n+\t\t\t\t\t  IsDigitFunc is_digit_func, int base);\n \n public:\n   // Construct lexer with input file and filename provided\ndiff --git a/gcc/testsuite/rust/execute/non_decimal_128_saturation.rs b/gcc/testsuite/rust/execute/non_decimal_128_saturation.rs\nnew file mode 100644\nindex 00000000000..5020d3cf432\n--- /dev/null\n+++ b/gcc/testsuite/rust/execute/non_decimal_128_saturation.rs\n@@ -0,0 +1,24 @@\n+// { dg-do run }\n+// { dg-require-effective-target lp64 }\n+// { dg-options \"-O0\" }\n+#![feature(no_core)]\n+#![no_core]\n+\n+fn main() -> i32 {\n+    let hex_val: u128 = 0x1_0000_0000_0000_0000_u128;\n+    if (hex_val >> 64) as u8 != 1 {\n+        return 1;\n+    }\n+\n+    let bin_val: u128 =\n+        0b1_00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000_u128;\n+    if (bin_val >> 64) as u8 != 1 {\n+        return 1;\n+    }\n+\n+    let oct_val: u128 = 0o2_000_000_000_000_000_000_000_u128;\n+    if (oct_val >> 64) as u8 != 1 {\n+        return 1;\n+    }\n+    0\n+}\n","prefixes":["COMMITTED","09/43"]}