From bf966f523755c9f72886e90a98c15eae8d248cd8 Mon Sep 17 00:00:00 2001 From: Adam Balogh Date: Fri, 13 Jul 2018 13:44:44 +0000 Subject: [Analyzer] alpha.unix.cstring.OutOfBounds checker enable/disable fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was not possible to disable alpha.unix.cstring.OutOfBounds checker's reports since unix.Malloc checker always implicitly enabled the filter. Moreover if the checker was disabled from command line (-analyzer-disable-checker ..) the out of bounds warnings were nevertheless emitted under different checker names such as unix.cstring.NullArg, or unix.Malloc. This patch fixes the case sot that Malloc checker only enables implicitly the underlying modeling of strcpy, memcpy etc. but not the warning messages that would have been emmitted by alpha.unix.cstring.OutOfBounds Patch by: Dániel Krupp Differential Revision: https://reviews.llvm.org/D48831 llvm-svn: 337000 --- clang/test/Analysis/cstring-plist.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 clang/test/Analysis/cstring-plist.c (limited to 'clang/test/Analysis/cstring-plist.c') diff --git a/clang/test/Analysis/cstring-plist.c b/clang/test/Analysis/cstring-plist.c new file mode 100644 index 00000000000..19d0e46fd36 --- /dev/null +++ b/clang/test/Analysis/cstring-plist.c @@ -0,0 +1,22 @@ +// RUN: rm -f %t +// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,unix.Malloc,unix.cstring.NullArg -analyzer-disable-checker=alpha.unix.cstring.OutOfBounds -analyzer-output=plist -analyzer-config path-diagnostics-alternate=false -o %t %s +// RUN: FileCheck -input-file %t %s + +typedef __typeof(sizeof(int)) size_t; +void *malloc(size_t); +void free(void *); +char *strncpy(char *restrict s1, const char *restrict s2, size_t n); + + + +void cstringchecker_bounds_nocrash() { + char *p = malloc(2); + strncpy(p, "AAA", sizeof("AAA")); // we don't expect warning as the checker is disabled + free(p); +} + +// CHECK: diagnostics +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: +// CHECK-NEXT: -- cgit v1.2.3