clang-static-analyzer

Ignore system headers in clang-tidy

我的未来我决定 提交于 2019-12-06 16:59:03
问题 tldr;> How do I hide warnings from system headers in clang-tidy? I have the following minimal example source file, which triggers a clang-tidy warning in the system headers: #include <future> int main() { std::promise<int> p; p.set_value(3); } Calling it with libstdc++ 7.0.1 using clang-tidy 4.0.0 on Ubuntu 17.04: $ clang-tidy main.cpp -extra-arg=-std=c++14 yields Running without flags. 1 warning generated. /usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:693:5: warning

Failing compilation if return value is unused for a certain type

我怕爱的太早我们不能终老 提交于 2019-12-06 05:48:27
问题 I would like to make compilation fail for some function call but not others. The function call that I want to fail are those that do not handle return values when the value is of a certain type. In the example below, not handling a function returning Error is a compilation error but not handling a function that returns anything else should succeed just fine. Note: our runtime environment (embedded) does not allow us to use the following constructs: RTTI, exceptions. This code only needs to

How can I specify additional arguments for use with CMAKE_CXX_CLANG_TIDY variable

邮差的信 提交于 2019-12-06 04:47:13
问题 I'm trying to use make use of clang-tidy integration with cmake and I'd like to pass the -check argument. I've tried adding -DCMAKE_CXX_CLANG_TIDY="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" when invoking cmake, but my makefile commands end-up looking like: /usr/local/Cellar/cmake/3.6.2/bin/cmake -E __run_iwyu --tidy="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" --source=/Users/ellery/work/..... in other words, it seems like the ; separated args are not being parsed apart. I

silence a compiler warning about releasing a CGMutablePathRef object

对着背影说爱祢 提交于 2019-12-05 18:54:37
I have enabled the static analyzer, but it is telling me that at the end of that execution path that object didn't get released, hence possibly causing a memory leak. I am however passing that reference to the created object to another class which will release it. I was wondering if there is a method or keyword to tell the compiled that I will release this object later. I am looking for something like the auto-release. By the way, I am using ARC. I create the object like this: CGMutablePathRef pathRef = CGPathCreateMutable(); And pass it like this: self.flowView.pathToDraw = pathRef; In my

Why are static analysis tools missing this seemingly obvious case?

ⅰ亾dé卋堺 提交于 2019-12-05 14:28:17
I have a very simple C program with a potential buffer overflow using strcpy : #include <string.h> #include <stdio.h> void buffer_overflow(char* dst, const char* src) { strcpy(dst, src); } int main(int argc, char** argv) { if(argc == 2) { char buffer[16] = {0}; buffer_overflow(buffer, argv[1]); printf("[%d]: %s", (int)strlen(buffer), buffer); } return 0; } Neither clang static analyzer (using scan-build gcc -O0 -g3 -gdwarf-2 ) nor cppcheck (using cppcheck --enable=warning,style ) find this as an issue. Am I just asking too much from my static analysis tools? I can't speak for the quality of

Failing compilation if return value is unused for a certain type

☆樱花仙子☆ 提交于 2019-12-04 12:19:06
I would like to make compilation fail for some function call but not others. The function call that I want to fail are those that do not handle return values when the value is of a certain type. In the example below, not handling a function returning Error is a compilation error but not handling a function that returns anything else should succeed just fine. Note: our runtime environment (embedded) does not allow us to use the following constructs: RTTI, exceptions. This code only needs to compiler with Clang, I would prefer not having to annotate each function. We prefer a solution that fails

How can I specify additional arguments for use with CMAKE_CXX_CLANG_TIDY variable

↘锁芯ラ 提交于 2019-12-04 11:36:09
I'm trying to use make use of clang-tidy integration with cmake and I'd like to pass the -check argument. I've tried adding -DCMAKE_CXX_CLANG_TIDY="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" when invoking cmake, but my makefile commands end-up looking like: /usr/local/Cellar/cmake/3.6.2/bin/cmake -E __run_iwyu --tidy="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" --source=/Users/ellery/work/..... in other words, it seems like the ; separated args are not being parsed apart. I've also tried setting the target property CXX_CLANG_TIDY directly on my target with the same value and I

How can I enable clang-tidy's “modernize” checks?

假装没事ソ 提交于 2019-12-04 05:04:34
I just installed ClangOnWin ,and I'm trying to get clang-tidy 's "modernize" checks to work. Unfortunately, clang-tidy doesn't seem to know about them: clang-tidy -list-checks foo.cpp -- | grep modernize produces no output. The "modernize" checks are listed here , but that page seems to document Clang 3.8, and the version I have installed is 3.7. However, version 3.7 is the current one listed at the LLVM Download Page . clang-tidy knows about a variety of security checks, so I think I have it installed correctly. For example, clang-tidy -list-checks foo.cpp -- | grep security yields this:

Using an external Xcode Clang Static Analyzer binary, with additional checks

落爺英雄遲暮 提交于 2019-12-03 15:13:12
问题 I’m using Xcode 3.2.4 and have setup the Clang Static Analyser feature to use a newer build of the binary, as detailed here: http://clang-analyzer.llvm.org/xcode.html (Basically using the set-xcode-analyzer command line utility to change which copy of the Static Analyser that Xcode uses for Build and Analyze .) What I can’t figure is how to set that binary to use additional checks, such as -analyzer-check-objc-missing-dealloc when using the binary via Xcode, as detailed here: http://loufranco

How to make the Clang Static Analyzer output its working from command line?

拜拜、爱过 提交于 2019-12-03 05:51:32
问题 I'm running Clang 3.4 on Ubuntu 12.10 (from http://llvm.org/apt/). I ran the analyzer (clang --analyze) over some code, and it found a couple of issues: Blah.C:429:9: warning: Declared variable-length array (VLA) has zero size unsigned char separatedData[groupDataLength]; ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ But the specific issue isn't important. I want to know the steps of how it came to that conclusion (the code is complex enough for me not to see it within 15 mins). I see a