[Bug analyzer/102052] New: analyser testsuite failures with LLP64 model

nightstrike at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Aug 25 02:17:49 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102052

            Bug ID: 102052
           Summary: analyser testsuite failures with LLP64 model
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: nightstrike at gmail dot com
  Target Milestone: ---

Additional details here:
https://gcc.gnu.org/pipermail/gcc/2021-August/237158.html

pr98969.c:9:19: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
* This fails because the function arguments are "long int", and that tries to
hold a pointer.  It should be uintptr_t or similar.

Something like this should work:

diff --git a/gcc/testsuite/gcc.dg/analyzer/pr98969.c
b/gcc/testsuite/gcc.dg/analyzer/pr98969.c
index 7e1587d..770e6d2 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pr98969.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pr98969.c
@@ -4,14 +4,14 @@ struct foo
 };

 void
-test_1 (long int i)
+test_1 (__UINTPTR_TYPE__ i)
 {
   struct foo *f = (struct foo *)i;
   f->expr = __builtin_malloc (1024);
 } /* { dg-bogus "leak" } */

 void
-test_2 (long int i)
+test_2 (__UINTPTR_TYPR__ i)
 {
   __builtin_free (((struct foo *)i)->expr);
   __builtin_free (((struct foo *)i)->expr); /* { dg-warning "double-'free' of
'\\*\\(\\(struct foo \\*\\)i\\)\\.expr'" } */



pr99716-2.c:13:30: warning: implicit declaration of function 'random';did you
mean 'rand'? [-Wimplicit-function-declaration]
* The C function is rand(), so it's not clear to me at least why the code is
using random.  I have no idea what the test is testing, so I don't know if
rand() is a drop in replacement, but here you go:

index 7c9881c..adc9819 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pr99716-2.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pr99716-2.c
@@ -10,7 +10,7 @@ extern int foo (void);
 void
 test_mountpoint (const char *mp)
 {
-  const int nr_passes = 5 + (random () & 31);
+  const int nr_passes = 5 + (rand () & 31);
   int pass;
   int ret = 1;
   FILE *fp;



pr99774-1.c:12:14: warning: conflicting types for built-in function 'calloc';
expected 'void *(long long unsigned int,  long long unsigned int)'
[-Wbuiltin-declaration-mismatch]
zlib-5.c:10:15: warning: conflicting types for built-in function 'strlen';
expected 'long long unsigned int(const char *)'
[-Wbuiltin-declaration-mismatch]
zlib-5.c:16:14: warning: conflicting types for built-in function 'calloc';
expected 'void *(long long unsigned int,  long long unsigned int)'
[-Wbuiltin-declaration-mismatch]
* These are all examples of hardcoding a size_t typedef that is incorrect for
an LLP64 model.  Something like this would probably be enough to fix it:

diff --git a/gcc/testsuite/gcc.dg/analyzer/pr99774-1.c
b/gcc/testsuite/gcc.dg/analyzer/pr99774-1.c
index 620cf65..a2138d9 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pr99774-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pr99774-1.c
@@ -7,9 +7,8 @@ typedef unsigned char uint8_t;
 typedef unsigned short uint16_t;
 typedef unsigned long uint64_t;
 typedef unsigned long uint64_t;
-typedef long unsigned int size_t;

-extern void *calloc(size_t __nmemb, size_t __size)
+extern void *calloc(__SIZE_TYPE__ __nmemb, __SIZE_TYPE__ __size)
   __attribute__((__nothrow__, __leaf__))
   __attribute__((__malloc__))
   __attribute__((__alloc_size__(1, 2)))
diff --git a/gcc/testsuite/gcc.dg/analyzer/zlib-5.c
b/gcc/testsuite/gcc.dg/analyzer/zlib-5.c
index afb6102..93df2b1 100644
--- a/gcc/testsuite/gcc.dg/analyzer/zlib-5.c
+++ b/gcc/testsuite/gcc.dg/analyzer/zlib-5.c
@@ -2,18 +2,17 @@

 #include "analyzer-decls.h"

-typedef long unsigned int size_t;
 typedef unsigned char Byte;
 typedef unsigned int uInt;
 typedef unsigned long uLong;

-extern size_t strlen(const char *__s) __attribute__((__nothrow__, __leaf__))
+extern __SIZE_TYPE__ strlen(const char *__s) __attribute__((__nothrow__,
__leaf__))
     __attribute__((__pure__)) __attribute__((__nonnull__(1)));
 extern void exit(int __status) __attribute__((__nothrow__, __leaf__))
     __attribute__((__noreturn__));
 extern char *strcpy(char *__restrict __dest, const char *__restrict __src)
     __attribute__((__nothrow__, __leaf__)) __attribute__((__nonnull__(1, 2)));
-extern void *calloc(size_t __nmemb, size_t __size)
+extern void *calloc(__SIZE_TYPE__ __nmemb, __SIZE_TYPE__ __size)
     __attribute__((__nothrow__, __leaf__)) __attribute__((__malloc__));

 extern int compress(Byte *dest, uLong *destLen, const Byte *source,



strndup-1.c:9:13: warning: incompatible implicit declaration of built-in
function 'strndup' [-Wbuiltin-declaration-mismatch]
* This function doesn't exist on windows.  So, either we add it to libmingwex
if it isn't already there and then link that library in to
the test, or just mark it as unsupported.  I'd probably prefer the former, but
it's not up to me.  Let me know what I should do here.


gcc.dg/analyzer/gzio-3.c:
gcc.dg/analyzer/gzio-3a.c:
* For some reason, these work.  Maybe fread() isn't a builtin? Maybe
there's a way to make gcc emit a warning when fread() is redefined
differently.


More information about the Gcc-bugs mailing list