]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: fix issues in gcc.dg/analyzer/strchr-1.c seen with C23 libc
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 25 Nov 2025 17:44:10 +0000 (12:44 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 25 Nov 2025 17:44:10 +0000 (12:44 -0500)
Simplify this test case in the hope of avoiding an error seen
with glibc-2.42.9000-537-gcd748a63ab1 in CI with
"Implement C23 const-preserving standard library macros".

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/strchr-1.c: Drop include of <string.h>, and use
__builtin_strchr throughout rather than strchr to avoid const
correctness issues when the header implements strchr with a C23
const-preserving macro.  Drop "const" from two vars.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/testsuite/gcc.dg/analyzer/strchr-1.c

index 181f1829724f84c0bfdc42e52359fedb8d2bec0a..5cc5fe55734faca1a48195a5173236cb0bb4c406 100644 (file)
@@ -1,4 +1,3 @@
-#include <string.h>
 #include "analyzer-decls.h"
 
 const char* test_literal (int x)
@@ -14,28 +13,28 @@ const char* test_literal (int x)
   return p;
 }
 
-void test_2 (const char *s, int c)
+void test_2 (char *s, int c)
 {
   char *p = __builtin_strchr (s, c); /* { dg-message "when '__builtin_strchr' returns NULL" } */
   *p = 'A'; /* { dg-warning "dereference of NULL 'p'" "null deref" } */
 }
 
-void test_3 (const char *s, int c)
+void test_3 (char *s, int c)
 {
-  char *p = strchr (s, c); /* { dg-message "when 'strchr' returns NULL" } */
+  char *p = __builtin_strchr (s, c); /* { dg-message "when '__builtin_strchr' returns NULL" } */
   *p = 'A'; /* { dg-warning "dereference of NULL 'p'" "null deref" } */
 }
 
 void test_unterminated (int c)
 {
   char buf[3] = "abc";
-  strchr (buf, c); /* { dg-warning "stack-based buffer over-read" } */
-  /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of 'strchr'..." "event" { target *-*-* } .-1 } */
+  __builtin_strchr (buf, c); /* { dg-warning "stack-based buffer over-read" } */
+  /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__builtin_strchr'..." "event" { target *-*-* } .-1 } */
 }
 
 void test_uninitialized (int c)
 {
   char buf[16];
-  strchr (buf, c); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */
-  /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of 'strchr'..." "event" { target *-*-* } .-1 } */
+  __builtin_strchr (buf, c); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */
+  /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of '__builtin_strchr'..." "event" { target *-*-* } .-1 } */
 }