Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h @@ -313,6 +313,8 @@ bool hasRange() const { return K == StmtK || K == RangeK || K == DeclK; } + bool hasValidLocation() const { return asLocation().isValid(); } + void invalidate() { *this = PathDiagnosticLocation(); } @@ -468,7 +470,7 @@ PathDiagnosticPiece::Kind k, bool addPosRange = true) : PathDiagnosticPiece(s, k), Pos(pos) { - assert(Pos.isValid() && Pos.asLocation().isValid() && + assert(Pos.isValid() && Pos.hasValidLocation() && "PathDiagnosticSpotPiece's must have a valid location."); if (addPosRange && Pos.hasRange()) addRange(Pos.asRange()); } Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -578,6 +578,10 @@ PathDiagnosticLocation L = PathDiagnosticLocation::create(N->getLocation(), SM); + if (!L.hasValidLocation()) { + // Do we need to suppress our report for body-farmed functions as well? + return nullptr; + } SmallString<256> sbuf; llvm::raw_svector_ostream os(sbuf); Index: clang/test/Analysis/diagnostics/body-farm-crashes.c =================================================================== --- /dev/null +++ clang/test/Analysis/diagnostics/body-farm-crashes.c @@ -0,0 +1,15 @@ +// RUN: %clang_analyze_cc1 -w -analyzer-checker=core\ +// RUN: -analyzer-output=text -verify %s +// +int OSAtomicCompareAndSwapPtrBarrier(*, *, **); +int OSAtomicCompareAndSwapPtrBarrier() {} +int *atomicInvalidSLocOnRedecl() { + int *b; // expected-note{{'b' declared without an initial value}} + + // FIXME: These notes shouldn't be there because there's nothing between them. + OSAtomicCompareAndSwapPtrBarrier(0, 0, &b); // expected-note{{Calling 'OSAtomicCompareAndSwapPtrBarrier'}} + // expected-note@-1{{Returning from 'OSAtomicCompareAndSwapPtrBarrier'}} + + return b; // expected-warning{{Undefined or garbage value returned to caller}} + // expected-note@-1{{Undefined or garbage value returned to caller}} +}