DPDK patches and discussions
 help / color / mirror / Atom feed
From: Amit Prakash Shukla <amitprakashs@marvell.com>
To: Bruce Richardson <bruce.richardson@intel.com>
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>,
	Amit Prakash Shukla <amitprakashs@marvell.com>
Subject: [PATCH] build: enable static analyzer
Date: Thu, 14 Jul 2022 12:57:22 +0530	[thread overview]
Message-ID: <20220714072722.879156-1-amitprakashs@marvell.com> (raw)

This patch adds support to enable compiler static analyzer for
gcc and clang.

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
---
 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
+<https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html>`_
+
+`Clang static analyzer document
+<https://releases.llvm.org/9.0.1/tools/clang/docs/ClangStaticAnalyzer.html>`_
+
+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 <build_dir>
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


             reply	other threads:[~2022-07-14  7:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  7:27 Amit Prakash Shukla [this message]
2022-07-14 11:01 ` Bruce Richardson
2022-07-15 12:05   ` [EXT] " Amit Prakash Shukla
2023-07-06 22:59     ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220714072722.879156-1-amitprakashs@marvell.com \
    --to=amitprakashs@marvell.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=dmitrym@microsoft.com \
    --cc=jerinj@marvell.com \
    --cc=navasile@linux.microsoft.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).