{"id":2225868,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2225868/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/aeeztiQrDfqssPGq@tucnak/","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":"<aeeztiQrDfqssPGq@tucnak>","date":"2026-04-21T17:28:22","name":"c-family: Fix ICE with counted_by attribute [PR124969]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"78b6eee6042b57daf57cd8979bb3103113e354f4","submitter":{"id":671,"url":"http://patchwork.ozlabs.org/api/1.1/people/671/?format=json","name":"Jakub Jelinek","email":"jakub@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/aeeztiQrDfqssPGq@tucnak/mbox/","series":[{"id":500859,"url":"http://patchwork.ozlabs.org/api/1.1/series/500859/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500859","date":"2026-04-21T17:28:22","name":"c-family: Fix ICE with counted_by attribute [PR124969]","version":1,"mbox":"http://patchwork.ozlabs.org/series/500859/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225868/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225868/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=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=N97RWOGv;\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=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=N97RWOGv","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"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 4g0TqJ4PKdz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 03:28:59 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 2A0BA4BA2E3F\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 17:28:57 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 197184BA2E3C\n for <gcc-patches@gcc.gnu.org>; Tue, 21 Apr 2026 17:28:29 +0000 (GMT)","from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-BqAP4cftN4CI-rYedB-jfg-1; Tue,\n 21 Apr 2026 13:28:27 -0400","from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 3660218004A9; Tue, 21 Apr 2026 17:28:26 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.48.12])\n by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 7A40E180047F; Tue, 21 Apr 2026 17:28:25 +0000 (UTC)","from tucnak.zalov.cz (localhost [127.0.0.1])\n by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 63LHSMZ2931422\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Tue, 21 Apr 2026 19:28:22 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 63LHSMRB931421;\n Tue, 21 Apr 2026 19:28:22 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 2A0BA4BA2E3F","OpenDKIM Filter v2.11.0 sourceware.org 197184BA2E3C"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 197184BA2E3C","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 197184BA2E3C","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776792509; cv=none;\n b=J76kM+RdLmcpfTOcidVv9zsCC00mKo7PUFzV2n9+dOSKbavTA32uqIwnJsZXuNcb2oERTcrFHPm87AS3MYxbiYCAPutatu7mY/GkqHuzL6NbWnFAbdGksJQ52uGdT3NOaozbtTX3oWB858coaAX5LYxbij+tkRDwz/J0suaS6Uo=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776792509; c=relaxed/simple;\n bh=bMFHWlJ/jerKgsap2ubY8pzgZOQ7uLrWqx/Karh7kX4=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=D8nuUdZ0W6SIoj4iBhLn62dETOOHB33P+um+l8KP4Lgg4TZW5ycwiywnaPPnNdiy6KCwizvXhURa5pp872+pesuzzYMWNgUgmL/Y57xZLLsWdMDruDyr9MNtIYfNdaKhA4+WHmFMf2M78zgAtknhOCvWjbbx5JXuRuJFhZwJK3w=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776792508;\n h=from:from:reply-to:reply-to:subject:subject:date:date:\n message-id:message-id:to:to:cc:cc:mime-version:mime-version:\n content-type:content-type; bh=gRBdCwrKlUVfV/h9DHXa/TQQWgKm8gHsfeQd41UA/d0=;\n b=N97RWOGv0dnRsAnRDl6Y0B/TLDF5Z0mlZKnOXntLz23YbuNJ1KCze7UoSL4+cOezIpogfA\n No2RdB4fTDYab69xwmrq8TZT0s3s85ZsX7NyyZtvsUGsjE/ex3pIqry5A/KhdgRffbxqCx\n L1w17lnf3AU4Zypf3Gn/Qm3RTKFRYYI=","X-MC-Unique":"BqAP4cftN4CI-rYedB-jfg-1","X-Mimecast-MFC-AGG-ID":"BqAP4cftN4CI-rYedB-jfg_1776792506","Date":"Tue, 21 Apr 2026 19:28:22 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"\"Joseph S. Myers\" <josmyers@redhat.com>,\n Marek Polacek <polacek@redhat.com>, Jason Merrill <jason@redhat.com>,\n Richard Biener <rguenther@suse.de>","Cc":"gcc-patches@gcc.gnu.org","Subject":"[PATCH] c-family: Fix ICE with counted_by attribute [PR124969]","Message-ID":"<aeeztiQrDfqssPGq@tucnak>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.93","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"TpzKDB6Q5dtc8w9uAZ7kQizlZsBopToH5FjQo6JwkR4_1776792506","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","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>","Reply-To":"Jakub Jelinek <jakub@redhat.com>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Hi!\n\nThe following valid testcase ICEs, because we try to use\nTREE_CODE (NULL_TREE).\nWe document that counted_by is supported on pointers to void\nand that it behaves like the GNU pointer to void arithmetics\nextension in that case.  build_access_with_size_for_counted_by\nalready uses 1 in that case as element_size.\n\nThe following patch fixes it, plus for error recovery punts\nif it is a pointer to incomplete type other than void (pointer\narithmetics on such type will be diagnosed as error later on).\n\nOk for trunk if it passes full bootstrap/regtest?\n\n2026-04-21  Jakub Jelinek  <jakub@redhat.com>\n\n\tPR sanitizer/124969\n\t* c-ubsan.cc (get_index_from_pointer_addr_expr): For\n\tVOID_TYPE_P (pointee_type) use size_one_node instead of\n\tTYPE_SIZE_UNIT (pointee_type) as pointee_size.  Punt if\n\tpointee_size is NULL_TREE.  Formatting fix.\n\n\t* gcc.dg/ubsan/pr124969-1.c: New test.\n\n\n\tJakub","diff":"--- gcc/c-family/c-ubsan.cc.jj\t2026-03-27 10:17:13.716337560 +0100\n+++ gcc/c-family/c-ubsan.cc\t2026-04-21 19:02:54.261275681 +0200\n@@ -741,7 +741,11 @@ get_index_from_pointer_addr_expr (tree p\n   /* Get the pointee type of the call to .ACCESS_WITH_SIZE.\n      This should be the element type of the pointer array.  */\n   tree pointee_type = TREE_TYPE (TREE_TYPE (call));\n-  tree pointee_size = TYPE_SIZE_UNIT (pointee_type);\n+  tree pointee_size;\n+  if (VOID_TYPE_P (pointee_type))\n+    pointee_size = size_one_node;\n+  else\n+    pointee_size = TYPE_SIZE_UNIT (pointee_type);\n \n   tree index_exp = TREE_OPERAND (pointer, 1);\n   *index_p = pointer;\n@@ -750,6 +754,8 @@ get_index_from_pointer_addr_expr (tree p\n   if (!(TREE_CODE (index_exp) != MULT_EXPR\n \t&& tree_int_cst_equal (pointee_size, integer_one_node)))\n     {\n+      if (pointee_size == NULL_TREE)\n+\treturn NULL_TREE;\n       while (CONVERT_EXPR_CODE_P (TREE_CODE (index_exp)))\n \t{\n \t  *index_p = index_exp;\n@@ -760,7 +766,7 @@ get_index_from_pointer_addr_expr (tree p\n \t\t\t\t\t index_n, pointee_size);\n \n       if (!index_exp)\n-      return NULL_TREE;\n+\treturn NULL_TREE;\n     }\n \n   while (CONVERT_EXPR_CODE_P (TREE_CODE (index_exp)))\n--- gcc/testsuite/gcc.dg/ubsan/pr124969-1.c.jj\t2026-04-21 19:18:43.197227776 +0200\n+++ gcc/testsuite/gcc.dg/ubsan/pr124969-1.c\t2026-04-21 19:19:23.288549722 +0200\n@@ -0,0 +1,14 @@\n+/* PR sanitizer/124969 */\n+/* { dg-do compile } */\n+/* { dg-options \"-fsanitize=undefined\" } */\n+\n+struct S {\n+  int c;\n+  void *b __attribute__ ((counted_by (c)));\n+} a;\n+\n+void *\n+foo (void)\n+{\n+  return a.b + 10;\n+}\n","prefixes":[]}