diff mbox

[ovs-dev,v2] Makefile.am: Add clang static analysis support

Message ID 1467130153-74274-1-git-send-email-bhanuprakash.bodireddy@intel.com
State Changes Requested
Headers show

Commit Message

Bodireddy, Bhanuprakash June 28, 2016, 4:09 p.m. UTC
Clang Static Analyzer is a source code analysis tool to find bugs. This
patch adds make target to trigger static analysis using below commands.

./boot.sh
./configure --with-dpdk(in case of DPDK datapath)
make clang-analyze
scan-view --host=<ip address> --port <PORT>
  $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
  --allow-all-hosts

Results can be viewed on browser: http://<ip address>:<PORT>/

v1->v2:
* Change the output directory to tests/clang-analyzer-results
* Remove '-j' make option, This might potentially hang some system
  while spawning infinite jobs.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
---
 Makefile.am | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Lance Richardson June 28, 2016, 4:22 p.m. UTC | #1
> From: "Bhanuprakash Bodireddy" <bhanuprakash.bodireddy@intel.com>
> To: dev@openvswitch.org
> Cc: u9012063@gmail.com, lrichard@redhat.com, "Bhanuprakash Bodireddy" <bhanuprakash.bodireddy@intel.com>
> Sent: Tuesday, June 28, 2016 12:09:13 PM
> Subject: [PATCH v2] Makefile.am: Add clang static analysis support
> 
> Clang Static Analyzer is a source code analysis tool to find bugs. This
> patch adds make target to trigger static analysis using below commands.
> 
> ./boot.sh
> ./configure --with-dpdk(in case of DPDK datapath)
> make clang-analyze
> scan-view --host=<ip address> --port <PORT>
>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
>   --allow-all-hosts
> 
> Results can be viewed on browser: http://<ip address>:<PORT>/
> 
> v1->v2:
> * Change the output directory to tests/clang-analyzer-results
> * Remove '-j' make option, This might potentially hang some system
>   while spawning infinite jobs.
> 
> Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
> ---
>  Makefile.am | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/Makefile.am b/Makefile.am
> index 8cb8523..d0e6166 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -400,6 +400,16 @@ ovsext_clean: datapath-windows/ovsext.sln
>  endif
>  .PHONY: ovsext
>  
> +clang-analyze: clean
> +	@if which clang scan-build > /dev/null 2>&1; then \
> +	  $(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results" || exit 1; \
> +	  scan-build -o $(srcdir)/tests/clang-analyzer-results
> --use-analyzer=/usr/bin/clang \
> +		make || exit 1; \
> +	else \
> +	  echo -e "Unable to find clang/scan-build, Install clang,clang-analyzer
> packages"; \
> +	fi
> +.PHONY: clang-analyze
> +
>  dist-hook: $(DIST_HOOKS)
>  all-local: $(ALL_LOCAL)
>  clean-local: $(CLEAN_LOCAL)
> --
> 2.4.11
> 
> 
LGTM, thanks!

Acked-by: Lance Richardson <lrichard@redhat.com>
Ben Pfaff July 2, 2016, 5:14 p.m. UTC | #2
On Tue, Jun 28, 2016 at 05:09:13PM +0100, Bhanuprakash Bodireddy wrote:
> Clang Static Analyzer is a source code analysis tool to find bugs. This
> patch adds make target to trigger static analysis using below commands.
> 
> ./boot.sh
> ./configure --with-dpdk(in case of DPDK datapath)
> make clang-analyze
> scan-view --host=<ip address> --port <PORT>
>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
>   --allow-all-hosts
> 
> Results can be viewed on browser: http://<ip address>:<PORT>/
> 
> v1->v2:
> * Change the output directory to tests/clang-analyzer-results
> * Remove '-j' make option, This might potentially hang some system
>   while spawning infinite jobs.
> 
> Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>

I'd tend to write this a little differently, maybe like this:

clang-analyze: clean
	@which clang scan-build >/dev/null 2>&1 || \
	  (echo "Unable to find clang/scan-build, Install clang,clang-analyzer packages"; exit 1)
	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-analyzer=/usr/bin/clang $(MAKE)
.PHONY: clang-analyze

But it doesn't work for me anyway.  When I run it from a build tree
configured to use clang, I get the following:

    make  all-recursive
    make[2]: Entering directory '/home/blp/nicira/ovs/_clang'
    Making all in datapath
    make[3]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
    make[4]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
    make[4]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
    make[3]: Entering directory '/home/blp/nicira/ovs/_clang'
      CC       lib/aes128.lo
    gcc: error: unrecognized command line option '-Wthread-safety'
    gcc: error: unrecognized command line option '-Qunused-arguments'
    gcc: error: unrecognized command line option '-fno-caret-diagnostics'
    Makefile:4179: recipe for target 'lib/aes128.lo' failed
    make[3]: *** [lib/aes128.lo] Error 1
    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang'
    Makefile:4831: recipe for target 'all-recursive' failed
    make[2]: *** [all-recursive] Error 1
    make[2]: Leaving directory '/home/blp/nicira/ovs/_clang'
    Makefile:2749: recipe for target 'all' failed
    make[1]: *** [all] Error 2
    make[1]: Leaving directory '/home/blp/nicira/ovs/_clang'
    scan-build: Removing directory '/home/blp/nicira/ovs/tests/clang-analyzer-results/2016-07-02-101251-14653-1' because it contains no reports.
    scan-build: No bugs found.
    Makefile:5845: recipe for target 'clang-analyze' failed
    make: *** [clang-analyze] Error 1

Alternatively, if I run it from a build tree configured to use GCC, I
get the following:

    make  all-recursive
    make[2]: Entering directory '/home/blp/nicira/ovs/_build'
    Making all in datapath
    make[3]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
    make[4]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
    make[4]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
    make[3]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
    make[3]: Entering directory '/home/blp/nicira/ovs/_build'
      CC       lib/aes128.lo
      CC       lib/backtrace.lo
      CC       lib/bfd.lo
    In file included from ../lib/bfd.h:24:0,
                     from ../lib/bfd.c:16:
    ../lib/packets.h: In function 'eth_addr_invert':
    ../lib/packets.h:237:5: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    ../lib/packets.h:237:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
    In file included from ../lib/netdev.h:23:0,
                     from ../lib/dpif.h:391,
                     from ../lib/bfd.c:28:
    ../lib/flow.h: In function 'flowmap_is_empty':
    ../lib/flow.h:267:5: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    ../lib/flow.h:395:5: note: in expansion of macro 'FLOWMAP_FOR_EACH_MAP'
    ../lib/flow.h: In function 'flow_union_with_miniflow_subset':
    ../lib/flow.h:267:5: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    ../lib/flow.h:797:5: note: in expansion of macro 'FLOWMAP_FOR_EACH_MAP'
    In file included from ../lib/flow.h:24:0,
                     from ../lib/netdev.h:23,
                     from ../lib/dpif.h:391,
                     from ../lib/bfd.c:28:
    ../lib/bitmap.h:270:5: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    ../lib/flow.h:221:5: note: in expansion of macro 'ULLONG_FOR_EACH_1'
    ../lib/flow.h:800:9: note: in expansion of macro 'MAP_FOR_EACH_INDEX'
    Makefile:4179: recipe for target 'lib/bfd.lo' failed
    make[3]: *** [lib/bfd.lo] Error 1
    make[3]: Leaving directory '/home/blp/nicira/ovs/_build'
    Makefile:4831: recipe for target 'all-recursive' failed
    make[2]: *** [all-recursive] Error 1
    make[2]: Leaving directory '/home/blp/nicira/ovs/_build'
    Makefile:2749: recipe for target 'all' failed
    make[1]: *** [all] Error 2
    make[1]: Leaving directory '/home/blp/nicira/ovs/_build'
    scan-build: Removing directory '/home/blp/nicira/ovs/tests/clang-analyzer-results/2016-07-02-101322-15957-1' because it contains no reports.
    scan-build: No bugs found.
    Makefile:5845: recipe for target 'clang-analyze' failed
    make: *** [clang-analyze] Error 1

(In both cases I'm omitting the output from the "clean" part of the
operation.)

How is it supposed to work?

Thanks,

Ben.
Bodireddy, Bhanuprakash July 2, 2016, 8:14 p.m. UTC | #3
>-----Original Message-----
>From: Ben Pfaff [mailto:blp@ovn.org]
>Sent: Saturday, July 2, 2016 6:14 PM
>To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
>Cc: dev@openvswitch.org
>Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static analysis
>support
>
>On Tue, Jun 28, 2016 at 05:09:13PM +0100, Bhanuprakash Bodireddy wrote:
>> Clang Static Analyzer is a source code analysis tool to find bugs.
>> This patch adds make target to trigger static analysis using below commands.
>>
>> ./boot.sh
>> ./configure --with-dpdk(in case of DPDK datapath) make clang-analyze
>> scan-view --host=<ip address> --port <PORT>
>>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
>>   --allow-all-hosts
>>
>> Results can be viewed on browser: http://<ip address>:<PORT>/
>>
>> v1->v2:
>> * Change the output directory to tests/clang-analyzer-results
>> * Remove '-j' make option, This might potentially hang some system
>>   while spawning infinite jobs.
>>
>> Signed-off-by: Bhanuprakash Bodireddy
>> <bhanuprakash.bodireddy@intel.com>
>
>I'd tend to write this a little differently, maybe like this:
>
>clang-analyze: clean
>	@which clang scan-build >/dev/null 2>&1 || \
>	  (echo "Unable to find clang/scan-build, Install clang,clang-analyzer
>packages"; exit 1)
>	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
>	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-
>analyzer=/usr/bin/clang $(MAKE)
>.PHONY: clang-analyze

This is fine for me.

>
>But it doesn't work for me anyway.  When I run it from a build tree configured
>to use clang, I get the following:
>
>    make  all-recursive
>    make[2]: Entering directory '/home/blp/nicira/ovs/_clang'
>    Making all in datapath
>    make[3]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
>    make[4]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
>    make[4]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
>    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
>    make[3]: Entering directory '/home/blp/nicira/ovs/_clang'
>      CC       lib/aes128.lo
>    gcc: error: unrecognized command line option '-Wthread-safety'
>    gcc: error: unrecognized command line option '-Qunused-arguments'
>    gcc: error: unrecognized command line option '-fno-caret-diagnostics'
>    Makefile:4179: recipe for target 'lib/aes128.lo' failed
>    make[3]: *** [lib/aes128.lo] Error 1
>    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang'
>    Makefile:4831: recipe for target 'all-recursive' failed
>    make[2]: *** [all-recursive] Error 1
>    make[2]: Leaving directory '/home/blp/nicira/ovs/_clang'
>    Makefile:2749: recipe for target 'all' failed
>    make[1]: *** [all] Error 2
>    make[1]: Leaving directory '/home/blp/nicira/ovs/_clang'
>    scan-build: Removing directory '/home/blp/nicira/ovs/tests/clang-analyzer-
>results/2016-07-02-101251-14653-1' because it contains no reports.
>    scan-build: No bugs found.
>    Makefile:5845: recipe for target 'clang-analyze' failed
>    make: *** [clang-analyze] Error 1
>
>Alternatively, if I run it from a build tree configured to use GCC, I get the
>following:
>
>    make  all-recursive
>    make[2]: Entering directory '/home/blp/nicira/ovs/_build'
>    Making all in datapath
>    make[3]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
>    make[4]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
>    make[4]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
>    make[3]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
>    make[3]: Entering directory '/home/blp/nicira/ovs/_build'
>      CC       lib/aes128.lo
>      CC       lib/backtrace.lo
>      CC       lib/bfd.lo
>    In file included from ../lib/bfd.h:24:0,
>                     from ../lib/bfd.c:16:
>    ../lib/packets.h: In function 'eth_addr_invert':
>    ../lib/packets.h:237:5: error: 'for' loop initial declarations are only allowed in
>C99 or C11 mode
>    ../lib/packets.h:237:5: note: use option -std=c99, -std=gnu99, -std=c11 or -
>std=gnu11 to compile your code

I have tested this on F22 and didn't see this issue.  But when I tested it now on Ubuntu 14.04 LTS I could see the issue you reported here.
Adding CFLAGS="-std=gnu99" to make should fix this issue and I tested it now on Ubuntu 14.04

Can you try the below patch and see if you can generate clang analysis report properly this time?

+clang-analyze: clean
+       @which clang scan-build >/dev/null 2>&1 || \
+               (echo "Unable to find clang/scan-build, Install clang,clang-analyzer packages"; exit 1)
+       @$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
+       @scan-build -o $(srcdir)/tests/clang-analyzer-results --use-analyzer=/usr/bin/clang $(MAKE)  CFLAGS="-std=gnu99"
+.PHONY: clang-analyze

Regards,
Bhanu Prakash.
Ben Pfaff July 2, 2016, 8:31 p.m. UTC | #4
On Sat, Jul 02, 2016 at 08:14:02PM +0000, Bodireddy, Bhanuprakash wrote:
> >-----Original Message-----
> >From: Ben Pfaff [mailto:blp@ovn.org]
> >Sent: Saturday, July 2, 2016 6:14 PM
> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
> >Cc: dev@openvswitch.org
> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static analysis
> >support
> >
> >On Tue, Jun 28, 2016 at 05:09:13PM +0100, Bhanuprakash Bodireddy wrote:
> >> Clang Static Analyzer is a source code analysis tool to find bugs.
> >> This patch adds make target to trigger static analysis using below commands.
> >>
> >> ./boot.sh
> >> ./configure --with-dpdk(in case of DPDK datapath) make clang-analyze
> >> scan-view --host=<ip address> --port <PORT>
> >>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
> >>   --allow-all-hosts
> >>
> >> Results can be viewed on browser: http://<ip address>:<PORT>/
> >>
> >> v1->v2:
> >> * Change the output directory to tests/clang-analyzer-results
> >> * Remove '-j' make option, This might potentially hang some system
> >>   while spawning infinite jobs.
> >>
> >> Signed-off-by: Bhanuprakash Bodireddy
> >> <bhanuprakash.bodireddy@intel.com>
> >
> >I'd tend to write this a little differently, maybe like this:
> >
> >clang-analyze: clean
> >	@which clang scan-build >/dev/null 2>&1 || \
> >	  (echo "Unable to find clang/scan-build, Install clang,clang-analyzer
> >packages"; exit 1)
> >	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
> >	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-
> >analyzer=/usr/bin/clang $(MAKE)
> >.PHONY: clang-analyze
> 
> This is fine for me.
> 
> >
> >But it doesn't work for me anyway.  When I run it from a build tree configured
> >to use clang, I get the following:
> >
> >    make  all-recursive
> >    make[2]: Entering directory '/home/blp/nicira/ovs/_clang'
> >    Making all in datapath
> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
> >    make[4]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang'
> >      CC       lib/aes128.lo
> >    gcc: error: unrecognized command line option '-Wthread-safety'
> >    gcc: error: unrecognized command line option '-Qunused-arguments'
> >    gcc: error: unrecognized command line option '-fno-caret-diagnostics'
> >    Makefile:4179: recipe for target 'lib/aes128.lo' failed
> >    make[3]: *** [lib/aes128.lo] Error 1
> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >    Makefile:4831: recipe for target 'all-recursive' failed
> >    make[2]: *** [all-recursive] Error 1
> >    make[2]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >    Makefile:2749: recipe for target 'all' failed
> >    make[1]: *** [all] Error 2
> >    make[1]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >    scan-build: Removing directory '/home/blp/nicira/ovs/tests/clang-analyzer-
> >results/2016-07-02-101251-14653-1' because it contains no reports.
> >    scan-build: No bugs found.
> >    Makefile:5845: recipe for target 'clang-analyze' failed
> >    make: *** [clang-analyze] Error 1
> >
> >Alternatively, if I run it from a build tree configured to use GCC, I get the
> >following:
> >
> >    make  all-recursive
> >    make[2]: Entering directory '/home/blp/nicira/ovs/_build'
> >    Making all in datapath
> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
> >    make[4]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build'
> >      CC       lib/aes128.lo
> >      CC       lib/backtrace.lo
> >      CC       lib/bfd.lo
> >    In file included from ../lib/bfd.h:24:0,
> >                     from ../lib/bfd.c:16:
> >    ../lib/packets.h: In function 'eth_addr_invert':
> >    ../lib/packets.h:237:5: error: 'for' loop initial declarations are only allowed in
> >C99 or C11 mode
> >    ../lib/packets.h:237:5: note: use option -std=c99, -std=gnu99, -std=c11 or -
> >std=gnu11 to compile your code
> 
> I have tested this on F22 and didn't see this issue.  But when I tested it now on Ubuntu 14.04 LTS I could see the issue you reported here.
> Adding CFLAGS="-std=gnu99" to make should fix this issue and I tested it now on Ubuntu 14.04
> 
> Can you try the below patch and see if you can generate clang analysis report properly this time?

This change seems rather arbitrary.  Why doesn't the analysis phase use
the C compiler flags that have already been found to be correct for
compilation?
Bodireddy, Bhanuprakash July 2, 2016, 10:02 p.m. UTC | #5
>-----Original Message-----
>From: Ben Pfaff [mailto:blp@ovn.org]
>Sent: Saturday, July 2, 2016 9:31 PM
>To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
>Cc: dev@openvswitch.org
>Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static analysis
>support
>
>On Sat, Jul 02, 2016 at 08:14:02PM +0000, Bodireddy, Bhanuprakash wrote:
>> >-----Original Message-----
>> >From: Ben Pfaff [mailto:blp@ovn.org]
>> >Sent: Saturday, July 2, 2016 6:14 PM
>> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
>> >Cc: dev@openvswitch.org
>> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static
>> >analysis support
>> >
>> >On Tue, Jun 28, 2016 at 05:09:13PM +0100, Bhanuprakash Bodireddy wrote:
>> >> Clang Static Analyzer is a source code analysis tool to find bugs.
>> >> This patch adds make target to trigger static analysis using below
>commands.
>> >>
>> >> ./boot.sh
>> >> ./configure --with-dpdk(in case of DPDK datapath) make
>> >> clang-analyze scan-view --host=<ip address> --port <PORT>
>> >>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
>> >>   --allow-all-hosts
>> >>
>> >> Results can be viewed on browser: http://<ip address>:<PORT>/
>> >>
>> >> v1->v2:
>> >> * Change the output directory to tests/clang-analyzer-results
>> >> * Remove '-j' make option, This might potentially hang some system
>> >>   while spawning infinite jobs.
>> >>
>> >> Signed-off-by: Bhanuprakash Bodireddy
>> >> <bhanuprakash.bodireddy@intel.com>
>> >
>> >I'd tend to write this a little differently, maybe like this:
>> >
>> >clang-analyze: clean
>> >	@which clang scan-build >/dev/null 2>&1 || \
>> >	  (echo "Unable to find clang/scan-build, Install
>> >clang,clang-analyzer packages"; exit 1)
>> >	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
>> >	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-
>> >analyzer=/usr/bin/clang $(MAKE)
>> >.PHONY: clang-analyze
>>
>> This is fine for me.
>>
>> >
>> >But it doesn't work for me anyway.  When I run it from a build tree
>> >configured to use clang, I get the following:
>> >
>> >    make  all-recursive
>> >    make[2]: Entering directory '/home/blp/nicira/ovs/_clang'
>> >    Making all in datapath
>> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
>> >    make[4]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
>> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
>> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
>> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang'
>> >      CC       lib/aes128.lo
>> >    gcc: error: unrecognized command line option '-Wthread-safety'
>> >    gcc: error: unrecognized command line option '-Qunused-arguments'
>> >    gcc: error: unrecognized command line option '-fno-caret-diagnostics'
>> >    Makefile:4179: recipe for target 'lib/aes128.lo' failed
>> >    make[3]: *** [lib/aes128.lo] Error 1
>> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang'
>> >    Makefile:4831: recipe for target 'all-recursive' failed
>> >    make[2]: *** [all-recursive] Error 1
>> >    make[2]: Leaving directory '/home/blp/nicira/ovs/_clang'
>> >    Makefile:2749: recipe for target 'all' failed
>> >    make[1]: *** [all] Error 2
>> >    make[1]: Leaving directory '/home/blp/nicira/ovs/_clang'
>> >    scan-build: Removing directory
>> >'/home/blp/nicira/ovs/tests/clang-analyzer-
>> >results/2016-07-02-101251-14653-1' because it contains no reports.
>> >    scan-build: No bugs found.
>> >    Makefile:5845: recipe for target 'clang-analyze' failed
>> >    make: *** [clang-analyze] Error 1
>> >
>> >Alternatively, if I run it from a build tree configured to use GCC, I
>> >get the
>> >following:
>> >
>> >    make  all-recursive
>> >    make[2]: Entering directory '/home/blp/nicira/ovs/_build'
>> >    Making all in datapath
>> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
>> >    make[4]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
>> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
>> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
>> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build'
>> >      CC       lib/aes128.lo
>> >      CC       lib/backtrace.lo
>> >      CC       lib/bfd.lo
>> >    In file included from ../lib/bfd.h:24:0,
>> >                     from ../lib/bfd.c:16:
>> >    ../lib/packets.h: In function 'eth_addr_invert':
>> >    ../lib/packets.h:237:5: error: 'for' loop initial declarations
>> >are only allowed in
>> >C99 or C11 mode
>> >    ../lib/packets.h:237:5: note: use option -std=c99, -std=gnu99,
>> >-std=c11 or -
>> >std=gnu11 to compile your code
>>
>> I have tested this on F22 and didn't see this issue.  But when I tested it now
>on Ubuntu 14.04 LTS I could see the issue you reported here.
>> Adding CFLAGS="-std=gnu99" to make should fix this issue and I tested
>> it now on Ubuntu 14.04
>>
>> Can you try the below patch and see if you can generate clang analysis
>report properly this time?
>
>This change seems rather arbitrary.  Why doesn't the analysis phase use the C
>compiler flags that have already been found to be correct for compilation?

I tested the slightly tweaked patch updated below (added '--use-cc' flag) for both clang and gcc. 
I would let the user specify the CFLAGS at the configuration phase especially with gcc compiler on some distributions.
What do you think of this approach?

Clang:
./configure CC=clang --with-dpdk=$DPDK_BUILD
make clang-analyze

gcc:
./configure CC=gcc --with-dpdk=$DPDK_BUILD CFLAGS="-std=gnu99"
make clang-analyze

+clang-analyze: clean
+       @which clang scan-build >/dev/null 2>&1 || \
+               (echo "Unable to find clang/scan-build, Install clang,clang-analyzer packages"; exit 1)
+       @$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
+       @scan-build -o $(srcdir)/tests/clang-analyzer-results --use-cc=$(CC) --use-analyzer=/usr/bin/clang $(MAKE)
+.PHONY: clang-analyze
+
+

Regards,
Bhanuprakash.
Ben Pfaff July 3, 2016, 12:11 a.m. UTC | #6
On Sat, Jul 02, 2016 at 10:02:37PM +0000, Bodireddy, Bhanuprakash wrote:
> 
> >-----Original Message-----
> >From: Ben Pfaff [mailto:blp@ovn.org]
> >Sent: Saturday, July 2, 2016 9:31 PM
> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
> >Cc: dev@openvswitch.org
> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static analysis
> >support
> >
> >On Sat, Jul 02, 2016 at 08:14:02PM +0000, Bodireddy, Bhanuprakash wrote:
> >> >-----Original Message-----
> >> >From: Ben Pfaff [mailto:blp@ovn.org]
> >> >Sent: Saturday, July 2, 2016 6:14 PM
> >> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
> >> >Cc: dev@openvswitch.org
> >> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static
> >> >analysis support
> >> >
> >> >On Tue, Jun 28, 2016 at 05:09:13PM +0100, Bhanuprakash Bodireddy wrote:
> >> >> Clang Static Analyzer is a source code analysis tool to find bugs.
> >> >> This patch adds make target to trigger static analysis using below
> >commands.
> >> >>
> >> >> ./boot.sh
> >> >> ./configure --with-dpdk(in case of DPDK datapath) make
> >> >> clang-analyze scan-view --host=<ip address> --port <PORT>
> >> >>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
> >> >>   --allow-all-hosts
> >> >>
> >> >> Results can be viewed on browser: http://<ip address>:<PORT>/
> >> >>
> >> >> v1->v2:
> >> >> * Change the output directory to tests/clang-analyzer-results
> >> >> * Remove '-j' make option, This might potentially hang some system
> >> >>   while spawning infinite jobs.
> >> >>
> >> >> Signed-off-by: Bhanuprakash Bodireddy
> >> >> <bhanuprakash.bodireddy@intel.com>
> >> >
> >> >I'd tend to write this a little differently, maybe like this:
> >> >
> >> >clang-analyze: clean
> >> >	@which clang scan-build >/dev/null 2>&1 || \
> >> >	  (echo "Unable to find clang/scan-build, Install
> >> >clang,clang-analyzer packages"; exit 1)
> >> >	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
> >> >	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-
> >> >analyzer=/usr/bin/clang $(MAKE)
> >> >.PHONY: clang-analyze
> >>
> >> This is fine for me.
> >>
> >> >
> >> >But it doesn't work for me anyway.  When I run it from a build tree
> >> >configured to use clang, I get the following:
> >> >
> >> >    make  all-recursive
> >> >    make[2]: Entering directory '/home/blp/nicira/ovs/_clang'
> >> >    Making all in datapath
> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >    make[4]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang'
> >> >      CC       lib/aes128.lo
> >> >    gcc: error: unrecognized command line option '-Wthread-safety'
> >> >    gcc: error: unrecognized command line option '-Qunused-arguments'
> >> >    gcc: error: unrecognized command line option '-fno-caret-diagnostics'
> >> >    Makefile:4179: recipe for target 'lib/aes128.lo' failed
> >> >    make[3]: *** [lib/aes128.lo] Error 1
> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >> >    Makefile:4831: recipe for target 'all-recursive' failed
> >> >    make[2]: *** [all-recursive] Error 1
> >> >    make[2]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >> >    Makefile:2749: recipe for target 'all' failed
> >> >    make[1]: *** [all] Error 2
> >> >    make[1]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >> >    scan-build: Removing directory
> >> >'/home/blp/nicira/ovs/tests/clang-analyzer-
> >> >results/2016-07-02-101251-14653-1' because it contains no reports.
> >> >    scan-build: No bugs found.
> >> >    Makefile:5845: recipe for target 'clang-analyze' failed
> >> >    make: *** [clang-analyze] Error 1
> >> >
> >> >Alternatively, if I run it from a build tree configured to use GCC, I
> >> >get the
> >> >following:
> >> >
> >> >    make  all-recursive
> >> >    make[2]: Entering directory '/home/blp/nicira/ovs/_build'
> >> >    Making all in datapath
> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
> >> >    make[4]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
> >> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build'
> >> >      CC       lib/aes128.lo
> >> >      CC       lib/backtrace.lo
> >> >      CC       lib/bfd.lo
> >> >    In file included from ../lib/bfd.h:24:0,
> >> >                     from ../lib/bfd.c:16:
> >> >    ../lib/packets.h: In function 'eth_addr_invert':
> >> >    ../lib/packets.h:237:5: error: 'for' loop initial declarations
> >> >are only allowed in
> >> >C99 or C11 mode
> >> >    ../lib/packets.h:237:5: note: use option -std=c99, -std=gnu99,
> >> >-std=c11 or -
> >> >std=gnu11 to compile your code
> >>
> >> I have tested this on F22 and didn't see this issue.  But when I tested it now
> >on Ubuntu 14.04 LTS I could see the issue you reported here.
> >> Adding CFLAGS="-std=gnu99" to make should fix this issue and I tested
> >> it now on Ubuntu 14.04
> >>
> >> Can you try the below patch and see if you can generate clang analysis
> >report properly this time?
> >
> >This change seems rather arbitrary.  Why doesn't the analysis phase use the C
> >compiler flags that have already been found to be correct for compilation?
> 
> I tested the slightly tweaked patch updated below (added '--use-cc' flag) for both clang and gcc. 
> I would let the user specify the CFLAGS at the configuration phase especially with gcc compiler on some distributions.
> What do you think of this approach?
> 
> Clang:
> ./configure CC=clang --with-dpdk=$DPDK_BUILD
> make clang-analyze
> 
> gcc:
> ./configure CC=gcc --with-dpdk=$DPDK_BUILD CFLAGS="-std=gnu99"
> make clang-analyze
> 
> +clang-analyze: clean
> +       @which clang scan-build >/dev/null 2>&1 || \
> +               (echo "Unable to find clang/scan-build, Install clang,clang-analyzer packages"; exit 1)
> +       @$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
> +       @scan-build -o $(srcdir)/tests/clang-analyzer-results --use-cc=$(CC) --use-analyzer=/usr/bin/clang $(MAKE)
> +.PHONY: clang-analyze

The point I'm making is that the configure process already chooses a
correct set of CFLAGS and already allows the user to override them, so
why doesn't the clang-analyzer invocation use them?
Bodireddy, Bhanuprakash July 3, 2016, 11:32 a.m. UTC | #7
>-----Original Message-----
>From: Ben Pfaff [mailto:blp@ovn.org]
>Sent: Sunday, July 3, 2016 1:12 AM
>To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
>Cc: dev@openvswitch.org
>Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static analysis
>support
>
>On Sat, Jul 02, 2016 at 10:02:37PM +0000, Bodireddy, Bhanuprakash wrote:
>>
>> >-----Original Message-----
>> >From: Ben Pfaff [mailto:blp@ovn.org]
>> >Sent: Saturday, July 2, 2016 9:31 PM
>> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
>> >Cc: dev@openvswitch.org
>> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static
>> >analysis support
>> >
>> >On Sat, Jul 02, 2016 at 08:14:02PM +0000, Bodireddy, Bhanuprakash wrote:
>> >> >-----Original Message-----
>> >> >From: Ben Pfaff [mailto:blp@ovn.org]
>> >> >Sent: Saturday, July 2, 2016 6:14 PM
>> >> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
>> >> >Cc: dev@openvswitch.org
>> >> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static
>> >> >analysis support
>> >> >
>> >> >On Tue, Jun 28, 2016 at 05:09:13PM +0100, Bhanuprakash Bodireddy
>wrote:
>> >> >> Clang Static Analyzer is a source code analysis tool to find bugs.
>> >> >> This patch adds make target to trigger static analysis using
>> >> >> below
>> >commands.
>> >> >>
>> >> >> ./boot.sh
>> >> >> ./configure --with-dpdk(in case of DPDK datapath) make
>> >> >> clang-analyze scan-view --host=<ip address> --port <PORT>
>> >> >>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
>> >> >>   --allow-all-hosts
>> >> >>
>> >> >> Results can be viewed on browser: http://<ip address>:<PORT>/
>> >> >>
>> >> >> v1->v2:
>> >> >> * Change the output directory to tests/clang-analyzer-results
>> >> >> * Remove '-j' make option, This might potentially hang some system
>> >> >>   while spawning infinite jobs.
>> >> >>
>> >> >> Signed-off-by: Bhanuprakash Bodireddy
>> >> >> <bhanuprakash.bodireddy@intel.com>
>> >> >
>> >> >I'd tend to write this a little differently, maybe like this:
>> >> >
>> >> >clang-analyze: clean
>> >> >	@which clang scan-build >/dev/null 2>&1 || \
>> >> >	  (echo "Unable to find clang/scan-build, Install
>> >> >clang,clang-analyzer packages"; exit 1)
>> >> >	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
>> >> >	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-
>> >> >analyzer=/usr/bin/clang $(MAKE)
>> >> >.PHONY: clang-analyze
>> >>
>> >> This is fine for me.
>> >>
>> >> >
>> >> >But it doesn't work for me anyway.  When I run it from a build
>> >> >tree configured to use clang, I get the following:
>> >> >
>> >> >    make  all-recursive
>> >> >    make[2]: Entering directory '/home/blp/nicira/ovs/_clang'
>> >> >    Making all in datapath
>> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
>> >> >    make[4]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
>> >> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
>> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
>> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang'
>> >> >      CC       lib/aes128.lo
>> >> >    gcc: error: unrecognized command line option '-Wthread-safety'
>> >> >    gcc: error: unrecognized command line option '-Qunused-arguments'
>> >> >    gcc: error: unrecognized command line option '-fno-caret-diagnostics'
>> >> >    Makefile:4179: recipe for target 'lib/aes128.lo' failed
>> >> >    make[3]: *** [lib/aes128.lo] Error 1
>> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang'
>> >> >    Makefile:4831: recipe for target 'all-recursive' failed
>> >> >    make[2]: *** [all-recursive] Error 1
>> >> >    make[2]: Leaving directory '/home/blp/nicira/ovs/_clang'
>> >> >    Makefile:2749: recipe for target 'all' failed
>> >> >    make[1]: *** [all] Error 2
>> >> >    make[1]: Leaving directory '/home/blp/nicira/ovs/_clang'
>> >> >    scan-build: Removing directory
>> >> >'/home/blp/nicira/ovs/tests/clang-analyzer-
>> >> >results/2016-07-02-101251-14653-1' because it contains no reports.
>> >> >    scan-build: No bugs found.
>> >> >    Makefile:5845: recipe for target 'clang-analyze' failed
>> >> >    make: *** [clang-analyze] Error 1
>> >> >
>> >> >Alternatively, if I run it from a build tree configured to use
>> >> >GCC, I get the
>> >> >following:
>> >> >
>> >> >    make  all-recursive
>> >> >    make[2]: Entering directory '/home/blp/nicira/ovs/_build'
>> >> >    Making all in datapath
>> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
>> >> >    make[4]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
>> >> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
>> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
>> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build'
>> >> >      CC       lib/aes128.lo
>> >> >      CC       lib/backtrace.lo
>> >> >      CC       lib/bfd.lo
>> >> >    In file included from ../lib/bfd.h:24:0,
>> >> >                     from ../lib/bfd.c:16:
>> >> >    ../lib/packets.h: In function 'eth_addr_invert':
>> >> >    ../lib/packets.h:237:5: error: 'for' loop initial declarations
>> >> >are only allowed in
>> >> >C99 or C11 mode
>> >> >    ../lib/packets.h:237:5: note: use option -std=c99, -std=gnu99,
>> >> >-std=c11 or -
>> >> >std=gnu11 to compile your code
>> >>
>> >> I have tested this on F22 and didn't see this issue.  But when I
>> >> tested it now
>> >on Ubuntu 14.04 LTS I could see the issue you reported here.
>> >> Adding CFLAGS="-std=gnu99" to make should fix this issue and I
>> >> tested it now on Ubuntu 14.04
>> >>
>> >> Can you try the below patch and see if you can generate clang
>> >> analysis
>> >report properly this time?
>> >
>> >This change seems rather arbitrary.  Why doesn't the analysis phase
>> >use the C compiler flags that have already been found to be correct for
>compilation?
>>
>> I tested the slightly tweaked patch updated below (added '--use-cc' flag) for
>both clang and gcc.
>> I would let the user specify the CFLAGS at the configuration phase especially
>with gcc compiler on some distributions.
>> What do you think of this approach?
>>
>> Clang:
>> ./configure CC=clang --with-dpdk=$DPDK_BUILD make clang-analyze
>>
>> gcc:
>> ./configure CC=gcc --with-dpdk=$DPDK_BUILD CFLAGS="-std=gnu99"
>> make clang-analyze
>>
>> +clang-analyze: clean
>> +       @which clang scan-build >/dev/null 2>&1 || \
>> +               (echo "Unable to find clang/scan-build, Install clang,clang-analyzer
>packages"; exit 1)
>> +       @$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
>> +       @scan-build -o $(srcdir)/tests/clang-analyzer-results
>> +--use-cc=$(CC) --use-analyzer=/usr/bin/clang $(MAKE)
>> +.PHONY: clang-analyze
>
>The point I'm making is that the configure process already chooses a correct
>set of CFLAGS and already allows the user to override them,

Completely Agree Ben,  Using GCC 4.8.4 , the configure process in the default case
(i)  ./configure --with-dpdk=/root/dpdk-16.04/x86_64-native-linuxapp-gcc,  sets 'CFLAGS= -g -O2'  and  'CC' as below. 

       $ cat Makefile | grep "^CFLAGS ="
           CFLAGS = -g -O2

        $ cat Makefile | grep "^CC ="
            CC = $(if $(C),env REAL_CC="gcc -std=gnu99" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS) $(SPARSE_EXTRA_INCLUDES) "   cgcc $(CGCCFLAGS),gcc -std=gnu99)

        clang-analyze target in this case fails as below.
         $make clang-analyze
          (Omitted clean ouput here)
           scan-build: unrecognized option '-std=gnu99'
           make: *** [clang-analyze] Error 1

To get around this error, when CFLAGS is overridden from cmdline as
(ii) ./configure CC=gcc --with-dpdk=$DPDK_BUILD CFLAGS="-std=gnu99",  sets 'CFLAGS = -std=gnu99' and 'CC' as below.

       $ cat Makefile | grep "^CFLAGS ="
          CFLAGS = -std=gnu99

       $ cat Makefile | grep "^CC ="
           CC = $(if $(C),env REAL_CC="gcc" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS) $(SPARSE_EXTRA_INCLUDES) " cgcc  $(CGCCFLAGS),gcc)

       Clang-analyze target works perfectly in this case.

> so why doesn't
>the clang-analyzer invocation use them?

Clang-analyzer picks the CFLAGS automatically when invoked,  output snippet is pasted from case (ii).

'/bin/bash ./libtool  --tag=CC   --mode=compile /usr/share/clang/scan-build/ccc-analyzer -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -mssse3 -I/root/dpdk-16.04/x86_64-native-linuxapp-gcc/include -D_FILE_OFFSET_BITS=64  -std=gnu99 -MT lib/dpif.lo -MD -MP -MF $depbase.Tpo -c -o lib/dpif.lo lib/dpif.c'

I have also attached the configuration logs for case (i) and (ii).  This was tested using GCC version 4.8.4 on Ubuntu 14.04
In case (i),  config log shows:    checking for gcc option to accept ISO C99... -std=gnu99
In case (ii), config log shows :   checking for gcc option to accept ISO C99... none needed

This isn't observed when using GCC version 5.3.1 on F22.   Am I missing something?

Regards,
Bhanu Prakash.
Ben Pfaff July 3, 2016, 2:43 p.m. UTC | #8
On Sun, Jul 03, 2016 at 11:32:49AM +0000, Bodireddy, Bhanuprakash wrote:
> >-----Original Message-----
> >From: Ben Pfaff [mailto:blp@ovn.org]
> >Sent: Sunday, July 3, 2016 1:12 AM
> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
> >Cc: dev@openvswitch.org
> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static analysis
> >support
> >
> >On Sat, Jul 02, 2016 at 10:02:37PM +0000, Bodireddy, Bhanuprakash wrote:
> >>
> >> >-----Original Message-----
> >> >From: Ben Pfaff [mailto:blp@ovn.org]
> >> >Sent: Saturday, July 2, 2016 9:31 PM
> >> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
> >> >Cc: dev@openvswitch.org
> >> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static
> >> >analysis support
> >> >
> >> >On Sat, Jul 02, 2016 at 08:14:02PM +0000, Bodireddy, Bhanuprakash wrote:
> >> >> >-----Original Message-----
> >> >> >From: Ben Pfaff [mailto:blp@ovn.org]
> >> >> >Sent: Saturday, July 2, 2016 6:14 PM
> >> >> >To: Bodireddy, Bhanuprakash <bhanuprakash.bodireddy@intel.com>
> >> >> >Cc: dev@openvswitch.org
> >> >> >Subject: Re: [ovs-dev] [PATCH v2] Makefile.am: Add clang static
> >> >> >analysis support
> >> >> >
> >> >> >On Tue, Jun 28, 2016 at 05:09:13PM +0100, Bhanuprakash Bodireddy
> >wrote:
> >> >> >> Clang Static Analyzer is a source code analysis tool to find bugs.
> >> >> >> This patch adds make target to trigger static analysis using
> >> >> >> below
> >> >commands.
> >> >> >>
> >> >> >> ./boot.sh
> >> >> >> ./configure --with-dpdk(in case of DPDK datapath) make
> >> >> >> clang-analyze scan-view --host=<ip address> --port <PORT>
> >> >> >>   $OVS_DIR>/clang-analyzer-results/yyyy-mm-dd-114251-1027-1>
> >> >> >>   --allow-all-hosts
> >> >> >>
> >> >> >> Results can be viewed on browser: http://<ip address>:<PORT>/
> >> >> >>
> >> >> >> v1->v2:
> >> >> >> * Change the output directory to tests/clang-analyzer-results
> >> >> >> * Remove '-j' make option, This might potentially hang some system
> >> >> >>   while spawning infinite jobs.
> >> >> >>
> >> >> >> Signed-off-by: Bhanuprakash Bodireddy
> >> >> >> <bhanuprakash.bodireddy@intel.com>
> >> >> >
> >> >> >I'd tend to write this a little differently, maybe like this:
> >> >> >
> >> >> >clang-analyze: clean
> >> >> >	@which clang scan-build >/dev/null 2>&1 || \
> >> >> >	  (echo "Unable to find clang/scan-build, Install
> >> >> >clang,clang-analyzer packages"; exit 1)
> >> >> >	@$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
> >> >> >	@scan-build -o $(srcdir)/tests/clang-analyzer-results --use-
> >> >> >analyzer=/usr/bin/clang $(MAKE)
> >> >> >.PHONY: clang-analyze
> >> >>
> >> >> This is fine for me.
> >> >>
> >> >> >
> >> >> >But it doesn't work for me anyway.  When I run it from a build
> >> >> >tree configured to use clang, I get the following:
> >> >> >
> >> >> >    make  all-recursive
> >> >> >    make[2]: Entering directory '/home/blp/nicira/ovs/_clang'
> >> >> >    Making all in datapath
> >> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >> >    make[4]: Entering directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang/datapath'
> >> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_clang'
> >> >> >      CC       lib/aes128.lo
> >> >> >    gcc: error: unrecognized command line option '-Wthread-safety'
> >> >> >    gcc: error: unrecognized command line option '-Qunused-arguments'
> >> >> >    gcc: error: unrecognized command line option '-fno-caret-diagnostics'
> >> >> >    Makefile:4179: recipe for target 'lib/aes128.lo' failed
> >> >> >    make[3]: *** [lib/aes128.lo] Error 1
> >> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >> >> >    Makefile:4831: recipe for target 'all-recursive' failed
> >> >> >    make[2]: *** [all-recursive] Error 1
> >> >> >    make[2]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >> >> >    Makefile:2749: recipe for target 'all' failed
> >> >> >    make[1]: *** [all] Error 2
> >> >> >    make[1]: Leaving directory '/home/blp/nicira/ovs/_clang'
> >> >> >    scan-build: Removing directory
> >> >> >'/home/blp/nicira/ovs/tests/clang-analyzer-
> >> >> >results/2016-07-02-101251-14653-1' because it contains no reports.
> >> >> >    scan-build: No bugs found.
> >> >> >    Makefile:5845: recipe for target 'clang-analyze' failed
> >> >> >    make: *** [clang-analyze] Error 1
> >> >> >
> >> >> >Alternatively, if I run it from a build tree configured to use
> >> >> >GCC, I get the
> >> >> >following:
> >> >> >
> >> >> >    make  all-recursive
> >> >> >    make[2]: Entering directory '/home/blp/nicira/ovs/_build'
> >> >> >    Making all in datapath
> >> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
> >> >> >    make[4]: Entering directory '/home/blp/nicira/ovs/_build/datapath'
> >> >> >    make[4]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
> >> >> >    make[3]: Leaving directory '/home/blp/nicira/ovs/_build/datapath'
> >> >> >    make[3]: Entering directory '/home/blp/nicira/ovs/_build'
> >> >> >      CC       lib/aes128.lo
> >> >> >      CC       lib/backtrace.lo
> >> >> >      CC       lib/bfd.lo
> >> >> >    In file included from ../lib/bfd.h:24:0,
> >> >> >                     from ../lib/bfd.c:16:
> >> >> >    ../lib/packets.h: In function 'eth_addr_invert':
> >> >> >    ../lib/packets.h:237:5: error: 'for' loop initial declarations
> >> >> >are only allowed in
> >> >> >C99 or C11 mode
> >> >> >    ../lib/packets.h:237:5: note: use option -std=c99, -std=gnu99,
> >> >> >-std=c11 or -
> >> >> >std=gnu11 to compile your code
> >> >>
> >> >> I have tested this on F22 and didn't see this issue.  But when I
> >> >> tested it now
> >> >on Ubuntu 14.04 LTS I could see the issue you reported here.
> >> >> Adding CFLAGS="-std=gnu99" to make should fix this issue and I
> >> >> tested it now on Ubuntu 14.04
> >> >>
> >> >> Can you try the below patch and see if you can generate clang
> >> >> analysis
> >> >report properly this time?
> >> >
> >> >This change seems rather arbitrary.  Why doesn't the analysis phase
> >> >use the C compiler flags that have already been found to be correct for
> >compilation?
> >>
> >> I tested the slightly tweaked patch updated below (added '--use-cc' flag) for
> >both clang and gcc.
> >> I would let the user specify the CFLAGS at the configuration phase especially
> >with gcc compiler on some distributions.
> >> What do you think of this approach?
> >>
> >> Clang:
> >> ./configure CC=clang --with-dpdk=$DPDK_BUILD make clang-analyze
> >>
> >> gcc:
> >> ./configure CC=gcc --with-dpdk=$DPDK_BUILD CFLAGS="-std=gnu99"
> >> make clang-analyze
> >>
> >> +clang-analyze: clean
> >> +       @which clang scan-build >/dev/null 2>&1 || \
> >> +               (echo "Unable to find clang/scan-build, Install clang,clang-analyzer
> >packages"; exit 1)
> >> +       @$(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results"
> >> +       @scan-build -o $(srcdir)/tests/clang-analyzer-results
> >> +--use-cc=$(CC) --use-analyzer=/usr/bin/clang $(MAKE)
> >> +.PHONY: clang-analyze
> >
> >The point I'm making is that the configure process already chooses a correct
> >set of CFLAGS and already allows the user to override them,
> 
> Completely Agree Ben,  Using GCC 4.8.4 , the configure process in the default case
> (i)  ./configure --with-dpdk=/root/dpdk-16.04/x86_64-native-linuxapp-gcc,  sets 'CFLAGS= -g -O2'  and  'CC' as below. 
> 
>        $ cat Makefile | grep "^CFLAGS ="
>            CFLAGS = -g -O2
> 
>         $ cat Makefile | grep "^CC ="
>             CC = $(if $(C),env REAL_CC="gcc -std=gnu99" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS) $(SPARSE_EXTRA_INCLUDES) "   cgcc $(CGCCFLAGS),gcc -std=gnu99)
> 
>         clang-analyze target in this case fails as below.
>          $make clang-analyze
>           (Omitted clean ouput here)
>            scan-build: unrecognized option '-std=gnu99'
>            make: *** [clang-analyze] Error 1
> 
> To get around this error, when CFLAGS is overridden from cmdline as
> (ii) ./configure CC=gcc --with-dpdk=$DPDK_BUILD CFLAGS="-std=gnu99",  sets 'CFLAGS = -std=gnu99' and 'CC' as below.
> 
>        $ cat Makefile | grep "^CFLAGS ="
>           CFLAGS = -std=gnu99
> 
>        $ cat Makefile | grep "^CC ="
>            CC = $(if $(C),env REAL_CC="gcc" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS) $(SPARSE_EXTRA_INCLUDES) " cgcc  $(CGCCFLAGS),gcc)
> 
>        Clang-analyze target works perfectly in this case.
> 
> > so why doesn't
> >the clang-analyzer invocation use them?
> 
> Clang-analyzer picks the CFLAGS automatically when invoked,  output snippet is pasted from case (ii).
> 
> '/bin/bash ./libtool  --tag=CC   --mode=compile /usr/share/clang/scan-build/ccc-analyzer -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -mssse3 -I/root/dpdk-16.04/x86_64-native-linuxapp-gcc/include -D_FILE_OFFSET_BITS=64  -std=gnu99 -MT lib/dpif.lo -MD -MP -MF $depbase.Tpo -c -o lib/dpif.lo lib/dpif.c'
> 
> I have also attached the configuration logs for case (i) and (ii).  This was tested using GCC version 4.8.4 on Ubuntu 14.04
> In case (i),  config log shows:    checking for gcc option to accept ISO C99... -std=gnu99
> In case (ii), config log shows :   checking for gcc option to accept ISO C99... none needed
> 
> This isn't observed when using GCC version 5.3.1 on F22.   Am I missing something?

GCC 5.x defaults to gnu11 mode, so no option is necessary there.

I really don't understand the point you're making.  Post a new version,
if you have one, that works on common setups.
diff mbox

Patch

diff --git a/Makefile.am b/Makefile.am
index 8cb8523..d0e6166 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -400,6 +400,16 @@  ovsext_clean: datapath-windows/ovsext.sln
 endif
 .PHONY: ovsext
 
+clang-analyze: clean
+	@if which clang scan-build > /dev/null 2>&1; then \
+	  $(MKDIR_P) "$(srcdir)/tests/clang-analyzer-results" || exit 1; \
+	  scan-build -o $(srcdir)/tests/clang-analyzer-results --use-analyzer=/usr/bin/clang \
+		make || exit 1; \
+	else \
+	  echo -e "Unable to find clang/scan-build, Install clang,clang-analyzer packages"; \
+	fi
+.PHONY: clang-analyze
+
 dist-hook: $(DIST_HOOKS)
 all-local: $(ALL_LOCAL)
 clean-local: $(CLEAN_LOCAL)