Open 68b1592b-506f-4f32-b7cc-f7acec066692 opened 3 years ago
Related example:
#include <stdlib.h>
int test() {
char *x = malloc(-1);
char *y = malloc(2);
int ret = (x != NULL) && (y != NULL);
free(x); free(y);
return ret;
}
Arguably, this function must return "0" since it is impossible that both of these 'malloc's succeed. However, clang optimizes this function to return "1". (gcc will not do that.)
I saw the C++ bug report but (a) it was withdrawn, and (b) the response cited a C++ rule for why it was allowed. This is a C bug report.
So are you saying that C++ rules apply in this case? The cited provision is not in C11.
This bug has been marked as a duplicate of bug llvm/llvm-project#28790
Extended Description
Works with
-O0
With-O3
is optmized tohttps://godbolt.org/z/4fr7Wz7n7