[llvm-branch-commits] [cfe-tag] r251468 - [analyzer] checker-277: Apply lambda fixes and turn off nullability by default.

Devin Coughlin via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Oct 27 16:17:09 PDT 2015


Author: dcoughlin
Date: Tue Oct 27 18:17:09 2015
New Revision: 251468

URL: http://llvm.org/viewvc/llvm-project?rev=251468&view=rev
Log:
[analyzer] checker-277: Apply lambda fixes and turn off nullability by default.

Bring in the following commits from ToT:

r251289: [analyzer] Fixed a rare crash when analyzing lambda functions.
r251313: [analyzer] Added a missing test case for r251289.
r251404: [analyzer] Fix another crash when analyzing lambda functions.
r251407: [analyzer] Fix lambdas that are capturing constants.

to fix crashes when analyzing lambdas.

Also revert:

r247614: [Static Analyzer] Turn on some nullability checks by default.

to turn off nullability checking by default.

Modified:
    cfe/tags/checker/checker-277/lib/Driver/Tools.cpp
    cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/ExprEngine.cpp
    cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/MemRegion.cpp
    cfe/tags/checker/checker-277/test/Analysis/lambdas.cpp

Modified: cfe/tags/checker/checker-277/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/checker/checker-277/lib/Driver/Tools.cpp?rev=251468&r1=251467&r2=251468&view=diff
==============================================================================
--- cfe/tags/checker/checker-277/lib/Driver/Tools.cpp (original)
+++ cfe/tags/checker/checker-277/lib/Driver/Tools.cpp Tue Oct 27 18:17:09 2015
@@ -3339,11 +3339,6 @@ void Clang::ConstructJob(Compilation &C,
       CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mktemp");
       CmdArgs.push_back("-analyzer-checker=security.insecureAPI.mkstemp");
       CmdArgs.push_back("-analyzer-checker=security.insecureAPI.vfork");
-
-      // Default nullability checks.
-      CmdArgs.push_back("-analyzer-checker=nullability.NullPassedToNonnull");
-      CmdArgs.push_back(
-          "-analyzer-checker=nullability.NullReturnedFromNonnull");
     }
 
     // Set the output format. The default is plist, for (lame) historical

Modified: cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=251468&r1=251467&r2=251468&view=diff
==============================================================================
--- cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Oct 27 18:17:09 2015
@@ -1855,13 +1855,20 @@ void ExprEngine::VisitCommonDeclRefExpr(
       FieldDecl *LambdaThisCaptureField;
       CXXRec->getCaptureFields(LambdaCaptureFields, LambdaThisCaptureField);
       const FieldDecl *FD = LambdaCaptureFields[VD];
-      Loc CXXThis =
-          svalBuilder.getCXXThis(MD, LocCtxt->getCurrentStackFrame());
-      SVal CXXThisVal = state->getSVal(CXXThis);
-      V = state->getLValue(FD, CXXThisVal);
-      if (FD->getType()->isReferenceType() &&
-          !VD->getType()->isReferenceType())
-        CaptureByReference = true;
+      if (!FD) {
+        // When a constant is captured, sometimes no corresponding field is
+        // created in the lambda object.
+        assert(VD->getType().isConstQualified());
+        V = state->getLValue(VD, LocCtxt);
+      } else {
+        Loc CXXThis =
+            svalBuilder.getCXXThis(MD, LocCtxt->getCurrentStackFrame());
+        SVal CXXThisVal = state->getSVal(CXXThis);
+        V = state->getLValue(FD, CXXThisVal);
+        if (FD->getType()->isReferenceType() &&
+            !VD->getType()->isReferenceType())
+          CaptureByReference = true;
+      }
     } else {
       V = state->getLValue(VD, LocCtxt);
     }

Modified: cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=251468&r1=251467&r2=251468&view=diff
==============================================================================
--- cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/tags/checker/checker-277/lib/StaticAnalyzer/Core/MemRegion.cpp Tue Oct 27 18:17:09 2015
@@ -1022,7 +1022,8 @@ MemRegionManager::getCXXThisRegion(QualT
   // 'this' refers to a this to the enclosing scope, there is no right region to
   // return.
   while (!LC->inTopFrame() &&
-         PT != D->getThisType(getContext())->getAs<PointerType>()) {
+         (!D || D->isStatic() ||
+          PT != D->getThisType(getContext())->getAs<PointerType>())) {
     LC = LC->getParent();
     D = dyn_cast<CXXMethodDecl>(LC->getDecl());
   }

Modified: cfe/tags/checker/checker-277/test/Analysis/lambdas.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/tags/checker/checker-277/test/Analysis/lambdas.cpp?rev=251468&r1=251467&r2=251468&view=diff
==============================================================================
--- cfe/tags/checker/checker-277/test/Analysis/lambdas.cpp (original)
+++ cfe/tags/checker/checker-277/test/Analysis/lambdas.cpp Tue Oct 27 18:17:09 2015
@@ -176,6 +176,40 @@ void inlineDefensiveChecks() {
   (void)p;
 }
 
+
+template<typename T>
+void callLambda(T t) {
+  t();
+}
+
+struct DontCrash {
+  int x;
+  void f() {
+    callLambda([&](){ ++x; });
+    callLambdaFromStatic([&](){ ++x; });
+  }
+  
+  template<typename T>
+  static void callLambdaFromStatic(T t) {
+    t();
+  }
+};
+
+
+// Capture constants
+
+void captureConstants() {
+  const int i = 5;
+  [=]() {
+    if (i != 5)
+      clang_analyzer_warnIfReached();
+  }();
+  [&] {
+    if (i != 5)
+      clang_analyzer_warnIfReached();
+  }();
+}
+
 // CHECK: [B2 (ENTRY)]
 // CHECK:   Succs (1): B1
 // CHECK: [B1]




More information about the llvm-branch-commits mailing list