[Bug testsuite/108161] New: gcc.dg/ipa/pr96040.c fails with incorrect size_t assumption (snprintf, strspn)
nightstrike at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Dec 17 22:30:33 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108161
Bug ID: 108161
Summary: gcc.dg/ipa/pr96040.c fails with incorrect size_t
assumption (snprintf, strspn)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: testsuite
Assignee: unassigned at gcc dot gnu.org
Reporter: nightstrike at gmail dot com
Target Milestone: ---
gcc.dg/ipa/pr96040.c assumes that size_t is unsigned long, which it isn't for
LLP64. The following definitions are therefor incorrect:
int snprintf(char *, unsigned long, const char *, ...);
unsigned long strspn(const char *, const char *);
Changing "unsigned long" in both instances to "__SIZE_TYPE__" makes the test
pass:
int snprintf(char *, __SIZE_TYPE__, const char *, ...);
__SIZE_TYPE__ strspn(const char *, const char *);
However, it's also possible, and perhaps more maintainable, to just use
__builtin_*, or to include <stdio.h> and <string.h>. Both of the following
options work, though there are many ways to skin this cat:
diff --git a/gcc/testsuite/gcc.dg/ipa/pr96040.c
b/gcc/testsuite/gcc.dg/ipa/pr96040.c
index af7e9c4ed94..9c9b76269a6 100644
--- a/gcc/testsuite/gcc.dg/ipa/pr96040.c
+++ b/gcc/testsuite/gcc.dg/ipa/pr96040.c
@@ -3,8 +3,8 @@
int puts(const char *);
-int snprintf(char *, unsigned long, const char *, ...);
-unsigned long strspn(const char *, const char *);
+int snprintf(char *, __SIZE_TYPE__, const char *, ...);
+__SIZE_TYPE__ strspn(const char *, const char *);
struct TValue {
union {
diff --git a/gcc/testsuite/gcc.dg/ipa/pr96040.c
b/gcc/testsuite/gcc.dg/ipa/pr96040.c
index af7e9c4ed94..2c8d405ff9b 100644
--- a/gcc/testsuite/gcc.dg/ipa/pr96040.c
+++ b/gcc/testsuite/gcc.dg/ipa/pr96040.c
@@ -3,8 +3,8 @@
int puts(const char *);
-int snprintf(char *, unsigned long, const char *, ...);
-unsigned long strspn(const char *, const char *);
+#define snprintf __builtin_snprintf
+#define strspn __builtin_strspn
struct TValue {
union {
More information about the Gcc-bugs
mailing list