llvm-capstone/clang/test/Analysis/plist-html-macros.c
Kristof Umann 4962816e72 [analyzer] Fix an assertation failure for invalid sourcelocation, add a new debug checker
For a rather short code snippet, if debug.ReportStmts (added in this patch) was
enabled, a bug reporter visitor crashed:

struct h {
  operator int();
};

int k() {
  return h();
}

Ultimately, this originated from PathDiagnosticLocation::createMemberLoc, as it
didn't handle the case where it's MemberExpr typed parameter returned and
invalid SourceLocation for MemberExpr::getMemberLoc. The solution was to find
any related valid SourceLocaion, and Stmt::getBeginLoc happens to be just that.

Differential Revision: https://reviews.llvm.org/D58777

llvm-svn: 356161
2019-03-14 16:10:29 +00:00

34 lines
873 B
C

// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
// (sanity check)
// RUN: rm -rf %t.dir
// RUN: mkdir -p %t.dir
//
// RUN: %clang_analyze_cc1 -o %t.dir/index.plist %s \
// RUN: -analyzer-checker=core -analyzer-output=plist-html
//
// RUN: ls %t.dir | grep '\.html' | count 1
// RUN: grep '\.html' %t.dir/index.plist | count 1
// This tests two things: that the two calls to null_deref below are coalesced
// into a single bug by both the plist and HTML diagnostics, and that the plist
// diagnostics have a reference to the HTML diagnostics. (It would be nice to
// check more carefully that the two actually match, but that's hard to write
// in a lit RUN line.)
#define CALL_FN(a) null_deref(a)
void null_deref(int *a) {
if (a)
return;
*a = 1; // expected-warning{{null}}
}
void test1() {
CALL_FN(0);
}
void test2(int *p) {
CALL_FN(p);
}