From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CFC84A00C5; Thu, 14 Jul 2022 09:27:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA6D542836; Thu, 14 Jul 2022 09:27:52 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id B8DEC41156 for ; Thu, 14 Jul 2022 09:27:51 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26E3eqLI019044; Thu, 14 Jul 2022 00:27:50 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=cNpbahS8H/xzHAdeZ9bBYI4Vi0qOfoJp7k7LwjyctAY=; b=LCnjkemzGva7PCYJdtz8d7eKSLj5R9NgdWNSPZg+MRSmMJbraIPnlM9wiSQ7xzrCXtb/ kEjIAuI6SIovmu/qUJ9pqkoxEU1sucImqWwGvgec95iVa8b5GmtJiNCSJ0bQnuI1Bxg3 uET89hsv6rpbqhzAt/vuC35veXGF60ZoY1tW24+8yLk52mUAjedFw/DT75XnJgF0R59y ECpfa627/UORozxnaEFn1sUDPYo3qKzJE2hu9SzUCxBT6drIJ3MJW0FfVXeyo61vRoqd jlcJvkJGsphbsgnWe2OJbU9tubJ9SwH8m+JIP5Y0ankuS/T+SzY+20kBYBWrJhVH9H0d jA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3habegrnnb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 14 Jul 2022 00:27:50 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 14 Jul 2022 00:27:49 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Thu, 14 Jul 2022 00:27:49 -0700 Received: from localhost.localdomain (unknown [10.28.48.63]) by maili.marvell.com (Postfix) with ESMTP id 45D713F704D; Thu, 14 Jul 2022 00:27:46 -0700 (PDT) From: Amit Prakash Shukla To: Bruce Richardson CC: , , , , , , , Amit Prakash Shukla Subject: [PATCH] build: enable static analyzer Date: Thu, 14 Jul 2022 12:57:22 +0530 Message-ID: <20220714072722.879156-1-amitprakashs@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: kK5eFbUKw189WmN9Os80YD_qhJEHXYRW X-Proofpoint-ORIG-GUID: kK5eFbUKw189WmN9Os80YD_qhJEHXYRW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-14_04,2022-07-13_03,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch adds support to enable compiler static analyzer for gcc and clang. Signed-off-by: Amit Prakash Shukla --- config/meson.build | 14 ++++++++++++++ doc/guides/prog_guide/index.rst | 1 + doc/guides/prog_guide/static_analyzer.rst | 21 +++++++++++++++++++++ meson_options.txt | 2 ++ 4 files changed, 38 insertions(+) create mode 100644 doc/guides/prog_guide/static_analyzer.rst diff --git a/config/meson.build b/config/meson.build index 7f7b6c92fd..1154396326 100644 --- a/config/meson.build +++ b/config/meson.build @@ -440,6 +440,20 @@ if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address endif endif +if get_option('static_analyzer') + if cc.get_id() == 'gcc' and cc.version().version_compare('>=10.1.0') + add_project_arguments('-fanalyzer', language: 'c') + elif cc.get_id() == 'clang' and cc.version().version_compare('>=9.0.1') + add_project_arguments('--analyze', language: 'c') + add_project_arguments('-Xanalyzer', language: 'c') + add_project_arguments('-analyzer-output=text', language: 'c') + elif cc.get_id() == 'gcc' or cc.get_id() == 'clang' + error('Static analysis not supported for current gcc/clang version.') + else + error('Compiler does not support static analysis') + endif +endif + if get_option('default_library') == 'both' error( ''' Unsupported value "both" for "default_library" option. diff --git a/doc/guides/prog_guide/index.rst b/doc/guides/prog_guide/index.rst index 8564883018..9f6d98904a 100644 --- a/doc/guides/prog_guide/index.rst +++ b/doc/guides/prog_guide/index.rst @@ -76,4 +76,5 @@ Programmer's Guide lto profile_app asan + static_analyzer glossary diff --git a/doc/guides/prog_guide/static_analyzer.rst b/doc/guides/prog_guide/static_analyzer.rst new file mode 100644 index 0000000000..11260eebe7 --- /dev/null +++ b/doc/guides/prog_guide/static_analyzer.rst @@ -0,0 +1,21 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright(c) 2022 Marvell + +Running Static Analyzer +======================== +Static analyzer is a compiler feature which when enabled scans through the source +code to try and find various problems at compile-time, rather than at runtime. + +Static analyzer is a part of clang (9.0.1+) and GCC (10.1.0+). + +`GCC Static analyzer document +`_ + +`Clang static analyzer document +`_ + +Enabling 'Static analyzer' is done by passing the -Dstatic_analyzer=true option to +the meson build system. By-default static analyzer is disabled. + +Example:: + - meson setup -Dstatic_analyzer=true diff --git a/meson_options.txt b/meson_options.txt index 7c220ad68d..fde9a579a0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -48,3 +48,5 @@ option('tests', type: 'boolean', value: true, description: 'build unit tests') option('use_hpet', type: 'boolean', value: false, description: 'use HPET timer in EAL') +option('static_analyzer', type: 'boolean', value: false, description: + 'Compile time static analyses for gcc-10.1.0+ and clang-9.0.1+') -- 2.25.1