]> granicus.if.org Git - clang/commitdiff
Enhance path-sensitive return-of-stack-address check to print out the line number...
authorTed Kremenek <kremenek@apple.com>
Fri, 31 Oct 2008 00:13:20 +0000 (00:13 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 31 Oct 2008 00:13:20 +0000 (00:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58478 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngineInternalChecks.cpp

index c313697b9eab06ca13467b6021ea27f35bfb5bf2..428ffb23be96b1eb0cd4632de96d859ad9e10f3b 100644 (file)
@@ -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 @@ public:
       
       // 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);