SlideShare a Scribd company logo
Lloyd Moore, President
Lloyd@CyberData-Robotics.com
www.CyberData-Robotics.com
Free C++ Static
Analysis Tools
Introduction:
What is static analysis?
Both free / open source and proprietary tools exist.
Proprietary tools can be quite expensive, $25K/year/repo in one case.
This presentation will survey several free options and then deep dive setting up
and running one of them.
Free Static Analysis Tools
 Clang Static Analyzer
 CppCheck
 CppLint
 OCLint
 SonarQube Community Edition
Note: Other options exist, these appeared to be the most common.
Clang Static Analyzer
 Website:

https://clang-analyzer.llvm.org
 Type / Depth of Analysis:

Excellent
 Integration / Usability:

Excellent, integrated with various IDEs
 Customization / Extensibility:

Excellent

https://clang.llvm.org/docs/analyzer/user-docs/Options.html
 Performance:

Fast
 License:

Apache 2.0 (via LLVM)
 Notes:

Part of and integrated with the Clang and LLVM toolchain.
CppCheck
 Website:

Open Source: http://cppcheck.net, https://github.com/danmar/cppcheck

Premium / Proprietary : https://www.cppcheck.com
 Type / Depth of Analysis:

Excellent

https://sourceforge.net/p/cppcheck/wiki/ListOfChecks
 Integration / Usability:

Excellent, plugins for common IDEs

Supports non-standard syntax
 Customization / Extensibility:

Excellent

Supports Python based add on scripts
 Performance:

Fast
 License:

GPL-3.0
 Notes:

Has a premium version supporting MISRA and Cert coding standards.
CppLint
 Website:

https://github.com/cpplint/cpplint
 Type / Depth of Analysis:

Limited, appears to be style focused
 Integration / Usability:

CLI only
 Customization / Extensibility:

Limited
 Performance:

Likely slow, written in Python
 License:

Google

https://github.com/cpplint/cpplint/blob/develop/LICENSE
 Notes:

Doesn’t appear to have a web site beyond the GitHub repository.

Was originally developed by Google, no longer maintained
OCLint
 Website:

https://oclint.org/
 Type / Depth of Analysis:

Excellent (builds on Clang Static Analyzer)
 Integration / Usability:

Medium

CLI only

Can integrate with Clang Static Analyzer
 Customization / Extensibility:

Excellent

Can load rules from a directory at run time
 Performance:

Slow (reported)
 License:

Modified BSD 3

https://github.com/oclint/oclint/blob/master/LICENSE
 Notes:

Last release: October 26, 2021

Works via an AST

Linux and MacOS X only
SonarQube Community Edition
 Website:

https://www.sonarsource.com/open-source-editions/sonarqube-community-ed
ition
 Type / Depth of Analysis:

Limited

50K lines of code per project
 Integration / Usability:

Excellent
 Customization / Extensibility:

Limited
 Performance:

Fast (reported)

Is a cloud based solution
 License:

Proprietary
 Notes:

Appears to be a “gateway” to the full/proprietary version ($500/yr)
Summary
Tool Analysis Integ. License MISRA Extens. Support Perf
Clang Excellent Excellent Apache 2 No Excellent Excellent Fast
CppCheck Excellent Excellent GPL-3.0 Via Addon Excellent Excellent Fast
CppLint Limited CLI Only Google No Limited Limited Slow
OCLint Excellent CLI Only BSD 3 No Excellent Limited Slow
Sonar C. Limited Excellent Proprietary No Limited Limited Fast
Summary
Tool Analysis Integ. License MISRA Extens. Support Perf
Clang Excellent Excellent Apache 2 No Excellent Excellent Fast
CppCheck Excellent Excellent GPL-3.0 Via Addon Excellent Excellent Fast
CppLint Limited CLI Only Google No Limited Limited Slow
OCLint Excellent CLI Only BSD 3 No Excellent Limited Slow
Sonar C. Limited Excellent Proprietary No Limited Limited Fast
Selection Criteria (for my project):

Analysis: Excellent

Integration: CLI good enough

License: Any open source

Performance: Fast

Other: At least allow CUDA code to be present
Summary
Tool Analysis Integ. License MISRA Extens. Support Perf
Clang Excellent Excellent Apache 2 No Excellent Excellent Fast
CppCheck Excellent Excellent GPL-3.0 Via Addon Excellent Excellent Fast
CppLint Limited CLI Only Google No Limited Limited Slow
OCLint Excellent CLI Only BSD 3 No Excellent Limited Slow
Sonar C. Limited Excellent Proprietary No Limited Limited Fast
Selection Criteria (for my project):

Analysis: Excellent

Integration: CLI good enough

License: Any open source

Performance: Fast

Other: At least allow CUDA code to be present
Installing CppCheck
Windows, Linux and Mac are supported, web site and documentation has all the
details.
Very easy on Debian based Linux:
sudo apt install cppcheck
Running CppCheck
For a test run we’ll use the SimpleCuda code base from my prior talk:
Simple C++ code base
Incorporates CUDA code which is something I’m interested in
Code that at least some of you have seen before
Running “cppcheck” without any parameters provides help, as does the manual!
Running CppCheck
To check a folder simply run “cppcheck <path>”.
Note: This will only check files ending with .cpp, the CUDA files don’t get checked!
Running CppCheck
A few more command line parameters and now everything is gets checked!
Note: Both the language and the standard needed to be specified.
Running CppCheck
Next, “--enable=all” to do more detailed checking:
Note this gives us a false positive: ‘pythagorean_kernel’ is actually used, it is the
CUDA kernel and is called indirectly by CUDA. There are configuration settings to
suppress errors.
Running CppCheck
Finally , “--inline-suppr” and a suppression statement to handle the false positive:
Note that suppression statements can also be specified in various file formats.
Running CppCheck
There is an option to use the Clang parser:
I didn’t actually try this as it would break my use case of being able to check CUDA
code. The parser in CppCheck is designed specifically for non-standard extensions.
I’ve used Clang Analyzer in the past, and it works very well!
General Recommendations

No single tool is going to cover everything, use multiple tools when you can

Many professional projects build with multiple compilers, and versions

Catch portability issues early

Different compilers will flag different warnings

Static analysis can be time consuming

Generally don’t run static analysis for debug builds

Generally DO have a dedicated build where deep analysis is done

“make check”

Integrate the “make check” into your CI build and block commits which don’t pass

Flag any “disable check” type statements

Most developers won’t overtly try to bypass the system, but I won’t say it hasn’t
happened!

Place configuration files used to control the analysis under version control

In regulated environments save the analysis logs generated for release builds
Questions?

More Related Content

ODP
CPAN Module Maintenance
PPTX
Kali Linux-Operating System Presentation.pptx
ODP
Things I Learned From Having Users
PPTX
Kubernetes - State of the Union (Q1-2016)
PDF
Guider: An Integrated Runtime Performance Analyzer on AGL
PDF
OpenShift Origin Community Day (Boston) Extending OpenShift Origin: Build You...
PDF
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
ODP
Kyua and Jenkins: Testing Framework for BSD
CPAN Module Maintenance
Kali Linux-Operating System Presentation.pptx
Things I Learned From Having Users
Kubernetes - State of the Union (Q1-2016)
Guider: An Integrated Runtime Performance Analyzer on AGL
OpenShift Origin Community Day (Boston) Extending OpenShift Origin: Build You...
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
Kyua and Jenkins: Testing Framework for BSD

Similar to Free / Open Source C++ Static Analysis Tools (20)

PDF
DEF CON 27 - workshop - ISAAC EVANS - discover exploit and eradicate entire v...
DOC
QTP 10 00 Guide
PDF
OpenCV Workshop
PDF
OpenSCAP Overview(security scanning for docker image and container)
PDF
Joomla Code Quality Control and Automation Testing
PDF
CDS Filtering Program - User Manual
PDF
The Popper Experimentation Protocol and CLI tool
PDF
LCE13: Test and Validation Summit: The future of testing at Linaro
PDF
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...
PPTX
Process control daemon
PPTX
RedisConf18 - Implementing a New Data Structure for Redis
ODP
Improving code quality using CI
PDF
Code quality par Simone Civetta
PPTX
Automation tools: making things go... (March 2019)
PPTX
Optimizing and Profiling Golang Rest Api
PDF
Monitorama 2015 Netflix Instance Analysis
PDF
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
PPTX
Webinar | Building Apps with the Cassandra Python Driver
KEY
Movable Type 5.2 Overview at MTDDC 2012
PPT
Fut Lsi
DEF CON 27 - workshop - ISAAC EVANS - discover exploit and eradicate entire v...
QTP 10 00 Guide
OpenCV Workshop
OpenSCAP Overview(security scanning for docker image and container)
Joomla Code Quality Control and Automation Testing
CDS Filtering Program - User Manual
The Popper Experimentation Protocol and CLI tool
LCE13: Test and Validation Summit: The future of testing at Linaro
LCE13: Test and Validation Mini-Summit: Review Current Linaro Engineering Pro...
Process control daemon
RedisConf18 - Implementing a New Data Structure for Redis
Improving code quality using CI
Code quality par Simone Civetta
Automation tools: making things go... (March 2019)
Optimizing and Profiling Golang Rest Api
Monitorama 2015 Netflix Instance Analysis
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Webinar | Building Apps with the Cassandra Python Driver
Movable Type 5.2 Overview at MTDDC 2012
Fut Lsi
Ad

More from LloydMoore (15)

PPTX
Chosing The Right Language for your project
PDF
Cuda Without a Phd - A practical guick start
PPTX
Less Magical Numbers - A coding standard proposal
PPTX
Debugging Intermittent Issues - A How To
PPTX
Successful Software Projects - What you need to consider
PPTX
A Slice Of Rust - A quick look at the Rust programming language
PPTX
What Have We Lost - A look at some historical techniques
PPTX
Raspberry pi robotics
PPTX
High Reliabilty Systems
PPTX
Real Time Debugging - What to do when a breakpoint just won't do
PPT
PSoC USB HID
PPT
Using PSoC Creator
PPT
Using the Cypress PSoC Processor
PPT
C for Microcontrollers
PPTX
Starting Raspberry Pi
Chosing The Right Language for your project
Cuda Without a Phd - A practical guick start
Less Magical Numbers - A coding standard proposal
Debugging Intermittent Issues - A How To
Successful Software Projects - What you need to consider
A Slice Of Rust - A quick look at the Rust programming language
What Have We Lost - A look at some historical techniques
Raspberry pi robotics
High Reliabilty Systems
Real Time Debugging - What to do when a breakpoint just won't do
PSoC USB HID
Using PSoC Creator
Using the Cypress PSoC Processor
C for Microcontrollers
Starting Raspberry Pi
Ad

Recently uploaded (20)

PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
medical staffing services at VALiNTRY
PDF
AI in Product Development-omnex systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
System and Network Administration Chapter 2
PPTX
L1 - Introduction to python Backend.pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Transform Your Business with a Software ERP System
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
wealthsignaloriginal-com-DS-text-... (1).pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Migrate SBCGlobal Email to Yahoo Easily
medical staffing services at VALiNTRY
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PTS Company Brochure 2025 (1).pdf.......
Which alternative to Crystal Reports is best for small or large businesses.pdf
System and Network Administration Chapter 2
L1 - Introduction to python Backend.pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
System and Network Administraation Chapter 3
Design an Analysis of Algorithms I-SECS-1021-03
Wondershare Filmora 15 Crack With Activation Key [2025
How to Choose the Right IT Partner for Your Business in Malaysia
Transform Your Business with a Software ERP System
top salesforce developer skills in 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Design an Analysis of Algorithms II-SECS-1021-03
Upgrade and Innovation Strategies for SAP ERP Customers

Free / Open Source C++ Static Analysis Tools

  • 2. Introduction: What is static analysis? Both free / open source and proprietary tools exist. Proprietary tools can be quite expensive, $25K/year/repo in one case. This presentation will survey several free options and then deep dive setting up and running one of them.
  • 3. Free Static Analysis Tools  Clang Static Analyzer  CppCheck  CppLint  OCLint  SonarQube Community Edition Note: Other options exist, these appeared to be the most common.
  • 4. Clang Static Analyzer  Website:  https://clang-analyzer.llvm.org  Type / Depth of Analysis:  Excellent  Integration / Usability:  Excellent, integrated with various IDEs  Customization / Extensibility:  Excellent  https://clang.llvm.org/docs/analyzer/user-docs/Options.html  Performance:  Fast  License:  Apache 2.0 (via LLVM)  Notes:  Part of and integrated with the Clang and LLVM toolchain.
  • 5. CppCheck  Website:  Open Source: http://cppcheck.net, https://github.com/danmar/cppcheck  Premium / Proprietary : https://www.cppcheck.com  Type / Depth of Analysis:  Excellent  https://sourceforge.net/p/cppcheck/wiki/ListOfChecks  Integration / Usability:  Excellent, plugins for common IDEs  Supports non-standard syntax  Customization / Extensibility:  Excellent  Supports Python based add on scripts  Performance:  Fast  License:  GPL-3.0  Notes:  Has a premium version supporting MISRA and Cert coding standards.
  • 6. CppLint  Website:  https://github.com/cpplint/cpplint  Type / Depth of Analysis:  Limited, appears to be style focused  Integration / Usability:  CLI only  Customization / Extensibility:  Limited  Performance:  Likely slow, written in Python  License:  Google  https://github.com/cpplint/cpplint/blob/develop/LICENSE  Notes:  Doesn’t appear to have a web site beyond the GitHub repository.  Was originally developed by Google, no longer maintained
  • 7. OCLint  Website:  https://oclint.org/  Type / Depth of Analysis:  Excellent (builds on Clang Static Analyzer)  Integration / Usability:  Medium  CLI only  Can integrate with Clang Static Analyzer  Customization / Extensibility:  Excellent  Can load rules from a directory at run time  Performance:  Slow (reported)  License:  Modified BSD 3  https://github.com/oclint/oclint/blob/master/LICENSE  Notes:  Last release: October 26, 2021  Works via an AST  Linux and MacOS X only
  • 8. SonarQube Community Edition  Website:  https://www.sonarsource.com/open-source-editions/sonarqube-community-ed ition  Type / Depth of Analysis:  Limited  50K lines of code per project  Integration / Usability:  Excellent  Customization / Extensibility:  Limited  Performance:  Fast (reported)  Is a cloud based solution  License:  Proprietary  Notes:  Appears to be a “gateway” to the full/proprietary version ($500/yr)
  • 9. Summary Tool Analysis Integ. License MISRA Extens. Support Perf Clang Excellent Excellent Apache 2 No Excellent Excellent Fast CppCheck Excellent Excellent GPL-3.0 Via Addon Excellent Excellent Fast CppLint Limited CLI Only Google No Limited Limited Slow OCLint Excellent CLI Only BSD 3 No Excellent Limited Slow Sonar C. Limited Excellent Proprietary No Limited Limited Fast
  • 10. Summary Tool Analysis Integ. License MISRA Extens. Support Perf Clang Excellent Excellent Apache 2 No Excellent Excellent Fast CppCheck Excellent Excellent GPL-3.0 Via Addon Excellent Excellent Fast CppLint Limited CLI Only Google No Limited Limited Slow OCLint Excellent CLI Only BSD 3 No Excellent Limited Slow Sonar C. Limited Excellent Proprietary No Limited Limited Fast Selection Criteria (for my project):  Analysis: Excellent  Integration: CLI good enough  License: Any open source  Performance: Fast  Other: At least allow CUDA code to be present
  • 11. Summary Tool Analysis Integ. License MISRA Extens. Support Perf Clang Excellent Excellent Apache 2 No Excellent Excellent Fast CppCheck Excellent Excellent GPL-3.0 Via Addon Excellent Excellent Fast CppLint Limited CLI Only Google No Limited Limited Slow OCLint Excellent CLI Only BSD 3 No Excellent Limited Slow Sonar C. Limited Excellent Proprietary No Limited Limited Fast Selection Criteria (for my project):  Analysis: Excellent  Integration: CLI good enough  License: Any open source  Performance: Fast  Other: At least allow CUDA code to be present
  • 12. Installing CppCheck Windows, Linux and Mac are supported, web site and documentation has all the details. Very easy on Debian based Linux: sudo apt install cppcheck
  • 13. Running CppCheck For a test run we’ll use the SimpleCuda code base from my prior talk: Simple C++ code base Incorporates CUDA code which is something I’m interested in Code that at least some of you have seen before Running “cppcheck” without any parameters provides help, as does the manual!
  • 14. Running CppCheck To check a folder simply run “cppcheck <path>”. Note: This will only check files ending with .cpp, the CUDA files don’t get checked!
  • 15. Running CppCheck A few more command line parameters and now everything is gets checked! Note: Both the language and the standard needed to be specified.
  • 16. Running CppCheck Next, “--enable=all” to do more detailed checking: Note this gives us a false positive: ‘pythagorean_kernel’ is actually used, it is the CUDA kernel and is called indirectly by CUDA. There are configuration settings to suppress errors.
  • 17. Running CppCheck Finally , “--inline-suppr” and a suppression statement to handle the false positive: Note that suppression statements can also be specified in various file formats.
  • 18. Running CppCheck There is an option to use the Clang parser: I didn’t actually try this as it would break my use case of being able to check CUDA code. The parser in CppCheck is designed specifically for non-standard extensions. I’ve used Clang Analyzer in the past, and it works very well!
  • 19. General Recommendations  No single tool is going to cover everything, use multiple tools when you can  Many professional projects build with multiple compilers, and versions  Catch portability issues early  Different compilers will flag different warnings  Static analysis can be time consuming  Generally don’t run static analysis for debug builds  Generally DO have a dedicated build where deep analysis is done  “make check”  Integrate the “make check” into your CI build and block commits which don’t pass  Flag any “disable check” type statements  Most developers won’t overtly try to bypass the system, but I won’t say it hasn’t happened!  Place configuration files used to control the analysis under version control  In regulated environments save the analysis logs generated for release builds