aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/malloc-paths-4.c
blob: 7b7803eac45ad5cb48964ff51737e55aeee2ecc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 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 } */
}