https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104288
Bug ID: 104288 Summary: Null pointer check invalidly deleted Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: nrk at disroot dot org Target Milestone: --- Hi, In the following code, the null checks are removed when compiled with `-O2` on gcc v11.2.1. Compiling with `-O2 -fno-delete-null-pointer-checks` produces proper result. #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define RESULT_PASS "PASS" #define RESULT_FAIL "FAIL" void test_assert(bool result) { printf("Assert: %s\n", result ? RESULT_PASS : RESULT_FAIL); if (!result) exit(EXIT_FAILURE); } void test_strcmp(const char *value_1, const char *value_2) { test_assert(value_1 != NULL); test_assert(value_2 != NULL); bool result = !strcmp(value_1, value_2); printf("Test equal: %s\n", result ? RESULT_PASS : RESULT_FAIL); } int main() { test_strcmp(NULL, "value 1"); } (code snippet taken from: https://gist.github.com/novns/c84d6e1efd6304b3076811fef34096fd )