Support for functions wmempcpy, wmemmove, wmemcmp is added to the checker.
The same tests are copied that exist for the non-wide versions, with
non-wide functions and character types changed to the wide version.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Other than nits, I think it looks great.
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp | ||
---|---|---|
1368 | Personally, I dislike bools for this purpose. |
A related question:
Is it better to have a more generic function like this:
void CStringChecker::evalMemmove(CheckerContext &C, const CallExpr *CE, bool IsRestricted, bool IsMempcpy, bool IsWide) const { // void *memmove(void *dst, const void *src, size_t n); // The return value is the address of the destination buffer. DestinationArgExpr Dest = {CE->getArg(0), 0}; SourceArgExpr Src = {CE->getArg(1), 1}; SizeArgExpr Size = {CE->getArg(2), 2}; evalCopyCommon(C, CE, C.getState(), Size, Dest, Src, IsRestricted, IsMempcpy, IsWide); }
(Instead of bool enums can be used.) Or make additional versions of the eval functions and remove the IsWide argument (this is even more code repetition)?
I'd strive for the least code repetition. But I consider this just some nice to have sugar.
LGTM
clang/test/Analysis/wstring.c | ||
---|---|---|
372–376 | This comment is probably outdated (I know it has been copied from bstring.c but still). Perhaps we should have the else branch now not just here but also in bstring.c. |
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp | ||
---|---|---|
1343 | Do you think we should also update these comments? |
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp | ||
---|---|---|
1343 | These are only for "reference" purpose and already not exact declarations (no restricted). The wide version is similar, does not look not necessary to repeat here. | |
clang/test/Analysis/wstring.c | ||
372–376 | clang_analyzer_eval(n == 0) is TRUE and FALSE, not UNKNOWN here. n can be 0 or non-0 but it is connected to values of a and b too. |
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp | ||
---|---|---|
138–139 | Every other enum in the file is enum class, I like more to use enum class. But the name can be shortened and constants added because it is used often. |
I think there's only some very minor style nits which are remained, but that should not block this any further. Let's land it.
If you were using a plain-old enum, it would feel less repetitive.
You are already in the anonymous namespace, so it would not pollute anything anyway.
You could also use std::bind, to make it denser.