[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
NoQ added a comment. In https://reviews.llvm.org/D53856#1285373, @rnkovacs wrote: > In https://reviews.llvm.org/D53856#1280408, @Szelethus wrote: > > > In https://reviews.llvm.org/D53856#1279887, @NoQ wrote: > > > > > This might be also covered by @rnkovacs's string buffer escape checker - > > > either already or eventually, it'll become just yet another string view > > > API that the checker supports. > > > > > > I thought about that too, adding some `StringRef` specific information to > > that checker makes more sense then essentially duplicating the logic. > > However, what @MTC mentioned about `ArrayRef` would be a neat addition > > too, and maybe it isn't worth making `InnerPointerChecker` //that// general. > > > > @rnkovacs, any thoughts? > > > I agree, adding `StringRef` support to the buffer escape checker around the > time we add `string_view` will be great. Also, we named it > `InnerPointerChecker` to allow for covering more general structures in the > future, so I guess `ArrayRef`s may also be added eventually. Unfortunately, I > have some other tasks to finish before getting to these, so I think this > patch is fine now as-is. I also agree that we should generally try harder to determine common logic behind checkers. Eg., `MallocChecker` and `StreamChecker` should be the same checker, or at least re-use a large chunk of common code that implements the overall idea of "one function produces a symbol, then another function consumes it, and the consuming function always needs to be called on that symbol, while the symbol should not be used in certain (almost all) manners after it is consumed". Repository: rC Clang https://reviews.llvm.org/D53856 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
This revision was automatically updated to reflect the committed changes. Closed by commit rC345990: [analyzer] Put llvm.Conventions back in alpha (authored by Szelethus, committed by ). Changed prior to commit: https://reviews.llvm.org/D53856?vs=172253=172380#toc Repository: rC Clang https://reviews.llvm.org/D53856 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp test/Analysis/Inputs/system-header-simulator-cxx.h test/Analysis/diagnostics/explicit-suppression.cpp test/Analysis/inner-pointer.cpp test/Analysis/llvm-conventions.cpp test/Analysis/temporaries.cpp www/analyzer/alpha_checks.html Index: include/clang/StaticAnalyzer/Checkers/Checkers.td === --- include/clang/StaticAnalyzer/Checkers/Checkers.td +++ include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -83,6 +83,7 @@ def MPI : Package<"mpi">, InPackage; def LLVM : Package<"llvm">; +def LLVMAlpha : Package<"llvm">, InPackage, Hidden; // The APIModeling package is for checkers that model APIs and don't perform // any diagnostics. These checkers are always turned on; this package is @@ -730,7 +731,7 @@ //===--===// def LLVMConventionsChecker : Checker<"Conventions">, - InPackage, + InPackage, HelpText<"Check code for LLVM codebase conventions">, DescFile<"LLVMConventionsChecker.cpp">; Index: test/Analysis/inner-pointer.cpp === --- test/Analysis/inner-pointer.cpp +++ test/Analysis/inner-pointer.cpp @@ -1,43 +1,9 @@ -//RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.InnerPointer %s -analyzer-output=text -verify +// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.InnerPointer \ +// RUN: %s -analyzer-output=text -verify +#include "Inputs/system-header-simulator-cxx.h" namespace std { -typedef int size_type; - -template -class basic_string { -public: - basic_string(); - basic_string(const CharT *s); - - ~basic_string(); - void clear(); - - basic_string =(const basic_string ); - basic_string +=(const basic_string ); - - const CharT *c_str() const; - const CharT *data() const; - CharT *data(); - - basic_string (size_type count, CharT ch); - basic_string (size_type count, CharT ch); - basic_string (size_type index, size_type count); - basic_string (size_type index, size_type count, CharT ch); - basic_string (size_type pos, size_type count, const basic_string ); - void pop_back(); - void push_back(CharT ch); - void reserve(size_type new_cap); - void resize(size_type count); - void shrink_to_fit(); - void swap(basic_string ); -}; - -typedef basic_string string; -typedef basic_string wstring; -typedef basic_string u16string; -typedef basic_string u32string; - template void func_ref(T ); Index: test/Analysis/llvm-conventions.cpp === --- test/Analysis/llvm-conventions.cpp +++ test/Analysis/llvm-conventions.cpp @@ -0,0 +1,226 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.llvm.Conventions \ +// RUN: -std=c++14 -verify %s + +#include "Inputs/system-header-simulator-cxx.h" + +//===--===// +// Forward declarations for StringRef tests. +//===--===// + +using size_t = unsigned long; +using size_type = size_t; + +namespace std { + +template +struct numeric_limits { const static bool is_signed; }; + +} // end of namespace std + +namespace llvm { + +template +struct iterator_range; + +template +struct function_ref; + +struct hash_code; + +template +struct SmallVectorImpl; + +struct APInt; + +class StringRef { +public: + static const size_t npos = ~size_t(0); + using iterator = const char *; + using const_iterator = const char *; + using size_type = size_t; + + /*implicit*/ StringRef() = default; + StringRef(std::nullptr_t) = delete; + /*implicit*/ StringRef(const char *Str); + /*implicit*/ constexpr StringRef(const char *data, size_t length); + /*implicit*/ StringRef(const std::string ); + + static StringRef withNullAsEmpty(const char *data); + iterator begin() const; + iterator end() const; + const unsigned char *bytes_begin() const; + const unsigned char *bytes_end() const; + iterator_range bytes() const; + const char *data() const; + bool empty() const; + size_t size() const; + char front() const; + char back() const; + template + StringRef copy(Allocator ) const; + bool equals(StringRef RHS) const; + bool equals_lower(StringRef RHS) const; + int compare(StringRef RHS) const; + int compare_lower(StringRef RHS) const; + int compare_numeric(StringRef RHS) const; + unsigned edit_distance(StringRef Other, bool AllowReplacements = true, + unsigned MaxEditDistance =
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
This revision was automatically updated to reflect the committed changes. Closed by commit rL345990: [analyzer] Put llvm.Conventions back in alpha (authored by Szelethus, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D53856?vs=172253=172379#toc Repository: rC Clang https://reviews.llvm.org/D53856 Files: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td cfe/trunk/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp cfe/trunk/test/Analysis/inner-pointer.cpp cfe/trunk/test/Analysis/llvm-conventions.cpp cfe/trunk/test/Analysis/temporaries.cpp cfe/trunk/www/analyzer/alpha_checks.html Index: cfe/trunk/www/analyzer/alpha_checks.html === --- cfe/trunk/www/analyzer/alpha_checks.html +++ cfe/trunk/www/analyzer/alpha_checks.html @@ -27,6 +27,7 @@ Clone Alpha Checkers Core Alpha Checkers C++ Alpha Checkers +LLVM Checkers Variable Argument Alpha Checkers Dead Code Alpha Checkers OS X Alpha Checkers @@ -583,6 +584,31 @@ + +LLVM Checkers + + +Name, DescriptionExample + + + +alpha.llvm.Conventions +(C) +Check code for LLVM codebase conventions: + + A StringRef should not be bound to a temporary std::string + whose lifetime is shorter than the StringRef's. + Clang AST nodes should not have fields that can allocate memory. + + + + + + + + + + OS X Alpha Checkers Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td === --- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -83,6 +83,7 @@ def MPI : Package<"mpi">, InPackage; def LLVM : Package<"llvm">; +def LLVMAlpha : Package<"llvm">, InPackage, Hidden; // The APIModeling package is for checkers that model APIs and don't perform // any diagnostics. These checkers are always turned on; this package is @@ -730,7 +731,7 @@ //===--===// def LLVMConventionsChecker : Checker<"Conventions">, - InPackage, + InPackage, HelpText<"Check code for LLVM codebase conventions">, DescFile<"LLVMConventionsChecker.cpp">; Index: cfe/trunk/test/Analysis/llvm-conventions.cpp === --- cfe/trunk/test/Analysis/llvm-conventions.cpp +++ cfe/trunk/test/Analysis/llvm-conventions.cpp @@ -0,0 +1,226 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.llvm.Conventions \ +// RUN: -std=c++14 -verify %s + +#include "Inputs/system-header-simulator-cxx.h" + +//===--===// +// Forward declarations for StringRef tests. +//===--===// + +using size_t = unsigned long; +using size_type = size_t; + +namespace std { + +template +struct numeric_limits { const static bool is_signed; }; + +} // end of namespace std + +namespace llvm { + +template +struct iterator_range; + +template +struct function_ref; + +struct hash_code; + +template +struct SmallVectorImpl; + +struct APInt; + +class StringRef { +public: + static const size_t npos = ~size_t(0); + using iterator = const char *; + using const_iterator = const char *; + using size_type = size_t; + + /*implicit*/ StringRef() = default; + StringRef(std::nullptr_t) = delete; + /*implicit*/ StringRef(const char *Str); + /*implicit*/ constexpr StringRef(const char *data, size_t length); + /*implicit*/ StringRef(const std::string ); + + static StringRef withNullAsEmpty(const char *data); + iterator begin() const; + iterator end() const; + const unsigned char *bytes_begin() const; + const unsigned char *bytes_end() const; + iterator_range bytes() const; + const char *data() const; + bool empty() const; + size_t size() const; + char front() const; + char back() const; + template + StringRef copy(Allocator ) const; + bool equals(StringRef RHS) const; + bool equals_lower(StringRef RHS) const; + int compare(StringRef RHS) const; + int compare_lower(StringRef RHS) const; + int compare_numeric(StringRef RHS) const; + unsigned edit_distance(StringRef Other, bool AllowReplacements = true, + unsigned MaxEditDistance = 0) const; + std::string str() const; + char operator[](size_t Index) const; + template + typename std::enable_if::value, + StringRef>::type & + operator=(T &) = delete; + operator std::string() const; + bool startswith(StringRef Prefix) const; + bool startswith_lower(StringRef Prefix) const; + bool endswith(StringRef Suffix) const; + bool endswith_lower(StringRef Suffix) const; + size_t find(char C, size_t From = 0) const; + size_t
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
rnkovacs added a comment. In https://reviews.llvm.org/D53856#1280408, @Szelethus wrote: > In https://reviews.llvm.org/D53856#1279887, @NoQ wrote: > > > This might be also covered by @rnkovacs's string buffer escape checker - > > either already or eventually, it'll become just yet another string view API > > that the checker supports. > > > I thought about that too, adding some `StringRef` specific information to > that checker makes more sense then essentially duplicating the logic. > However, what @MTC mentioned about `ArrayRef` would be a neat addition > too, and maybe it isn't worth making `InnerPointerChecker` //that// general. > > @rnkovacs, any thoughts? I agree, adding `StringRef` support to the buffer escape checker around the time we add `string_view` will be great. Also, we named it `InnerPointerChecker` to allow for covering more general structures in the future, so I guess `ArrayRef`s may also be added eventually. Unfortunately, I have some other tasks to finish before getting to these, so I think this patch is fine now as-is. https://reviews.llvm.org/D53856 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
Szelethus updated this revision to Diff 172253. Szelethus added a comment. - Moved `std::string` implementation from `InnerPointerChecker`'s testfile to the system header simulator header file. https://reviews.llvm.org/D53856 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp test/Analysis/Inputs/system-header-simulator-cxx.h test/Analysis/diagnostics/explicit-suppression.cpp test/Analysis/inner-pointer.cpp test/Analysis/llvm-conventions.cpp test/Analysis/temporaries.cpp www/analyzer/alpha_checks.html Index: www/analyzer/alpha_checks.html === --- www/analyzer/alpha_checks.html +++ www/analyzer/alpha_checks.html @@ -27,6 +27,7 @@ Clone Alpha Checkers Core Alpha Checkers C++ Alpha Checkers +LLVM Checkers Variable Argument Alpha Checkers Dead Code Alpha Checkers OS X Alpha Checkers @@ -554,6 +555,31 @@ + +LLVM Checkers + + +Name, DescriptionExample + + + +alpha.llvm.Conventions +(C) +Check code for LLVM codebase conventions: + + A StringRef should not be bound to a temporary std::string + whose lifetime is shorter than the StringRef's. + Clang AST nodes should not have fields that can allocate memory. + + + + + + + + + + OS X Alpha Checkers Index: test/Analysis/temporaries.cpp === --- test/Analysis/temporaries.cpp +++ test/Analysis/temporaries.cpp @@ -9,7 +9,7 @@ extern bool clang_analyzer_warnIfReached(); void clang_analyzer_checkInlined(bool); -#include "Inputs/system-header-simulator-cxx.h"; +#include "Inputs/system-header-simulator-cxx.h" struct Trivial { Trivial(int x) : value(x) {} Index: test/Analysis/llvm-conventions.cpp === --- /dev/null +++ test/Analysis/llvm-conventions.cpp @@ -0,0 +1,226 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.llvm.Conventions \ +// RUN: -std=c++14 -verify %s + +#include "Inputs/system-header-simulator-cxx.h" + +//===--===// +// Forward declarations for StringRef tests. +//===--===// + +using size_t = unsigned long; +using size_type = size_t; + +namespace std { + +template +struct numeric_limits { const static bool is_signed; }; + +} // end of namespace std + +namespace llvm { + +template +struct iterator_range; + +template +struct function_ref; + +struct hash_code; + +template +struct SmallVectorImpl; + +struct APInt; + +class StringRef { +public: + static const size_t npos = ~size_t(0); + using iterator = const char *; + using const_iterator = const char *; + using size_type = size_t; + + /*implicit*/ StringRef() = default; + StringRef(std::nullptr_t) = delete; + /*implicit*/ StringRef(const char *Str); + /*implicit*/ constexpr StringRef(const char *data, size_t length); + /*implicit*/ StringRef(const std::string ); + + static StringRef withNullAsEmpty(const char *data); + iterator begin() const; + iterator end() const; + const unsigned char *bytes_begin() const; + const unsigned char *bytes_end() const; + iterator_range bytes() const; + const char *data() const; + bool empty() const; + size_t size() const; + char front() const; + char back() const; + template + StringRef copy(Allocator ) const; + bool equals(StringRef RHS) const; + bool equals_lower(StringRef RHS) const; + int compare(StringRef RHS) const; + int compare_lower(StringRef RHS) const; + int compare_numeric(StringRef RHS) const; + unsigned edit_distance(StringRef Other, bool AllowReplacements = true, + unsigned MaxEditDistance = 0) const; + std::string str() const; + char operator[](size_t Index) const; + template + typename std::enable_if::value, + StringRef>::type & + operator=(T &) = delete; + operator std::string() const; + bool startswith(StringRef Prefix) const; + bool startswith_lower(StringRef Prefix) const; + bool endswith(StringRef Suffix) const; + bool endswith_lower(StringRef Suffix) const; + size_t find(char C, size_t From = 0) const; + size_t find_lower(char C, size_t From = 0) const; + size_t find_if(function_ref F, size_t From = 0) const; + size_t find_if_not(function_ref F, size_t From = 0) const; + size_t find(StringRef Str, size_t From = 0) const; + size_t find_lower(StringRef Str, size_t From = 0) const; + size_t rfind(char C, size_t From = npos) const; + size_t rfind_lower(char C, size_t From = npos) const; + size_t rfind(StringRef Str) const; + size_t rfind_lower(StringRef Str) const; + size_t find_first_of(char C, size_t From = 0) const; + size_t find_first_of(StringRef Chars, size_t From = 0) const; + size_t find_first_not_of(char C, size_t From = 0) const; + size_t find_first_not_of(StringRef Chars, size_t From = 0) const; +
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
Szelethus added a comment. In https://reviews.llvm.org/D53856#1279887, @NoQ wrote: > This might be also covered by @rnkovacs's string buffer escape checker - > either already or eventually, it'll become just yet another string view API > that the checker supports. I thought about that too, adding some `StringRef` specific information to that checker makes more sense then essentially duplicating the logic. However, what @MTC mentioned about `ArrayRef` would be a neat addition too, and maybe it isn't worth making `InnerPointerChecker` //that// general. @rnkovacs, any thoughts? https://reviews.llvm.org/D53856 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
MTC added a comment. In addition, `clang/lib/StaticAnalyzer/README.txt` and other related docs in `clang/lib/docs/analyzer` are also out of date. Comment at: www/analyzer/alpha_checks.html:570 + + A StringRef should not be bound to a temporary std::string + whose lifetime is shorter than the StringRef's. Like `StringRef`, `ArrayRef` may have similar issues. After this patch landed, maybe we can enhance this checker step by step. By that time, we may need the ideas of the heavy users of the LLVM library. https://reviews.llvm.org/D53856 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
NoQ accepted this revision. NoQ added a comment. This revision is now accepted and ready to land. I've actually never noticed this checker until you started updating the website :) This might be also covered by @rnkovacs's string buffer escape checker - either already or eventually, it'll become just yet another string view API that the checker supports. Comment at: test/Analysis/llvm-conventions.cpp:8 + +using size_t = unsigned long; +using size_type = size_t; I think we should try to re-use (and possibly extend) `test/Analysis/inputs/system-header-simulator-cxx.h`. https://reviews.llvm.org/D53856 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
Szelethus added inline comments. Comment at: lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp:193-195 static bool AllocatesMemory(QualType T) { return IsStdVector(T) || IsStdString(T) || IsSmallVector(T); } The `StringRef`part of this checker doesn't do a thing for me at all (even after a good amount of trying to make it work), but this part of the checker suffers a lot too. I'm sure we can some up with better ways for this function (and every single one in this file to be honest) now that almost a decade has passed. https://reviews.llvm.org/D53856 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
Szelethus updated this revision to Diff 171623. Szelethus added a comment. Added an entry to the website. https://reviews.llvm.org/D53856 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp test/Analysis/llvm-conventions.cpp www/analyzer/alpha_checks.html Index: www/analyzer/alpha_checks.html === --- www/analyzer/alpha_checks.html +++ www/analyzer/alpha_checks.html @@ -27,6 +27,7 @@ Clone Alpha Checkers Core Alpha Checkers C++ Alpha Checkers +LLVM Checkers Variable Argument Alpha Checkers Dead Code Alpha Checkers OS X Alpha Checkers @@ -554,6 +555,31 @@ + +LLVM Checkers + + +Name, DescriptionExample + + + +alpha.llvm.Conventions +(C) +Check code for LLVM codebase conventions: + + A StringRef should not be bound to a temporary std::string + whose lifetime is shorter than the StringRef's. + Clang AST nodes should not have fields that can allocate memory. + + + + + + + + + + OS X Alpha Checkers Index: test/Analysis/llvm-conventions.cpp === --- /dev/null +++ test/Analysis/llvm-conventions.cpp @@ -0,0 +1,271 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.llvm.Conventions \ +// RUN: -std=c++14 -verify %s + +//===--===// +// Forward declarations for StringRef tests. +//===--===// + +using size_t = unsigned long; +using size_type = size_t; + +namespace std { + +using nullptr_t = decltype(nullptr); + +template +struct pair { T1 first; T2 second; }; + +template +struct enable_if {}; + +template +struct enable_if { typedef T type; }; + +template +struct is_same { const static bool value; }; + +template +struct numeric_limits { const static bool is_signed; }; + +template +class basic_string { +public: + basic_string(); + basic_string(const CharT *s); + + ~basic_string(); + void clear(); + + basic_string =(const basic_string ); + basic_string +=(const basic_string ); + + const CharT *c_str() const; + const CharT *data() const; + CharT *data(); + + basic_string (size_type count, CharT ch); + basic_string (size_type count, CharT ch); + basic_string (size_type index, size_type count); + basic_string (size_type index, size_type count, CharT ch); + basic_string (size_type pos, size_type count, const basic_string ); + void pop_back(); + void push_back(CharT ch); + void reserve(size_type new_cap); + void resize(size_type count); + void shrink_to_fit(); + void swap(basic_string ); +}; + +typedef basic_string string; +typedef basic_string wstring; +typedef basic_string u16string; +typedef basic_string u32string; + +} // end of namespace std + +namespace llvm { + +template +struct iterator_range; + +template +struct function_ref; + +struct hash_code; + +template +struct SmallVectorImpl; + +struct APInt; + +class StringRef { +public: + static const size_t npos = ~size_t(0); + using iterator = const char *; + using const_iterator = const char *; + using size_type = size_t; + + /*implicit*/ StringRef() = default; + StringRef(std::nullptr_t) = delete; + /*implicit*/ StringRef(const char *Str); + /*implicit*/ constexpr StringRef(const char *data, size_t length); + /*implicit*/ StringRef(const std::string ); + + static StringRef withNullAsEmpty(const char *data); + iterator begin() const; + iterator end() const; + const unsigned char *bytes_begin() const; + const unsigned char *bytes_end() const; + iterator_range bytes() const; + const char *data() const; + bool empty() const; + size_t size() const; + char front() const; + char back() const; + template + StringRef copy(Allocator ) const; + bool equals(StringRef RHS) const; + bool equals_lower(StringRef RHS) const; + int compare(StringRef RHS) const; + int compare_lower(StringRef RHS) const; + int compare_numeric(StringRef RHS) const; + unsigned edit_distance(StringRef Other, bool AllowReplacements = true, + unsigned MaxEditDistance = 0) const; + std::string str() const; + char operator[](size_t Index) const; + template + typename std::enable_if::value, + StringRef>::type & + operator=(T &) = delete; + operator std::string() const; + bool startswith(StringRef Prefix) const; + bool startswith_lower(StringRef Prefix) const; + bool endswith(StringRef Suffix) const; + bool endswith_lower(StringRef Suffix) const; + size_t find(char C, size_t From = 0) const; + size_t find_lower(char C, size_t From = 0) const; + size_t find_if(function_ref F, size_t From = 0) const; + size_t find_if_not(function_ref F, size_t From = 0) const; + size_t find(StringRef Str, size_t From = 0) const; + size_t find_lower(StringRef Str, size_t From = 0) const; + size_t rfind(char C, size_t From = npos) const; + size_t
[PATCH] D53856: [analyzer] Put llvm.Conventions back in alpha
Szelethus created this revision. Szelethus added reviewers: george.karpenkov, NoQ, xazax.hun, MTC. Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, whisperity. Interestingly, this many year old (when I last looked I remember 2010ish) checker was committed without any tests, so I thought I'd implement them, but I was shocked to see how I barely managed to get it working. The code is severely outdated, I'm not even sure it has ever been used, so I'd propose to move it back into alpha, and possibly even remove it. Repository: rC Clang https://reviews.llvm.org/D53856 Files: include/clang/StaticAnalyzer/Checkers/Checkers.td lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp test/Analysis/llvm-conventions.cpp Index: test/Analysis/llvm-conventions.cpp === --- /dev/null +++ test/Analysis/llvm-conventions.cpp @@ -0,0 +1,271 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.llvm.Conventions \ +// RUN: -std=c++14 -verify %s + +//===--===// +// Forward declarations for StringRef tests. +//===--===// + +using size_t = unsigned long; +using size_type = size_t; + +namespace std { + +using nullptr_t = decltype(nullptr); + +template +struct pair { T1 first; T2 second; }; + +template +struct enable_if {}; + +template +struct enable_if { typedef T type; }; + +template +struct is_same { const static bool value; }; + +template +struct numeric_limits { const static bool is_signed; }; + +template +class basic_string { +public: + basic_string(); + basic_string(const CharT *s); + + ~basic_string(); + void clear(); + + basic_string =(const basic_string ); + basic_string +=(const basic_string ); + + const CharT *c_str() const; + const CharT *data() const; + CharT *data(); + + basic_string (size_type count, CharT ch); + basic_string (size_type count, CharT ch); + basic_string (size_type index, size_type count); + basic_string (size_type index, size_type count, CharT ch); + basic_string (size_type pos, size_type count, const basic_string ); + void pop_back(); + void push_back(CharT ch); + void reserve(size_type new_cap); + void resize(size_type count); + void shrink_to_fit(); + void swap(basic_string ); +}; + +typedef basic_string string; +typedef basic_string wstring; +typedef basic_string u16string; +typedef basic_string u32string; + +} // end of namespace std + +namespace llvm { + +template +struct iterator_range; + +template +struct function_ref; + +struct hash_code; + +template +struct SmallVectorImpl; + +struct APInt; + +class StringRef { +public: + static const size_t npos = ~size_t(0); + using iterator = const char *; + using const_iterator = const char *; + using size_type = size_t; + + /*implicit*/ StringRef() = default; + StringRef(std::nullptr_t) = delete; + /*implicit*/ StringRef(const char *Str); + /*implicit*/ constexpr StringRef(const char *data, size_t length); + /*implicit*/ StringRef(const std::string ); + + static StringRef withNullAsEmpty(const char *data); + iterator begin() const; + iterator end() const; + const unsigned char *bytes_begin() const; + const unsigned char *bytes_end() const; + iterator_range bytes() const; + const char *data() const; + bool empty() const; + size_t size() const; + char front() const; + char back() const; + template + StringRef copy(Allocator ) const; + bool equals(StringRef RHS) const; + bool equals_lower(StringRef RHS) const; + int compare(StringRef RHS) const; + int compare_lower(StringRef RHS) const; + int compare_numeric(StringRef RHS) const; + unsigned edit_distance(StringRef Other, bool AllowReplacements = true, + unsigned MaxEditDistance = 0) const; + std::string str() const; + char operator[](size_t Index) const; + template + typename std::enable_if::value, + StringRef>::type & + operator=(T &) = delete; + operator std::string() const; + bool startswith(StringRef Prefix) const; + bool startswith_lower(StringRef Prefix) const; + bool endswith(StringRef Suffix) const; + bool endswith_lower(StringRef Suffix) const; + size_t find(char C, size_t From = 0) const; + size_t find_lower(char C, size_t From = 0) const; + size_t find_if(function_ref F, size_t From = 0) const; + size_t find_if_not(function_ref F, size_t From = 0) const; + size_t find(StringRef Str, size_t From = 0) const; + size_t find_lower(StringRef Str, size_t From = 0) const; + size_t rfind(char C, size_t From = npos) const; + size_t rfind_lower(char C, size_t From = npos) const; + size_t rfind(StringRef Str) const; + size_t rfind_lower(StringRef Str) const; + size_t find_first_of(char C, size_t From = 0) const; + size_t find_first_of(StringRef Chars, size_t From = 0) const; + size_t