public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104288] New: Null pointer check invalidly deleted
@ 2022-01-30 10:09 nrk at disroot dot org
  2022-01-30 10:26 ` [Bug middle-end/104288] [11/12 Regression] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: nrk at disroot dot org @ 2022-01-30 10:09 UTC (permalink / raw)
  To: gcc-bugs

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 )

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-04-09  7:43 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30 10:09 [Bug c/104288] New: Null pointer check invalidly deleted nrk at disroot dot org
2022-01-30 10:26 ` [Bug middle-end/104288] [11/12 Regression] " pinskia at gcc dot gnu.org
2022-01-30 10:29 ` [Bug tree-optimization/104288] [11/12 Regression] EVRP null pointer check removal for strcmp (and maybe others) is not flow senative pinskia at gcc dot gnu.org
2022-01-30 11:03 ` jakub at gcc dot gnu.org
2022-01-31  8:21 ` rguenth at gcc dot gnu.org
2022-01-31 14:53 ` amacleod at redhat dot com
2022-01-31 15:34 ` jakub at gcc dot gnu.org
2022-01-31 22:39 ` amacleod at redhat dot com
2022-02-01  8:04 ` rguenther at suse dot de
2022-02-02 21:52 ` amacleod at redhat dot com
2022-02-08 15:03 ` cvs-commit at gcc dot gnu.org
2022-02-09 14:10 ` cvs-commit at gcc dot gnu.org
2022-02-09 14:11 ` amacleod at redhat dot com
2023-04-09  3:59 ` christian.prochaska@genode-labs.com
2023-04-09  4:12 ` pinskia at gcc dot gnu.org
2023-04-09  4:12 ` pinskia at gcc dot gnu.org
2023-04-09  7:07 ` christian.prochaska@genode-labs.com
2023-04-09  7:43 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).