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 D7299A00C5; Thu, 14 Jul 2022 13:01:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 69E3142B73; Thu, 14 Jul 2022 13:01:31 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 6194B42B6D for ; Thu, 14 Jul 2022 13:01:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657796489; x=1689332489; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=nU7vxXv89XwBsYf1jzOPuvx2biED/9iHD74tSUKXa74=; b=HCljiIAd+qPl0eSj+I7Ag3aJbZlsLA+k+7giTn0OKqykGVVK0JAP24zv C6oLuxUTUBMucx/P21KnrTvy6Q4/1uqb1mWnIzTshNr/Sl/bXJ2e+Y1b+ MOROlXAd6E6vL+OCFd2mLwuriVxN9OKJBCrjrN103u5aETjA1euphQ1lM ORhS4Gsul+rEg4XxXArq65X36muos7mC5swOY62nJX+W9gSXipLEac/d5 wwRjuWXjLvrPrqR4RL2E3lfJJ4M6hMLo8bI3aqT/jOAHK8wi0/3Ga5wLZ S2K1BYX21vF97zd3NFmYP7tBQ+8g7VLywX83i/XpNndbyn789++7rZtMx w==; X-IronPort-AV: E=McAfee;i="6400,9594,10407"; a="371792762" X-IronPort-AV: E=Sophos;i="5.92,271,1650956400"; d="scan'208";a="371792762" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2022 04:01:16 -0700 X-IronPort-AV: E=Sophos;i="5.92,271,1650956400"; d="scan'208";a="663742169" Received: from bricha3-mobl.ger.corp.intel.com ([10.55.133.37]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 14 Jul 2022 04:01:15 -0700 Date: Thu, 14 Jul 2022 12:01:12 +0100 From: Bruce Richardson To: Amit Prakash Shukla Cc: dev@dpdk.org, jerinj@marvell.com, thomas@monjalon.net, david.marchand@redhat.com, dmitry.kozliuk@gmail.com, navasile@linux.microsoft.com, dmitrym@microsoft.com Subject: Re: [PATCH] build: enable static analyzer Message-ID: References: <20220714072722.879156-1-amitprakashs@marvell.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220714072722.879156-1-amitprakashs@marvell.com> 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 On Thu, Jul 14, 2022 at 12:57:22PM +0530, Amit Prakash Shukla wrote: > 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') Rather than checking for specific compiler versions, we should instead just check for particular flags and use those. > + 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+') > -- Rather than adding support for this through DPDK project itself, this might be better added to meson directly so that other projects can also benefit from it. It also would fit in well with other meson options such as the ASAN support, coverage support, or PGO support. Regards, /Bruce