[cfe-commits] r163012 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp test/Analysis/retain-release.mm

Jordan Rose jordan_rose at apple.com
Fri Aug 31 11:19:18 PDT 2012


Author: jrose
Date: Fri Aug 31 13:19:18 2012
New Revision: 163012

URL: http://llvm.org/viewvc/llvm-project?rev=163012&view=rev
Log:
[analyzer] RetainCountChecker: don't assume all functions have names.

Fixes a hard-to-reach crash when calling a non-member overloaded operator
with arguments that may be callbacks.

Future-proofing: don't make the same assumption in MallocSizeofChecker.
Aside from possibly respecting attributes in the future, it might be
possible to call 'malloc' through a function pointer.

I audited all other uses of FunctionDecl::getIdentifier() in the analyzer;
they all now correctly test to see if the identifier is present before
using it.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
    cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
    cfe/trunk/test/Analysis/retain-release.mm

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp?rev=163012&r1=163011&r2=163012&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp Fri Aug 31 13:19:18 2012
@@ -196,9 +196,13 @@
           SmallString<64> buf;
           llvm::raw_svector_ostream OS(buf);
 
-          OS << "Result of '"
-             << i->AllocCall->getDirectCallee()->getIdentifier()->getName()
-             << "' is converted to a pointer of type '"
+          OS << "Result of ";
+          const FunctionDecl *Callee = i->AllocCall->getDirectCallee();
+          if (Callee && Callee->getIdentifier())
+            OS << '\'' << Callee->getIdentifier()->getName() << '\'';
+          else
+            OS << "call";
+          OS << " is converted to a pointer of type '"
              << PointeeType.getAsString() << "', which is incompatible with "
              << "sizeof operand type '" << SizeofType.getAsString() << "'";
           llvm::SmallVector<SourceRange, 4> Ranges;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=163012&r1=163011&r2=163012&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Fri Aug 31 13:19:18 2012
@@ -950,8 +950,9 @@
       IdentifierInfo *Name = FC->getDecl()->getIdentifier();
 
       // This callback frees the associated buffer.
-      if (Name->isStr("CGBitmapContextCreateWithData"))
-        RE = S->getRetEffect();
+      if (Name)
+        if (Name->isStr("CGBitmapContextCreateWithData"))
+          RE = S->getRetEffect();
     }
 
     S = getPersistentSummary(RE, RecEffect, DefEffect);

Modified: cfe/trunk/test/Analysis/retain-release.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.mm?rev=163012&r1=163011&r2=163012&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.mm (original)
+++ cfe/trunk/test/Analysis/retain-release.mm Fri Aug 31 13:19:18 2012
@@ -366,3 +366,22 @@
     return string;
 }
 
+//===----------------------------------------------------------------------===//
+// Don't crash on non-member functions with "callbacks" but without names.
+//===----------------------------------------------------------------------===//
+
+struct IntWrapper {
+  int arg;
+};
+
+int operator>> (const IntWrapper &W, int (*f)(int)) {
+  return f(W.arg);
+}
+
+void testCallback() {
+  IntWrapper val = { 42 };
+
+  extern int process(int);
+  val >> process;
+}
+





More information about the cfe-commits mailing list