apelete updated this revision to Diff 55483.
apelete added a comment.

[scan-build] fix logic error warnings emitted on clang code base

Changes since last revison:

- lib/Format/AffectedRangeManager.h: fix declaration of nonPPLineAffected() to 
pass a reference to AnnotatedLine as first parameter.

- lib/Format/AffectedRangeManager.cpp: fix nonPPLineAffected() definition 
accordingly.


http://reviews.llvm.org/D19385

Files:
  lib/AST/DeclObjC.cpp
  lib/Format/AffectedRangeManager.cpp
  lib/Format/AffectedRangeManager.h
  lib/Frontend/CompilerInstance.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaLookup.cpp
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===================================================================
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -297,6 +297,7 @@
   if (!Diags.empty())
     SM = &Diags.front()->path.front()->getLocation().getManager();
 
+  assert(SM && "SourceManager is NULL, cannot iterate through the diagnostics");
 
   for (std::vector<const PathDiagnostic*>::iterator DI = Diags.begin(),
        DE = Diags.end(); DI != DE; ++DI) {
Index: lib/Sema/SemaLookup.cpp
===================================================================
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -3744,6 +3744,7 @@
   bool AnyVisibleDecls = !NewDecls.empty();
 
   for (/**/; DI != DE; ++DI) {
+    assert(*DI && "TypoCorrection iterator cannot be NULL");
     NamedDecl *VisibleDecl = *DI;
     if (!LookupResult::isVisible(SemaRef, *DI))
       VisibleDecl = findAcceptableDecl(SemaRef, *DI);
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -398,8 +398,10 @@
                                 SourceLocation TypeidLoc,
                                 Expr *E,
                                 SourceLocation RParenLoc) {
+  assert(E && "expression operand is NULL, cannot build C++ typeid expression");
+
   bool WasEvaluated = false;
-  if (E && !E->isTypeDependent()) {
+  if (!E->isTypeDependent()) {
     if (E->getType()->isPlaceholderType()) {
       ExprResult result = CheckPlaceholderExpr(E);
       if (result.isInvalid()) return ExprError();
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -742,7 +742,7 @@
 
   // Figure out where to get and map in the main file.
   if (InputFile != "-") {
-    const FileEntry *File;
+    const FileEntry *File = nullptr;
     if (Opts.FindPchSource.empty()) {
       File = FileMgr.getFile(InputFile, /*OpenFile=*/true);
     } else {
@@ -760,13 +760,14 @@
       SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 16>
           Includers;
       Includers.push_back(std::make_pair(FindFile, FindFile->getDir()));
-      File = HS->LookupFile(InputFile, SourceLocation(), /*isAngled=*/false,
-                            /*FromDir=*/nullptr,
-                            /*CurDir=*/UnusedCurDir, Includers,
-                            /*SearchPath=*/nullptr,
-                            /*RelativePath=*/nullptr,
-                            /*RequestingModule=*/nullptr,
-                            /*SuggestedModule=*/nullptr, /*SkipCache=*/true);
+      if (HS)
+        File = HS->LookupFile(InputFile, SourceLocation(), /*isAngled=*/false,
+                              /*FromDir=*/nullptr,
+                              /*CurDir=*/UnusedCurDir, Includers,
+                              /*SearchPath=*/nullptr,
+                              /*RelativePath=*/nullptr,
+                              /*RequestingModule=*/nullptr,
+                              /*SuggestedModule=*/nullptr, /*SkipCache=*/true);
       // Also add the header to /showIncludes output.
       if (File)
         DepOpts.ShowIncludesPretendHeader = File->getName();
Index: lib/Format/AffectedRangeManager.h
===================================================================
--- lib/Format/AffectedRangeManager.h
+++ lib/Format/AffectedRangeManager.h
@@ -54,7 +54,7 @@
 
   // Determines whether 'Line' is affected by the SourceRanges given as input.
   // Returns \c true if line or one if its children is affected.
-  bool nonPPLineAffected(AnnotatedLine *Line,
+  bool nonPPLineAffected(AnnotatedLine &Line,
                          const AnnotatedLine *PreviousLine);
   SourceManager &SourceMgr;
   const SmallVector<CharSourceRange, 8> Ranges;
Index: lib/Format/AffectedRangeManager.cpp
===================================================================
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -98,25 +98,28 @@
   }
 }
 
-bool AffectedRangeManager::nonPPLineAffected(
-    AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+bool AffectedRangeMLanager::nonPPLineAffected(
+    AnnotatedLine &Line, const AnnotatedLine *PreviousLine) {
   bool SomeLineAffected = false;
-  Line->ChildrenAffected =
-      computeAffectedLines(Line->Children.begin(), Line->Children.end());
-  if (Line->ChildrenAffected)
+  Line.ChildrenAffected =
+      computeAffectedLines(Line.Children.begin(), Line.Children.end());
+  if (Line.ChildrenAffected)
     SomeLineAffected = true;
 
-  // Stores whether one of the line's tokens is directly affected.
-  bool SomeTokenAffected = false;
   // Stores whether we need to look at the leading newlines of the next token
   // in order to determine whether it was affected.
   bool IncludeLeadingNewlines = false;
 
   // Stores whether the first child line of any of this line's tokens is
   // affected.
   bool SomeFirstChildAffected = false;
 
-  for (FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) {
+  // Stores whether one of the line's tokens is directly affected.
+  bool SomeTokenAffected = false;
+  if (Line.First == nullptr)
+    return SomeTokenAffected;
+
+  for (FormatToken *Tok = Line.First; Tok; Tok = Tok->Next) {
     // Determine whether 'Tok' was affected.
     if (affectsTokenRange(*Tok, *Tok, IncludeLeadingNewlines))
       SomeTokenAffected = true;
@@ -131,16 +134,16 @@
   // Was this line moved, i.e. has it previously been on the same line as an
   // affected line?
   bool LineMoved = PreviousLine && PreviousLine->Affected &&
-                   Line->First->NewlinesBefore == 0;
+                   Line.First->NewlinesBefore == 0;
 
   bool IsContinuedComment =
-      Line->First->is(tok::comment) && Line->First->Next == nullptr &&
-      Line->First->NewlinesBefore < 2 && PreviousLine &&
+      Line.First->is(tok::comment) && Line.First->Next == nullptr &&
+      Line.First->NewlinesBefore < 2 && PreviousLine &&
       PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
 
   if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
       IsContinuedComment) {
-    Line->Affected = true;
+    Line.Affected = true;
     SomeLineAffected = true;
   }
   return SomeLineAffected;
Index: lib/AST/DeclObjC.cpp
===================================================================
--- lib/AST/DeclObjC.cpp
+++ lib/AST/DeclObjC.cpp
@@ -1577,8 +1577,10 @@
           data().IvarList = layout[0].Ivar; Ix++;
           curIvar = data().IvarList;
         }
-        for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++)
+        for ( ; Ix != EIx; curIvar = layout[Ix].Ivar, Ix++) {
+          assert(curIvar && "instance variable is NULL, stop iterating through layout");
           curIvar->setNextIvar(layout[Ix].Ivar);
+        }
       }
     }
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to