aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer/malloc-paths-4.c
blob: 6976fce7ec66568228de55ce0e0a08e37c00b6cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */

/* Verify that we emit sane paths for state machine errors.  */

#include <stdlib.h>

int *test_4 (void)
{
  int *ptr = (int *)malloc (sizeof (int)); /* { dg-line malloc } */
  if (ptr) /* { dg-line cond } */
    *ptr = 42;
  else
    *ptr = 43; /* { dg-line on_null_ptr } */
  return ptr;

  /* { dg-warning "dereference of NULL 'ptr'" "warning" { target *-*-* } on_null_ptr } */
  /* { dg-message "\\(1\\) allocated here" "event 1" { target *-*-* } malloc } */
  /* { dg-message "\\(2\\) assuming 'ptr' is NULL" "event 2" { target *-*-* } cond } */
  /* { dg-message "\\(3\\) following 'false' branch \\(when 'ptr' is NULL\\)\\.\\.\\." "event 3" { target *-*-* } cond } */
  /* { dg-message "\\(4\\) \\.\\.\\.to here" "event 4" { target *-*-* } on_null_ptr } */
  /* { dg-message "\\(5\\) dereference of NULL 'ptr'" "event 5" { target *-*-* } on_null_ptr } */
}