[PATCH] D149158: [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 26 23:57:42 PDT 2023


steakhal added inline comments.


================
Comment at: clang/test/Analysis/Inputs/std-c-library-functions.h:1-2
+typedef typeof(sizeof(int)) size_t;
+typedef signed long ssize_t;
+typedef struct {
----------------
balazske wrote:
> steakhal wrote:
> > `ssize_t`'s size should match the size of `size_t`. In this implementation, it would be true only if `size_t` is `long`.
> > 
> I could not find a working way of defining the type in that way (there is no `__sizte_t`). The current definition should work well in the test code, the property of being the same size is supposedly not used in the tests. The previous definition was not better than this (and different in different places).
I think [[ https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/format-strings-scanf.c#L7-L15 | clang/test/Sema/format-strings-scanf.c ]] uses something like this: 
```lang=C++
typedef __SIZE_TYPE__ size_t;
#define __SSIZE_TYPE__                                                         \
  __typeof__(_Generic((__SIZE_TYPE__)0,                                        \
                      unsigned long long int : (long long int)0,               \
                      unsigned long int : (long int)0,                         \
                      unsigned int : (int)0,                                   \
                      unsigned short : (short)0,                               \
                      unsigned char : (signed char)0))
typedef __SSIZE_TYPE__ ssize_t;
```


================
Comment at: clang/test/Analysis/Inputs/std-c-library-functions.h:31
+int getchar(void);
+size_t fread(void *restrict, size_t, size_t, FILE *restrict);
+size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
----------------
steakhal wrote:
> `restrict` will only work if this header is included from `C` files. In `C++` files we will have a surprising behavior.
Ah, now I see a better way of doing this from [[ https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/Inputs/system-header-simulator.h#L8-L10 | clang/test/Analysis/Inputs/system-header-simulator.h ]]:
```lang=C++
#ifdef __cplusplus
#define restrict /*restrict*/
#endif
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149158/new/

https://reviews.llvm.org/D149158



More information about the cfe-commits mailing list