[cfe-commits] r152964 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h lib/StaticAnalyzer/Checkers/MallocChecker.cpp lib/StaticAnalyzer/Core/PathDiagnostic.cpp test/Analysis/malloc-plist.c
Anna Zaks
ganna at apple.com
Fri Mar 16 16:44:28 PDT 2012
Author: zaks
Date: Fri Mar 16 18:44:28 2012
New Revision: 152964
URL: http://llvm.org/viewvc/llvm-project?rev=152964&view=rev
Log:
[analyzer] Shorten the stack hint diagnostic.
Do not display the standard "Returning from 'foo'", when a stack hint is
available.
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
cfe/trunk/test/Analysis/malloc-plist.c
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=152964&r1=152963&r2=152964&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Fri Mar 16 18:44:28 2012
@@ -398,7 +398,7 @@
/// 'Msg via Nth parameter'
virtual std::string getMessageForArg(const Expr *ArgE, unsigned ArgIndex);
virtual std::string getMessageForReturn(const CallExpr *CallExpr) {
- return Msg + " returned";
+ return Msg;
}
virtual std::string getMessageForSymbolNotFound() {
return Msg;
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=152964&r1=152963&r2=152964&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Fri Mar 16 18:44:28 2012
@@ -254,7 +254,7 @@
SmallString<200> buf;
llvm::raw_svector_ostream os(buf);
- os << "; reallocation of ";
+ os << "Reallocation of ";
// Printed parameters start at 1, not 0.
printOrdinal(++ArgIndex, os);
os << " parameter failed";
@@ -263,7 +263,7 @@
}
virtual std::string getMessageForReturn(const CallExpr *CallExpr) {
- return "; reallocation of returned value failed";
+ return "Reallocation of returned value failed";
}
};
};
@@ -1292,15 +1292,17 @@
if (Mode == Normal) {
if (isAllocated(RS, RSPrev, S)) {
Msg = "Memory is allocated";
- StackHint = new StackHintGeneratorForSymbol(Sym, "; allocated memory");
+ StackHint = new StackHintGeneratorForSymbol(Sym,
+ "Returned allocated memory");
} else if (isReleased(RS, RSPrev, S)) {
Msg = "Memory is released";
- StackHint = new StackHintGeneratorForSymbol(Sym, "; released memory");
+ StackHint = new StackHintGeneratorForSymbol(Sym,
+ "Returned released memory");
} else if (isReallocFailedCheck(RS, RSPrev, S)) {
Mode = ReallocationFailed;
Msg = "Reallocation failed";
StackHint = new StackHintGeneratorForReallocationFailed(Sym,
- "; reallocation failed");
+ "Reallocation failed");
}
// We are in a special mode if a reallocation failed later in the path.
@@ -1320,7 +1322,8 @@
if (!(FunName.equals("realloc") || FunName.equals("reallocf")))
return 0;
Msg = "Attempt to reallocate memory";
- StackHint = new StackHintGeneratorForSymbol(Sym, "; reallocated memory");
+ StackHint = new StackHintGeneratorForSymbol(Sym,
+ "Returned reallocated memory");
Mode = Normal;
}
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=152964&r1=152963&r2=152964&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Fri Mar 16 18:44:28 2012
@@ -568,12 +568,12 @@
return 0;
SmallString<256> buf;
llvm::raw_svector_ostream Out(buf);
- if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Callee))
+ if (!CallStackMessage.empty())
+ Out << CallStackMessage;
+ else if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Callee))
Out << "Returning from '" << *ND << "'";
else
Out << "Returning to caller";
- if (!CallStackMessage.empty())
- Out << CallStackMessage;
return new PathDiagnosticEventPiece(callReturn, Out.str());
}
Modified: cfe/trunk/test/Analysis/malloc-plist.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-plist.c?rev=152964&r1=152963&r2=152964&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc-plist.c (original)
+++ cfe/trunk/test/Analysis/malloc-plist.c Fri Mar 16 18:44:28 2012
@@ -87,6 +87,7 @@
v = malloc_wrapper_ret();
}
+
// CHECK: <?xml version="1.0" encoding="UTF-8"?>
// CHECK: <plist version="1.0">
// CHECK: <dict>
@@ -1129,9 +1130,9 @@
// CHECK: </array>
// CHECK: <key>depth</key><integer>1</integer>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Returning from 'wrapper'; allocated memory returned</string>
+// CHECK: <string>Returned allocated memory</string>
// CHECK: <key>message</key>
-// CHECK: <string>Returning from 'wrapper'; allocated memory returned</string>
+// CHECK: <string>Returned allocated memory</string>
// CHECK: </dict>
// CHECK: <dict>
// CHECK: <key>kind</key><string>control</string>
@@ -1568,9 +1569,9 @@
// CHECK: </array>
// CHECK: <key>depth</key><integer>2</integer>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Returning from 'my_free'; released memory via 1st parameter</string>
+// CHECK: <string>Returned released memory via 1st parameter</string>
// CHECK: <key>message</key>
-// CHECK: <string>Returning from 'my_free'; released memory via 1st parameter</string>
+// CHECK: <string>Returned released memory via 1st parameter</string>
// CHECK: </dict>
// CHECK: <dict>
// CHECK: <key>kind</key><string>control</string>
@@ -1631,9 +1632,9 @@
// CHECK: </array>
// CHECK: <key>depth</key><integer>1</integer>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Returning from 'my_malloc_and_free'; released memory via 1st parameter</string>
+// CHECK: <string>Returned released memory via 1st parameter</string>
// CHECK: <key>message</key>
-// CHECK: <string>Returning from 'my_malloc_and_free'; released memory via 1st parameter</string>
+// CHECK: <string>Returned released memory via 1st parameter</string>
// CHECK: </dict>
// CHECK: <dict>
// CHECK: <key>kind</key><string>control</string>
@@ -2139,9 +2140,9 @@
// CHECK: </array>
// CHECK: <key>depth</key><integer>1</integer>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Returning from 'my_realloc'; reallocation of 1st parameter failed</string>
+// CHECK: <string>Reallocation of 1st parameter failed</string>
// CHECK: <key>message</key>
-// CHECK: <string>Returning from 'my_realloc'; reallocation of 1st parameter failed</string>
+// CHECK: <string>Reallocation of 1st parameter failed</string>
// CHECK: </dict>
// CHECK: <dict>
// CHECK: <key>kind</key><string>control</string>
@@ -2419,9 +2420,9 @@
// CHECK: </array>
// CHECK: <key>depth</key><integer>1</integer>
// CHECK: <key>extended_message</key>
-// CHECK: <string>Returning from 'malloc_wrapper_ret'; allocated memory returned</string>
+// CHECK: <string>Returned allocated memory</string>
// CHECK: <key>message</key>
-// CHECK: <string>Returning from 'malloc_wrapper_ret'; allocated memory returned</string>
+// CHECK: <string>Returned allocated memory</string>
// CHECK: </dict>
// CHECK: <dict>
// CHECK: <key>kind</key><string>control</string>
More information about the cfe-commits
mailing list