| Issue |
63326
|
| Summary |
[Clang] Unsafe pointers and C standard issues
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
luc0x61
|
The following short code exploits **three** possible issues with warnings and errors:
``` lang-c
/// \file unsafe.c
// clang -std=c11 -Weverything unsafe.c -o unsafe.exe
#include <stddef.h>
static int goo (int * pi, size_t a)
{
return pi[a];
}
int main (int argc, char *argv[])
{
(void)argc;
(void)argv;
int goz[4] = { 0, };
return goo(goz, 0);
}
```
Compiling on Windows 11 pro x64, but with the standard x86 installer (released Clang/LLVM 16.0.6, "LLVM-16.0.6-win32.exe"):
```
# clang --version
clang version 16.0.6
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files (x86)\LLVM\bin
# clang -std=c11 -Weverything unsafe.c -o unsafe.exe
unsafe.c:5:24: warning: 'pi' is an unsafe pointer used for buffer access
[-Wunsafe-buffer-usage]
static int goo (int * pi, size_t a)
~~~~~~^~
unsafe.c:7:12: note: used in buffer access here
return pi[a];
^~
unsafe.c:14:13: warning: mixing declarations and code is incompatible with
standards before C99 [-Wdeclaration-after-statement]
int goz[4] = { 0, };
^
2 warnings generated.
```
1. Looks like I can't pass a generic pointer and do any arithmetics on it without the unsafe pointer warning (lines 5, 7): am I missing anything?
2. I requested C11 standard, but still receive C99 warning (line 14): does it make any sense?
3. Note that if I delete/comment the `#include` line there is no error/warning on `size_t` missing definition, compilation goes smooth
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs