Issue 145218
Summary No warning about dangerous pointer casts
Labels new issue
Assignees
Reporter wo4mei3
    Both Clang and GCC do not issue any warnings about the following code, even with the -Wall option.
For Clang, I used Clang-16.
The executable produced by GCC caused a segmentation fault, while Clang's always prints 1.
I propose that casting a pointer from a smaller pointee type to larger one, which can easily lead to segmentation faults should produce a compiler warning.

```
#include <stdio.h>

struct X {
 int x;
};

struct Y {
        int x;
        int y;
};

int main(void) {
        struct X x = {0};
        struct Y* y = (struct Y*) &x;
        y->y = 1;
        printf("%d", y->y);
        return 0;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to