{"id":2225877,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2225877/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/aee0VThalXlyO9JV@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":"<aee0VThalXlyO9JV@tucnak>","date":"2026-04-21T17:31:01","name":"c: Fix counted_by attribute error recovery [PR124969]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"51f0e505419a20d8ae5d3fd06747abf017d8dd55","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/aee0VThalXlyO9JV@tucnak/mbox/","series":[{"id":500860,"url":"http://patchwork.ozlabs.org/api/1.1/series/500860/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500860","date":"2026-04-21T17:31:01","name":"c: Fix counted_by attribute error recovery [PR124969]","version":1,"mbox":"http://patchwork.ozlabs.org/series/500860/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225877/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225877/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=Wswwa1c+;\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 (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Wswwa1c+","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.133.124"],"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 4g0TtL5Hw1z1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 03:31:38 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id B650E4BA9021\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 17:31:36 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id 9FEE64BA2E3C\n for <gcc-patches@gcc.gnu.org>; Tue, 21 Apr 2026 17:31:09 +0000 (GMT)","from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-vNu2coRrNc2Jz197FRCHEQ-1; Tue,\n 21 Apr 2026 13:31:07 -0400","from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 8B08B1954B14; Tue, 21 Apr 2026 17:31:06 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.48.12])\n by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 2E9263000C25; Tue, 21 Apr 2026 17:31:03 +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 63LHV19T931454\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Tue, 21 Apr 2026 19:31:01 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 63LHV1w6931453;\n Tue, 21 Apr 2026 19:31:01 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org B650E4BA9021","OpenDKIM Filter v2.11.0 sourceware.org 9FEE64BA2E3C"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 9FEE64BA2E3C","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 9FEE64BA2E3C","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776792669; cv=none;\n b=EYQt29eMA6mD6bLbDwUFLxaKhw1VuKwhaNxU98gAPUPgTY3niQGQvubk2G9bpuIcIrpD2cSGzP28MMb8q1c9zORjrh+ySW+3dMzTBPo+N+sysn6X9nXQiwBH/0wRJvy9p8cjUwpRP+zFrQzMEuPAwrsI/WurWP3S8PUF+HP/xBg=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776792669; c=relaxed/simple;\n bh=bwzDJ7Fhhv+OcPGYyDsjXqnO60+K9dRQBymRze+TPYU=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=euGIBFDjNseWn6/NJJJCJqBX06CDrMc64+5aTqPN9b1JtARdj3UH9wuVFYtlAg6dejuf+5Atq+xiGnOCJmfH50KKMgF3JjbH5l7U3lAuAgcRxq7W0ZAg5HcfLyXqGl/FwbKQqibjC4AoUgE/gQEgiy0HgG1gWVPL0IV7JpfMD8w=","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=1776792669;\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=slAUUX6RUyxFJHh07OWFA+zZvY9Dk2XiOYHqtlmmaxI=;\n b=Wswwa1c+VRSjpNNSBr5uFhuEFbu4/CRdZgC+93xY2L599SYJYqnW2KKyRTpX2szcH5MZFd\n wpcNNedYCJgFd+ppd4k/XcdDoL/30k+VimyBmJQawFB+DT/jZ5guw9aV8s3UmmQSv9Zou7\n yr95i9FBlLuM1QmFpAZRSYs644J8qF4=","X-MC-Unique":"vNu2coRrNc2Jz197FRCHEQ-1","X-Mimecast-MFC-AGG-ID":"vNu2coRrNc2Jz197FRCHEQ_1776792666","Date":"Tue, 21 Apr 2026 19:31:01 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"\"Joseph S. Myers\" <josmyers@redhat.com>,\n Marek Polacek <polacek@redhat.com>, Richard Biener <rguenther@suse.de>","Cc":"gcc-patches@gcc.gnu.org","Subject":"[PATCH] c: Fix counted_by attribute error recovery [PR124969]","Message-ID":"<aee0VThalXlyO9JV@tucnak>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.4","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"_yAKd5RMGMZfvOJSYpMTHG29ZTrrWlPepVFTwwSvQbM_1776792666","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 last patch made me try also pointer arithmetics on incomplete\ntype.  And here we ICE before actually diagnosing the error\nbecause we try to dereference element_size.\n\nFurthermore, TYPE_SIZE_UNIT (element_type) is in sizetype, so\nwe shouldn't use build_one_cst (size_type_node) for the void *\ncase, but size_one_node (aka size_int (1)).\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-typeck.cc (build_access_with_size_for_counted_by): Use\n\tsize_one_node instead of build_one_cst (size_type_node).  Punt\n\tif element_size is NULL_TREE.\n\n\t* gcc.dg/ubsan/pr124969-2.c: New test.\n\n\n\tJakub","diff":"--- gcc/c/c-typeck.cc.jj\t2026-04-01 19:09:38.324343805 +0200\n+++ gcc/c/c-typeck.cc\t2026-04-21 19:16:20.325644120 +0200\n@@ -3270,8 +3270,10 @@ build_access_with_size_for_counted_by (l\n \n   tree element_type = TREE_TYPE (TREE_TYPE (ref));\n   tree element_size = VOID_TYPE_P (element_type)\n-\t\t      ? build_one_cst (size_type_node)\n+\t\t      ? size_one_node\n \t\t      : TYPE_SIZE_UNIT (element_type);\n+  if (element_size == NULL_TREE)\n+    return ref;\n \n   tree first_param = is_fam\n \t\t     ? c_fully_fold (array_to_pointer_conversion (loc, ref),\n--- gcc/testsuite/gcc.dg/ubsan/pr124969-2.c.jj\t2026-04-21 19:19:31.114417366 +0200\n+++ gcc/testsuite/gcc.dg/ubsan/pr124969-2.c\t2026-04-21 19:20:29.357432321 +0200\n@@ -0,0 +1,15 @@\n+/* PR sanitizer/124969 */\n+/* { dg-do compile } */\n+/* { dg-options \"-fsanitize=undefined\" } */\n+\n+struct T;\n+struct S {\n+  int c;\n+  struct T *b __attribute__ ((counted_by (c)));\n+} a;\n+\n+void *\n+foo ()\n+{\n+  return a.b + 10;\t/* { dg-error \"invalid use of undefined type 'struct T'\" } */\n+}\n","prefixes":[]}