llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Benedek Kaibas (benedekaibas)

<details>
<summary>Changes</summary>

Some issues reported in the Clang Static Analyzer got fixed by bisected 
commits, but those commits did not include the motivating examples from the 
reported issues. This PR adds some of those test cases to existing test files. 

The issues that were not covered by test cases and now are by this PR are the 
following: https://github.com/llvm/llvm-project/issues/56264, 
https://github.com/llvm/llvm-project/issues/47932, 
https://github.com/llvm/llvm-project/issues/39448, 
https://github.com/llvm/llvm-project/issues/60694, 
https://github.com/llvm/llvm-project/issues/26595, 
https://github.com/llvm/llvm-project/issues/59870, 
https://github.com/llvm/llvm-project/issues/64647, 
https://github.com/llvm/llvm-project/issues/43015, 
https://github.com/llvm/llvm-project/issues/3206, 
https://github.com/llvm/llvm-project/issues/40797, 
https://github.com/llvm/llvm-project/issues/49330, 
https://github.com/llvm/llvm-project/issues/20099, 
https://github.com/llvm/llvm-project/issues/19340

*AI Policy*: These bisection commits were found by AI. I have revisited each 
issue and verified that the mentioned commits actually fix the issue. I have 
not used AI for editing the existing test cases. To make sure the test cases 
this PR adds are not present in the test suite I have asked an LLM to scan the 
test suite of the Clang Static Analyzer which I verified manually as well.

---
Full diff: https://github.com/llvm/llvm-project/pull/241058.diff


12 Files Affected:

- (modified) clang/test/Analysis/builtin-functions.cpp (+27) 
- (modified) clang/test/Analysis/div-zero.cpp (+15) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+38) 
- (modified) clang/test/Analysis/inner-pointer.cpp (+9) 
- (modified) clang/test/Analysis/loop-assumptions.c (+18-4) 
- (modified) clang/test/Analysis/mpichecker.cpp (+9) 
- (modified) clang/test/Analysis/mutually_exclusive_null_fp.cpp (+8) 
- (modified) clang/test/Analysis/placement-new.cpp (+12) 
- (modified) clang/test/Analysis/plist-macros-with-expansion.cpp (+28) 
- (modified) clang/test/Analysis/retain-release-region-store.m (+29) 
- (modified) clang/test/Analysis/trivial-copy-struct.cpp (+25-1) 
- (modified) clang/test/Analysis/vla.c (+22) 


``````````diff
diff --git a/clang/test/Analysis/builtin-functions.cpp 
b/clang/test/Analysis/builtin-functions.cpp
index f7bafabd23cbcc..91fe38a648857f 100644
--- a/clang/test/Analysis/builtin-functions.cpp
+++ b/clang/test/Analysis/builtin-functions.cpp
@@ -120,3 +120,30 @@ void test_constant_p(void *ptr) {
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(ptr == 0)); // expected-warning 
{{FALSE}}
 }
+
+#ifdef _WIN32
+namespace GH39448 {
+struct A { int someApi(); };
+
+int testAssert(A* a) {
+  __assume(a != nullptr);
+  return a->someApi();
+}
+
+int testAssert2(int* a) {
+  __assume(a != nullptr);
+  return *a;
+}
+
+int testAssert3(A* a) {
+  __assume(a);
+  return a->someApi();
+}
+
+int testAssert4(int* a) {
+  __assume(a);
+  return *a;
+}
+
+} // namespace GH39448
+#endif
diff --git a/clang/test/Analysis/div-zero.cpp b/clang/test/Analysis/div-zero.cpp
index c756f24dec86b0..83f597ad0ae08b 100644
--- a/clang/test/Analysis/div-zero.cpp
+++ b/clang/test/Analysis/div-zero.cpp
@@ -109,3 +109,18 @@ int t6() {
   return 1 / (f.x - 32); // expected-warning {{Division by zero}}
 }
 }
+
+namespace GH40797 {
+typedef __typeof(sizeof(int)) size_t;
+typedef long ssize_t;
+
+ssize_t read(int fd, void *buf, size_t count);
+
+ssize_t read_n(void *p, size_t size, size_t n) {
+  size_t len = n * size;
+  if (size && len / size != n)
+    return 0;
+  return len ? read(0, p, len) / size : 0; // no-warning
+}
+
+} // namespace GH40797
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 72d167f68a1f49..c0b437e17dfe22 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -4,6 +4,7 @@
 // RUN:   -analyzer-checker=unix.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=apiModeling.Errno \
 // RUN:   -analyzer-checker=unix.Errno \
+// RUN:   -analyzer-checker=unix.Malloc \
 // RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true
 
 #include "Inputs/errno_var.h"
@@ -175,3 +176,40 @@ void errno_realpath(char *Path, char *Buf) {
     if (errno) {} // expected-warning{{An undefined value may be read from 
'errno'}}
   }
 }
+
+#define PATH_MAX 4096
+#define AF_UNIX 1
+#define SOCK_SEQPACKET 5
+#define SOCK_CLOEXEC 02000000
+
+void *malloc(size_t);
+void free(void *);
+int dosomething(char *);
+
+int GH43015_connect_socket(char **mname) {
+  int ret;
+  *mname = (char *)malloc(PATH_MAX);
+
+  int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
+  if (fd < 0) {
+    ret = errno;
+    free(*mname);
+    return ret;
+  }
+
+  {
+    ret = recv(fd, *mname, PATH_MAX, 0);
+    if (ret > 0) return 0;
+  }
+  close(fd);
+  return ret;
+}
+
+int GH43015(void) {
+  char *mname;
+  int ret = GH43015_connect_socket(&mname);
+  if (ret)
+    return ret;
+
+  return dosomething(mname); // no-warning
+}
diff --git a/clang/test/Analysis/inner-pointer.cpp 
b/clang/test/Analysis/inner-pointer.cpp
index 4cb194409412c6..30081457364c3f 100644
--- a/clang/test/Analysis/inner-pointer.cpp
+++ b/clang/test/Analysis/inner-pointer.cpp
@@ -25,6 +25,8 @@ T *__addressof(T &arg);
 
 char *data(std::string &c);
 
+string to_string(int);
+
 } // end namespace std
 
 void consume(const char *) {}
@@ -437,3 +439,10 @@ void no_CXXRecordDecl() {
 void checkReference(std::string &s) {
   const char *c = s.c_str();
 }
+
+const char *GH59870(int value) {
+  thread_local std::string retval;
+
+  retval = std::to_string(value);
+  return retval.c_str(); // no-warning
+}
diff --git a/clang/test/Analysis/loop-assumptions.c 
b/clang/test/Analysis/loop-assumptions.c
index b61ed8815e3f6e..55a9e28525295f 100644
--- a/clang/test/Analysis/loop-assumptions.c
+++ b/clang/test/Analysis/loop-assumptions.c
@@ -1,12 +1,12 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection \
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
 // RUN:     -verify=expected,noassumeone,eagerlyassume,combo %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection \
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
 // RUN:     -analyzer-config eagerly-assume=false \
 // RUN:     -verify=expected,noassumeone,noeagerlyassume,combo %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection \
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
 // RUN:     -analyzer-config assume-at-least-one-iteration=true \
 // RUN:     -verify=expected,eagerlyassume,combo %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection \
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \
 // RUN:     -analyzer-config 
assume-at-least-one-iteration=true,eagerly-assume=false \
 // RUN:     -verify=expected,noeagerlyassume %s
 
@@ -260,3 +260,17 @@ void onlyLoopConditions(int arg) {
 
   clang_analyzer_dump(i); // expected-warning {{1}} expected-warning {{2}} 
expected-warning {{3}} expected-warning {{4}}
 }
+
+void GH20099(const unsigned char n) {
+
+  int buf[2][4] = {{0,0,0,0},{0,0,0,0}};
+  unsigned char j,k,l,x;
+
+  for (l = n - 1; l >= 1; l--)
+    x = 0;
+
+  for (j = n - 1; j >= 1; j--) {
+    for (k = 0; k <= j - 1; k++)
+      x = buf[k][j]; // no-warning
+  }
+}
diff --git a/clang/test/Analysis/mpichecker.cpp 
b/clang/test/Analysis/mpichecker.cpp
index f2fd6c0951a2fd..514167233320d5 100644
--- a/clang/test/Analysis/mpichecker.cpp
+++ b/clang/test/Analysis/mpichecker.cpp
@@ -380,3 +380,12 @@ void externFunctions2() {
   void callNonblockingExtern(MPI_Request *req);
   callNonblockingExtern(&req);
 }
+
+bool contains();
+void GH64647() {
+  if (contains()) {
+    MPI_Request request_item;
+    MPI_Wait(&request_item, MPI_STATUS_IGNORE); // expected-warning {{Request 
'request_item' has no matching nonblocking call.}}
+       }
+       GH64647();
+}
diff --git a/clang/test/Analysis/mutually_exclusive_null_fp.cpp 
b/clang/test/Analysis/mutually_exclusive_null_fp.cpp
index e74e4e7be3580b..ac4c1bc04a25c1 100644
--- a/clang/test/Analysis/mutually_exclusive_null_fp.cpp
+++ b/clang/test/Analysis/mutually_exclusive_null_fp.cpp
@@ -22,3 +22,11 @@ int compare(Data &a, Data &b) {
 
   return compare(*aData, *bData); // no-warning
 }
+
+void GH3206(char* a, char* b) {
+  if (a != b) {
+    if (a != nullptr || b == nullptr) {
+                       a[0] = '\0'; // no-warning
+               }
+  }
+}
diff --git a/clang/test/Analysis/placement-new.cpp 
b/clang/test/Analysis/placement-new.cpp
index 292ea40b150b88..d8629433d83d29 100644
--- a/clang/test/Analysis/placement-new.cpp
+++ b/clang/test/Analysis/placement-new.cpp
@@ -485,3 +485,15 @@ void test22() {
 }
 
 } // namespace testStructAlign
+
+namespace GH56264 {
+struct S {
+  int x;
+};
+
+void test() {
+  S arr[4];
+  ::new (arr + 1) S[1]; // no-warning
+}
+
+} // namespace GH56264
diff --git a/clang/test/Analysis/plist-macros-with-expansion.cpp 
b/clang/test/Analysis/plist-macros-with-expansion.cpp
index d57bb0f2dd2651..c41d7f2e29c230 100644
--- a/clang/test/Analysis/plist-macros-with-expansion.cpp
+++ b/clang/test/Analysis/plist-macros-with-expansion.cpp
@@ -948,3 +948,31 @@ int bz44493(void) {
 // CHECK-NEXT:   <key>expansion</key><string>--(a );</string>
 // CHECK-NEXT:  </dict>
 // CHECK-NEXT: </array>
+
+const char *traceid(const char *);
+int trace(int, const char *, int, ...);
+#define TRACE_CALL(tracelevel, ...)  { __VA_ARGS__; }
+
+#define TRACE(tracelevel, str, ...) \
+  TRACE_CALL((tracelevel), trace((0), traceid("formatstr " str), 0, 
tracelevel, __VA_ARGS__))
+
+#define TRACE_WRAPPER TRACE
+
+void GH47932(void* Context_p)
+{
+  int localvar;
+  TRACE_WRAPPER(localvar, "localvar=%u ", 0); // expected-warning {{4th 
function call argument is an uninitialized value}}
+}
+// CHECK:      <key>macro_expansions</key>
+// CHECK-NEXT: <array>
+// CHECK-NEXT:  <dict>
+// CHECK-NEXT:   <key>location</key>
+// CHECK-NEXT:   <dict>
+// CHECK-NEXT:    <key>line</key><integer>964</integer>
+// CHECK-NEXT:    <key>col</key><integer>3</integer>
+// CHECK-NEXT:    <key>file</key><integer>0</integer>
+// CHECK-NEXT:   </dict>
+// CHECK-NEXT:   <key>name</key><string>TRACE_WRAPPER(localvar, 
&quot;localvar=%u &quot;, 0)</string>
+// CHECK-NEXT:   <key>expansion</key><string>{trace ((0),traceid 
(&quot;formatstr &quot;&quot;localvar=%u &quot;),0,localvar ,0);}</string>
+// CHECK-NEXT:  </dict>
+// CHECK-NEXT: </array>
diff --git a/clang/test/Analysis/retain-release-region-store.m 
b/clang/test/Analysis/retain-release-region-store.m
index 2418c9a5383d19..1f6a96cb82a513 100644
--- a/clang/test/Analysis/retain-release-region-store.m
+++ b/clang/test/Analysis/retain-release-region-store.m
@@ -255,3 +255,32 @@ void R8261992_test(R8261992 *tc) {
   *p = 0xDEADBEEF; // expected-warning{{null}}
 }
 
+extern CFStringRef CFStringCreateCopy(CFAllocatorRef, CFStringRef) 
__attribute__((cf_returns_retained));
+extern CFStringRef exampleString;
+CFStringRef GH19340_Strings[2][2];
+
+@interface GH19340_StringCache : NSObject {
+  CFStringRef strings[2];
+  CFStringRef moreStrings[2][2];
+}
+@end
+
+@implementation GH19340_StringCache
+- (CFStringRef)stringAtZ:(int)z {
+  if (!strings[z])
+    strings[z] = CFStringCreateCopy(kCFAllocatorDefault, exampleString);
+  return strings[z]; // no-warning
+}
+
+- (CFStringRef)stringAtX:(int)x y:(int)y {
+  if (!moreStrings[x][y])
+    moreStrings[x][y] = CFStringCreateCopy(kCFAllocatorDefault, exampleString);
+  return moreStrings[x][y]; // no-warning
+}
+
+- (CFStringRef)staticStringAtX:(int)x y:(int)y {
+  if (!GH19340_Strings[x][y])
+    GH19340_Strings[x][y] = CFStringCreateCopy(kCFAllocatorDefault, 
exampleString);
+  return GH19340_Strings[x][y]; // no-warning
+}
+@end
diff --git a/clang/test/Analysis/trivial-copy-struct.cpp 
b/clang/test/Analysis/trivial-copy-struct.cpp
index b2da777541aba9..e8102834ac37a8 100644
--- a/clang/test/Analysis/trivial-copy-struct.cpp
+++ b/clang/test/Analysis/trivial-copy-struct.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify %s
 
 template <typename T> void clang_analyzer_dump(T);
 template <typename T> void clang_analyzer_value(T);
@@ -99,3 +99,27 @@ void nestedLazyCompoundVal(List* n) {
   }
   delete w;
 }
+
+struct GH60694_Node { GH60694_Node *parent; };
+
+void GH60694(GH60694_Node *a, GH60694_Node *b) {
+  if (a->parent)
+    return;
+  *a = *b;
+  a->parent->parent = 0;
+}
+
+void free(void *);
+
+struct GH26595_List { GH26595_List *next; };
+
+GH26595_List *GH26595(GH26595_List *item) {
+  GH26595_List *next = item->next;
+  if (next) {
+    *item = *next;
+    free(next);
+    return item->next; // no-warning
+  }
+
+  return item;
+}
diff --git a/clang/test/Analysis/vla.c b/clang/test/Analysis/vla.c
index e32fe63c931400..f1c5058c653e35 100644
--- a/clang/test/Analysis/vla.c
+++ b/clang/test/Analysis/vla.c
@@ -151,3 +151,25 @@ void b(void) {
       foo();
   }
 } // no-crash
+
+float GH49330(int nValues, int x) {
+  int sqr = nValues * nValues;
+  float array[sqr];
+
+  for(unsigned long i = 0; i < sqr; ++i) {
+    array[i] = 0;
+  }
+
+  float sum = 0;
+  for (int i = 0; i < nValues; i++){
+    for (int j = 0; j < nValues; j++) {
+      sum += x * array[i + nValues * j]; // no-warning
+    }
+  }
+
+  if ( x < 12 ) {
+    GH49330(nValues, x+1);
+  }
+
+  return sum;
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/241058
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to