[cfe-dev] bug with NonNullParamChecker?

Mathieu Baudet mathieubaudet at fb.com
Wed May 1 22:16:26 PDT 2013


Hi,

As I was testing NonNullParamChecker this afternoon, I ran into this troubling example:

// --------- example 1 ------------
void *getNull() {
  return 0;
}

void check(void *p) __attribute__(( nonnull ));
void check(void *p) {
}

int main(int argc, char **argv) {
  void *p = getNull();
  check(p);
  return 0;
}
// --------------------------------

This code gives no warning on the versions of clang that I could test:
- Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
- clang version 3.3 (trunk 180768)
- clang version 3.3 (trunk 180907) (llvm/trunk 180768)

To get an error one I have to replace p = getNull() by p = 0.

First I was tempted to think it was just a limitation of the core analyzer, but
1) I obtain an error with a similar example where the nonnull attribute is replaced by a division by zero (see example 2 at the end)

2) I debugged the file NonNullParamChecker.cpp : I am very new to this codebase but it seems that a report is actually emitted (lines 119-139). Then it never shows up for some reason...

Is this a bug? If not, how can we improve this checker?

Thanks!
--
Mathieu


// --------- example 2 -----------
int getX() {
  return 0;
}

void check(int p) {
  1 / p;
}

int main(int argc, char **argv) {
  int x = getX();
  check(x);
  return 0;
}





More information about the cfe-dev mailing list