From patchwork Tue Mar 19 15:10:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schulze Frielinghaus X-Patchwork-Id: 1913622 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=m5W4uNaF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TzZtm0QLsz1yWn for ; Wed, 20 Mar 2024 02:11:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE58E3858429 for ; Tue, 19 Mar 2024 15:11:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 757F53858D37 for ; Tue, 19 Mar 2024 15:11:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 757F53858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 757F53858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710861069; cv=none; b=HCzqlXK3uEOq+X2xlvP0s+C27t1Ap4qmNgmyn7Fu1Y1Z3dqf9R2gTi/6lrPdU6XpiDSyjAPQJyuTZ4zrNWBqhNR5XjfIPdicVjow6tvzDW9uV9JT74uzu+5xnxkaeVCqWp6g/j8+/eLjPDSaGcjt6hUC78ffM94k1UTWQDjF5DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710861069; c=relaxed/simple; bh=Zq45p/ujREAyzUpFwfcOsGP9Q2UK6IIX9jpYMroUUt8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kICMZbhqyTti/EEGSc3eL5HKVdBTbva7OAL6G+q3x9YRsxCC2Cu2vvLlrL4JH+MzAUhjJ/TEInQ6c9Jh7onJFQwglNI1pLLfD+Bce8wJg2UljhRE2MWp+lA9mNe14d20Z1wiblEGDCtMXPk8jLvDhTwjJsRGIMinoN6kJ/IwgYw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42JDnqSs023739 for ; Tue, 19 Mar 2024 15:11:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=H97ry8/PdQ0PMUKDSgAr52XKl72O82qGGoNrUFrSkDA=; b=m5W4uNaFQY4rlOPYl9ZA18jPsc+IuWlU8LJxAvmbQHIQAOF1XrsMIrXNsdWZk3JFOGc6 33PeKemV/ETAODFbMdp6eE1xY92h3NOQPF6zvNpsCQWPBcUn8kINwFGy5dxzp6Tck/rd 0tpGULWnVDRFwNHWEoddtGJGwkRN7hHFVwMaaPYwnFPl9gvl9nSUI8FWcF0fPwpsNUTQ KL+UsWh7Cquq7yeXSGcE3XASEaOCOrwctumcbxeU6pi7cajuycVMTIgGtaXYH3J9W7hR CaxlaOiLEYChVVxOa3xSD+ejALFvWoq7t3LaK2XCNREkstczmy3t2ktiirh8sbT5aa7s Ug== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wybdhgqh6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 19 Mar 2024 15:11:03 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 42JFB37j030748 for ; Tue, 19 Mar 2024 15:11:03 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wybdhgqh3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Mar 2024 15:11:03 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 42JDsxOr011543; Tue, 19 Mar 2024 15:11:02 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3wwq8m06rr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Mar 2024 15:11:02 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 42JFAuZv13697402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2024 15:10:58 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A55A920040; Tue, 19 Mar 2024 15:10:56 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C34120063; Tue, 19 Mar 2024 15:10:56 +0000 (GMT) Received: from a8345010.lnxne.boe (unknown [9.152.108.100]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTPS; Tue, 19 Mar 2024 15:10:56 +0000 (GMT) From: Stefan Schulze Frielinghaus To: David Malcolm , gcc-patches@gcc.gnu.org Cc: Stefan Schulze Frielinghaus Subject: [PATCH] analyzer: Bail out on function pointer for -Wanalyzer-allocation-size Date: Tue, 19 Mar 2024 16:10:33 +0100 Message-ID: <20240319151032.732309-2-stefansf@linux.ibm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: z6YIwehzAIZJV8SX_6NFPqxh3i7lzQrb X-Proofpoint-ORIG-GUID: pziMeruyUl52t5WrbkLD2DUWmbmJgNCt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-19_04,2024-03-18_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 mlxscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 priorityscore=1501 spamscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403140000 definitions=main-2403190115 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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+incoming=patchwork.ozlabs.org@gcc.gnu.org On s390 pr94688.c is failing due to excess error pr94688.c:6:5: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size] This is because on s390 functions are by default aligned to an 8-byte boundary and during function type construction size is set to function boundary. Thus, for the assignment a.0_1 = (void (*) ()) &a; we have that the right-hand side is pointing to a 4-byte memory region whereas the size of the function pointer is 8 byte and a warning is emitted. I could follow and skip this test as done in PR112705, or we could bail out early in the analyzer for function pointers. My intuition so far is that -Wanalyzer-allocation-size shouldn't care about function pointer. Therefore, I went for bailing out early. If you believe this is wrong I can still go by skipping this test on s390. Any thoughts? --- gcc/analyzer/region-model.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index f079d1fb37e..1b43443d168 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -3514,6 +3514,10 @@ region_model::check_region_size (const region *lhs_reg, const svalue *rhs_sval, || TYPE_SIZE_UNIT (pointee_type) == NULL_TREE) return; + /* Bail out early on function pointers. */ + if (TREE_CODE (pointee_type) == FUNCTION_TYPE) + return; + /* Bail out early on pointers to structs where we can not deduce whether the buffer size is compatible. */ bool is_struct = RECORD_OR_UNION_TYPE_P (pointee_type);