r317565 - [analyzer] pr34779: CStringChecker: Accept non-standard headers.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 7 02:51:15 PST 2017
Author: dergachev
Date: Tue Nov 7 02:51:15 2017
New Revision: 317565
URL: http://llvm.org/viewvc/llvm-project?rev=317565&view=rev
Log:
[analyzer] pr34779: CStringChecker: Accept non-standard headers.
Do not crash when trying to define and call a non-standard
strcpy(unsigned char *, unsigned char *) during analysis.
At the same time, do not try to actually evaluate the call.
Differential Revision: https://reviews.llvm.org/D39422
Added:
cfe/trunk/test/Analysis/string-with-signedness.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=317565&r1=317564&r2=317565&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Tue Nov 7 02:51:15 2017
@@ -289,8 +289,8 @@ ProgramStateRef CStringChecker::CheckLoc
if (!ER)
return state;
- assert(ER->getValueType() == C.getASTContext().CharTy &&
- "CheckLocation should only be called with char* ElementRegions");
+ if (ER->getValueType() != C.getASTContext().CharTy)
+ return state;
// Get the size of the array.
const SubRegion *superReg = cast<SubRegion>(ER->getSuperRegion());
@@ -874,6 +874,8 @@ bool CStringChecker::IsFirstBufInBound(C
if (!ER)
return true; // cf top comment.
+ // FIXME: Does this crash when a non-standard definition
+ // of a library function is encountered?
assert(ER->getValueType() == C.getASTContext().CharTy &&
"IsFirstBufInBound should only be called with char* ElementRegions");
Added: cfe/trunk/test/Analysis/string-with-signedness.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/string-with-signedness.c?rev=317565&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/string-with-signedness.c (added)
+++ cfe/trunk/test/Analysis/string-with-signedness.c Tue Nov 7 02:51:15 2017
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -Wno-incompatible-library-redeclaration -analyzer-checker=core,unix.cstring,alpha.unix.cstring -verify %s
+
+// expected-no-diagnostics
+
+void *strcpy(unsigned char *, unsigned char *);
+
+unsigned char a, b;
+void testUnsignedStrcpy() {
+ strcpy(&a, &b);
+}
More information about the cfe-commits
mailing list