DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] build: enable static analyzer
@ 2022-07-14  7:27 Amit Prakash Shukla
  2022-07-14 11:01 ` Bruce Richardson
  0 siblings, 1 reply; 4+ messages in thread
From: Amit Prakash Shukla @ 2022-07-14  7:27 UTC (permalink / raw)
  To: Bruce Richardson
  Cc: dev, jerinj, thomas, david.marchand, dmitry.kozliuk, navasile,
	dmitrym, Amit Prakash Shukla

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] build: enable static analyzer
  2022-07-14  7:27 [PATCH] build: enable static analyzer Amit Prakash Shukla
@ 2022-07-14 11:01 ` Bruce Richardson
  2022-07-15 12:05   ` [EXT] " Amit Prakash Shukla
  0 siblings, 1 reply; 4+ messages in thread
From: Bruce Richardson @ 2022-07-14 11:01 UTC (permalink / raw)
  To: Amit Prakash Shukla
  Cc: dev, jerinj, thomas, david.marchand, dmitry.kozliuk, navasile, dmitrym

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 <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')

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
> +<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+')
> -- 

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [EXT] Re: [PATCH] build: enable static analyzer
  2022-07-14 11:01 ` Bruce Richardson
@ 2022-07-15 12:05   ` Amit Prakash Shukla
  2023-07-06 22:59     ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Amit Prakash Shukla @ 2022-07-15 12:05 UTC (permalink / raw)
  To: Bruce Richardson
  Cc: dev, Jerin Jacob Kollanukkaran, thomas, david.marchand,
	dmitry.kozliuk, navasile, dmitrym

Thanks Bruce for the review. Please find my comments in-line.

> -----Original Message-----
> From: Bruce Richardson <bruce.richardson@intel.com>
> Sent: Thursday, July 14, 2022 4:31 PM
> To: Amit Prakash Shukla <amitprakashs@marvell.com>
> Cc: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> thomas@monjalon.net; david.marchand@redhat.com;
> dmitry.kozliuk@gmail.com; navasile@linux.microsoft.com;
> dmitrym@microsoft.com
> Subject: [EXT] Re: [PATCH] build: enable static analyzer
> 
> External Email
> 
> ----------------------------------------------------------------------
> 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 <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')
> 
> Rather than checking for specific compiler versions, we should instead just
> check for particular flags and use those.

Sure, I will make the change as part of v2 patch.

> 
> > +    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://urldefense.proofpoint.com/v2/url?u=https-
> 3A__gcc.gnu.org_onl
> > +inedocs_gcc-2D10.1.0_gcc_Static-2DAnalyzer-
> 2DOptions.html&d=DwIBAg&c=
> >
> +nKjWec2b6R0mOyPaz7xtfQ&r=ALGdXl3fZgFGR69VnJLdSnADun7zLaXG1p5R
> s7pXihE&
> > +m=41ZGerooHPN2LY2ibMFNcjUVJscn-
> MehdDhTHMaoqddHVciH516PLZOrDEhur1ra&s=
> > +v1pD8igta4HfoQgJlCAmOwZCo3PJ-b2_NXk0ODPEoms&e= >`_
> > +
> > +`Clang static analyzer document
> > +<https://urldefense.proofpoint.com/v2/url?u=https-3A__releases.llvm.o
> >
> +rg_9.0.1_tools_clang_docs_ClangStaticAnalyzer.html&d=DwIBAg&c=nKjWe
> c2
> >
> +b6R0mOyPaz7xtfQ&r=ALGdXl3fZgFGR69VnJLdSnADun7zLaXG1p5Rs7pXihE&
> m=41ZGe
> > +rooHPN2LY2ibMFNcjUVJscn-
> MehdDhTHMaoqddHVciH516PLZOrDEhur1ra&s=J2lNXZy
> > +id-zCxLgclayGzcTbrof1athBH6Rn_MAGPt4&e= >`_
> > +
> > +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+')
> > --
> 
> 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.

Sure, will remove it from dpdk in v2 patch and add it to meson.

> 
> Regards,
> /Bruce

Thanks,
Amit Shukla

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [EXT] Re: [PATCH] build: enable static analyzer
  2022-07-15 12:05   ` [EXT] " Amit Prakash Shukla
@ 2023-07-06 22:59     ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2023-07-06 22:59 UTC (permalink / raw)
  To: Amit Prakash Shukla
  Cc: Bruce Richardson, dev, Jerin Jacob Kollanukkaran, thomas,
	david.marchand, dmitry.kozliuk, navasile, dmitrym

On Fri, 15 Jul 2022 12:05:41 +0000
Amit Prakash Shukla <amitprakashs@marvell.com> wrote:

> Thanks Bruce for the review. Please find my comments in-line.
> 
> > -----Original Message-----
> > From: Bruce Richardson <bruce.richardson@intel.com>
> > Sent: Thursday, July 14, 2022 4:31 PM
> > To: Amit Prakash Shukla <amitprakashs@marvell.com>
> > Cc: dev@dpdk.org; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> > thomas@monjalon.net; david.marchand@redhat.com;
> > dmitry.kozliuk@gmail.com; navasile@linux.microsoft.com;
> > dmitrym@microsoft.com
> > Subject: [EXT] Re: [PATCH] build: enable static analyzer
> > 
> > External Email
> > 
> > ----------------------------------------------------------------------
> > 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 <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')  
> > 
> > Rather than checking for specific compiler versions, we should instead just
> > check for particular flags and use those.  
> 
> Sure, I will make the change as part of v2 patch.

Never saw a v2 of this patch??

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-06 22:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14  7:27 [PATCH] build: enable static analyzer Amit Prakash Shukla
2022-07-14 11:01 ` Bruce Richardson
2022-07-15 12:05   ` [EXT] " Amit Prakash Shukla
2023-07-06 22:59     ` Stephen Hemminger

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).