view clang/test/Analysis/mutually_exclusive_null_fp.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children
line wrap: on
line source

// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s

// rdar://problem/56586853
// expected-no-diagnostics

struct Data {
  int x;
  Data *data;
};

int compare(Data &a, Data &b) {
  Data *aData = a.data;
  Data *bData = b.data;

  // Covers the cases where both pointers are null as well as both pointing to the same buffer.
  if (aData == bData)
    return 0;

  if (aData && !bData)
    return 1;

  if (!aData && bData)
    return -1;

  return compare(*aData, *bData); // no-warning
}