{"id":2231972,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2231972/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/b9e8a06e2d1fb139f4d3e06159c1784e359074ab.camel@tugraz.at/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/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},"msgid":"<b9e8a06e2d1fb139f4d3e06159c1784e359074ab.camel@tugraz.at>","date":"2026-05-01T19:21:34","name":"[C] argument expressions may be evaluated too often by typeof [PR124576]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a5ea67eb81943955e553c7420ad699794e944226","submitter":{"id":85465,"url":"http://patchwork.ozlabs.org/api/1.1/people/85465/?format=json","name":"Martin Uecker","email":"uecker@tugraz.at"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/b9e8a06e2d1fb139f4d3e06159c1784e359074ab.camel@tugraz.at/mbox/","series":[{"id":502491,"url":"http://patchwork.ozlabs.org/api/1.1/series/502491/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=502491","date":"2026-05-01T19:21:34","name":"[C] argument expressions may be evaluated too often by typeof [PR124576]","version":1,"mbox":"http://patchwork.ozlabs.org/series/502491/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2231972/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2231972/checks/","tags":{},"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 (1024-bit key;\n unprotected) header.d=tugraz.at header.i=@tugraz.at header.a=rsa-sha256\n header.s=mailrelay header.b=EUEkWaU8;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.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 (1024-bit key,\n unprotected) header.d=tugraz.at header.i=@tugraz.at header.a=rsa-sha256\n header.s=mailrelay header.b=EUEkWaU8","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=tugraz.at","sourceware.org; spf=pass smtp.mailfrom=tugraz.at","server2.sourceware.org;\n arc=none smtp.remote-ip=129.27.2.202"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 4g6gsS1Pk1z1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 02 May 2026 05:22:18 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id E284C4AA0961\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  1 May 2026 19:22:16 +0000 (GMT)","from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202])\n by sourceware.org (Postfix) with ESMTPS id 99F004BB58EB\n for <gcc-patches@gcc.gnu.org>; Fri,  1 May 2026 19:21:49 +0000 (GMT)","from vra-172-221.tugraz.at (vra-172-221.tugraz.at [129.27.172.221])\n by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4g6grb1gCLz2xLS;\n Fri,  1 May 2026 21:21:35 +0200 (CEST)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org E284C4AA0961","OpenDKIM Filter v2.11.0 sourceware.org 99F004BB58EB"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 99F004BB58EB","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 99F004BB58EB","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777663309; cv=none;\n b=jWs8fDTfUKfdZL7Rldk2FJchHbQv3DlozB0Yz6GjY4L6ZohI9O3T9dWMGZYOIjYbdbszLQ2/YBA5as3o0HQMNJu1M8fGQCnSTJ30e3wLHzo7giA8JjC8OpEz4oDlkuVt0U031A0SwMzNqAsUc6JC0DSDrXdtPi7JWjE2ihh/PDY=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777663309; c=relaxed/simple;\n bh=vNsFEEy9UU8O6BB/aeMd+YXcHhN/KADOTPfcEBt/o7c=;\n h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version;\n b=qZI1kVPsPKp4UZEUG6n6esEXkun/UnmVieTOFzktVOtY3Ig2G3XJBAPoXX3gFzLWcHMerUofNx3GsiCVc00OA0sZ2vfXQZEEwlhlrOGQX+YomRbBHs1HwDmMnvhM5GH1xJBZDckkRflQZFwBnlZ5pZ/rAhPO38QkdLDPDc28GSM=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at;\n s=mailrelay; t=1777663295;\n bh=dl4PTFzOE6UPvmsqEmfd/lyNFBNHbf8mm1OiroLDCNw=;\n h=Subject:From:To:Cc:Date;\n b=EUEkWaU8hsj9U0ko98B7eVqSqGYQdxp7UBQU7Ml0s0sUcc8aNN5mV+kPu/E6qA33e\n PxAhutIURPhEq5aBQ03DVopO9u0pvh7whx2uo0c179mA1e/s255GHWKA2QR0WA2sW+\n aEmqu8C1QQiEFH58MaT+MZv5Yw+hRNSq1k/ubDH0=","Message-ID":"<b9e8a06e2d1fb139f4d3e06159c1784e359074ab.camel@tugraz.at>","Subject":"[C PATCH] argument expressions may be evaluated too often by typeof\n [PR124576]","From":"Martin Uecker <uecker@tugraz.at>","To":"gcc-patches@gcc.gnu.org","Cc":"Joseph Myers <josmyers@redhat.com>","Date":"Fri, 01 May 2026 21:21:34 +0200","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","User-Agent":"Evolution 3.56.2-0+deb13u1 ","MIME-Version":"1.0","X-TUG-Backscatter-control":"G/VXY7/6zeyuAY/PU2/0qw","X-Scanned-By":"MIMEDefang 2.74 on 129.27.10.117","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":"Bootstrapped and regression tested on x86_64\n\n\n    c: argument expressions may be evaluated too often by typeof [PR124576]\n    \n    When there are multiple declarators in a declaration and the type\n    is specified via typeof, an expression inside the argument of\n    typeof may be evaluated multiple times.  Fix this by adding a\n    save expression.\n    \n            PR c/124576\n    \n    gcc/c/ChangeLog:\n            * c-decl.cc (declspecs_add_type): Add save_expr.\n    \n    gcc/testsuite/ChangeLog:\n            * pr124576.c: New test.","diff":"diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc\nindex 5e5193ed880..cc07e05e336 100644\n--- a/gcc/c/c-decl.cc\n+++ b/gcc/c/c-decl.cc\n@@ -13136,11 +13136,12 @@ declspecs_add_type (location_t loc, struct c_declspecs *specs,\n \t    }\n \t  if (spec.expr)\n \t    {\n+\t      tree expr = save_expr (fold_convert (void_type_node, spec.expr));\n \t      if (specs->expr)\n-\t\tspecs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (spec.expr),\n-\t\t\t\t      specs->expr, spec.expr);\n+\t\tspecs->expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),\n+\t\t\t\t      specs->expr, expr);\n \t      else\n-\t\tspecs->expr = spec.expr;\n+\t\tspecs->expr = expr;\n \t      specs->expr_const_operands &= spec.expr_const_operands;\n \t    }\n \t}\ndiff --git a/gcc/testsuite/gcc.dg/pr124576.c b/gcc/testsuite/gcc.dg/pr124576.c\nnew file mode 100644\nindex 00000000000..b66969d60fa\n--- /dev/null\n+++ b/gcc/testsuite/gcc.dg/pr124576.c\n@@ -0,0 +1,12 @@\n+/* { dg-do run } */\n+/* { dg-options \"-std=c99\" } */\n+\n+int main()\n+{\n+    int i = 0;\n+    int j = 0;\n+    __typeof__((__typeof__(int[i++])*)(j++, (void*)0)) a, b, c;\n+    if (1 != j)\n+\t    __builtin_abort();\n+}\n+\n","prefixes":["C"]}