[cfe-commits] r58478 - /cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
Ted Kremenek
kremenek at apple.com
Thu Oct 30 17:13:20 PDT 2008
Author: kremenek
Date: Thu Oct 30 19:13:20 2008
New Revision: 58478
URL: http://llvm.org/viewvc/llvm-project?rev=58478&view=rev
Log:
Enhance path-sensitive return-of-stack-address check to print out the line number of a compound literal (whose address is being returned) instead of printing out the hex representation of the pointer address of the CompoundLiteralExpr.
Modified:
cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
Modified: cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp?rev=58478&r1=58477&r2=58478&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Thu Oct 30 19:13:20 2008
@@ -14,6 +14,7 @@
#include "clang/Analysis/PathSensitive/BugReporter.h"
#include "clang/Analysis/PathSensitive/GRExprEngine.h"
+#include "clang/Basic/SourceManager.h"
#include "llvm/Support/Compiler.h"
#include <sstream>
@@ -200,13 +201,29 @@
// Generate a report for this bug.
std::ostringstream os;
- os << "Address of stack memory associated with local variable '"
- << V.getRegion()->getString() << "' returned.";
+ SourceRange R;
- std::string s = os.str();
+ // Check if the region is a compound literal.
+ if (const CompoundLiteralRegion* CR =
+ dyn_cast<CompoundLiteralRegion>(V.getRegion())) {
+
+ const CompoundLiteralExpr* CL = CR->getLiteralExpr();
+ os << "Address of stack memory associated with a compound literal "
+ "declared on line "
+ << BR.getSourceManager().getLogicalLineNumber(CL->getLocStart())
+ << " returned.";
+
+ R = CL->getSourceRange();
+ }
+ else {
+ os << "Address of stack memory associated with local variable '"
+ << V.getRegion()->getString() << "' returned.";
+ }
+ std::string s = os.str();
RangedBugReport report(*this, N, s.c_str());
report.addRange(E->getSourceRange());
+ if (R.isValid()) report.addRange(R);
// Emit the warning.
BR.EmitWarning(report);
More information about the cfe-commits
mailing list