diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 141518403344..4df77a845eb6 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -210,15 +210,17 @@ private:
// The allocated region symbol tracked by the main analysis.
SymbolRef Sym;
- // The mode we are in, i.e. what kind of diagnostics will be emitted.
- NotificationMode Mode;
+ // The mode we are in, i.e. what kind of diagnostics will be emitted.
+ NotificationMode Mode;
- // A symbol from when the primary region should have been reallocated.
- SymbolRef FailedReallocSymbol;
+ // A symbol from when the primary region should have been reallocated.
+ SymbolRef FailedReallocSymbol;
- public:
- MallocBugVisitor(SymbolRef S)
- : Sym(S), Mode(Normal), FailedReallocSymbol(0) {}
+ bool IsLeak;
+
+ public:
+ MallocBugVisitor(SymbolRef S, bool isLeak = false)
+ : Sym(S), Mode(Normal), FailedReallocSymbol(0), IsLeak(isLeak) {}
virtual ~MallocBugVisitor() {}
@@ -256,6 +258,20 @@ private:
const ExplodedNode *PrevN,
BugReporterContext &BRC,
BugReport &BR);
+
+ PathDiagnosticPiece* getEndPath(BugReporterContext &BRC,
+ const ExplodedNode *EndPathNode,
+ BugReport &BR) {
+ if (!IsLeak)
+ return 0;
+
+ PathDiagnosticLocation L =
+ PathDiagnosticLocation::createEndOfPath(EndPathNode,
+ BRC.getSourceManager());
+ // Do not add the statement itself as a range in case of leak.
+ return new PathDiagnosticEventPiece(L, BR.getDescription(), false);
+ }
+
private:
class StackHintGeneratorForReallocationFailed
: public StackHintGeneratorForSymbol {
@@ -895,7 +911,7 @@ void MallocChecker::reportLeak(SymbolRef Sym, ExplodedNode *N,
BugReport *R = new BugReport(*BT_Leak, os.str(), N, LocUsedForUniqueing);
R->markInteresting(Sym);
- R->addVisitor(new MallocBugVisitor(Sym));
+ R->addVisitor(new MallocBugVisitor(Sym, true));
C.EmitReport(R);
}
diff --git a/clang/test/Analysis/malloc-plist.c b/clang/test/Analysis/malloc-plist.c
index 8a36ab30856b..248abc21c889 100644
--- a/clang/test/Analysis/malloc-plist.c
+++ b/clang/test/Analysis/malloc-plist.c
@@ -350,21 +350,6 @@ void use_function_with_leak7() {
//CHECK: col5
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line14
-//CHECK: col5
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line14
-//CHECK: col6
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth0
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'p'
@@ -910,21 +895,6 @@ void use_function_with_leak7() {
//CHECK: col9
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line28
-//CHECK: col9
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line28
-//CHECK: col14
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth0
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'buf'
@@ -2400,21 +2370,6 @@ void use_function_with_leak7() {
//CHECK: col5
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line76
-//CHECK: col5
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line76
-//CHECK: col13
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth0
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'buf'
@@ -2843,21 +2798,6 @@ void use_function_with_leak7() {
//CHECK: col5
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line97
-//CHECK: col5
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line97
-//CHECK: col8
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth0
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'm'
@@ -3062,21 +3002,6 @@ void use_function_with_leak7() {
//CHECK: col5
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line102
-//CHECK: col5
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line102
-//CHECK: col11
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth1
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'x'
@@ -3281,21 +3206,6 @@ void use_function_with_leak7() {
//CHECK: col5
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line111
-//CHECK: col5
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line111
-//CHECK: col9
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth1
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'x'
@@ -3568,21 +3478,6 @@ void use_function_with_leak7() {
//CHECK: col9
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line120
-//CHECK: col9
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line120
-//CHECK: col9
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth1
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'x'
@@ -3855,21 +3750,6 @@ void use_function_with_leak7() {
//CHECK: col9
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line131
-//CHECK: col9
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line131
-//CHECK: col9
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth1
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'x'
@@ -4074,21 +3954,6 @@ void use_function_with_leak7() {
//CHECK: col12
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line142
-//CHECK: col12
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line142
-//CHECK: col29
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth1
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'x'
@@ -4293,21 +4158,6 @@ void use_function_with_leak7() {
//CHECK: col5
//CHECK: file0
//CHECK:
-//CHECK: ranges
-//CHECK:
-//CHECK:
-//CHECK:
-//CHECK: line153
-//CHECK: col5
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK: line153
-//CHECK: col23
-//CHECK: file0
-//CHECK:
-//CHECK:
-//CHECK:
//CHECK: depth1
//CHECK: extended_message
//CHECK: Memory is never released; potential leak of memory pointed to by 'x'