Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-04-26 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55103.
apelete added a comment.

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

Chnages since last revision:

- lib/Format/Format.cpp: removed all changes, redenderd obsolete by upstream.


http://reviews.llvm.org/D19385

Files:
  lib/AST/DeclObjC.cpp
  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::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, 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/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);
+}
   }
 }
   }


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::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 @@
   bo

Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-04-27 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55327.
apelete added a comment.

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

Changes since last revision:

- lib/Format/AffectedRangeManager.cpp: moved the fixes from 
lib/Format/Format.cpp:AffectedRangeManager::nonPPLineAffected() here since the 
code appaears to have been moved.


http://reviews.llvm.org/D19385

Files:
  lib/AST/DeclObjC.cpp
  lib/Format/AffectedRangeManager.cpp
  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::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, 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.cpp
===
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -100,12 +100,15 @@
 
 bool AffectedRangeManager::nonPPLineAffected(
 AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+  assert(Line && "does not contain any line");
+
   bool SomeLineAffected = false;
   Line->ChildrenAffected =
   computeAffectedLines(Line->Children.begin(), Line->Children.end());
   if (Line->ChildrenAffected)
 SomeLineAffected = true;
 
+  assert(Line->First && "does not have a first token");
   // 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
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 = layou

Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-04-28 Thread Apelete Seketeli via cfe-commits
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::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, 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 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;
- 

Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-04-28 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55487.
apelete marked 3 inline comments as done.
apelete added a comment.

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

Changes since last revision:

- lib/Format/AffectedRangeManager.cpp: fix the call to 
AffectedRangeManager::nonPPLineAffected() from 
AffectedRangeManager::computeAffectedLines() that was left out of previous 
revision somehow.


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::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, 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 Ranges;
Index: lib/Format/AffectedRangeManager.cpp
===
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -48,7 +48,7 @@
   continue;
 }
 
-if (nonPPLineAffected(Line, PreviousLine))
+if (nonPPLineAffected(*Line, PreviousLine))
   SomeLineAffected = true;
 
 PreviousLine = Line;
@@ -98,25 +98,28 @@
   }
 }
 
-bool AffectedRangeManager::nonPPLineA

Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-04-28 Thread Apelete Seketeli via cfe-commits
apelete added a comment.

Thanks for your reviews.


http://reviews.llvm.org/D19385



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19084: [clang-analyzer] fix warnings emitted on clang code base

2016-05-01 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55746.
apelete added a comment.

[clang-analyzer] fix warnings emitted on clang code base

Changes since last revision:

- fast forward rebase on git master branch.


http://reviews.llvm.org/D19084

Files:
  lib/AST/ASTDiagnostic.cpp
  lib/AST/NestedNameSpecifier.cpp
  lib/Driver/Tools.cpp
  lib/Sema/SemaInit.cpp

Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4862,6 +4862,8 @@
InitializationSequence &Sequence,
const InitializedEntity &Entity,
Expr *Initializer) {
+  assert(Initializer && "Initializer needs to be not NULL");
+
   bool ArrayDecay = false;
   QualType ArgType = Initializer->getType();
   QualType ArgPointee;
@@ -5237,11 +5239,11 @@
 DeclAccessPair dap;
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
+} else if (Initializer && Initializer->getType() == Context.OverloadTy &&
!S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
  false, dap))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
-else if (Initializer->getType()->isFunctionType() &&
+else if (Initializer && Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
   SetFailed(InitializationSequence::FK_AddressOfUnaddressableFunction);
 else
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2346,7 +2346,7 @@
 success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
   Args, Features);
 
-  if (!success)
+  if (!success && A)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 
   if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -456,7 +456,9 @@
   Buffer = NewBuffer;
   BufferCapacity = NewCapacity;
 }
-
+
+assert(Buffer && "Buffer cannot be NULL");
+
 memcpy(Buffer + BufferSize, Start, End - Start);
 BufferSize += End-Start;
   }
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -1683,7 +1683,7 @@
   ToName = ToTD->getQualifiedNameAsString();
 }
 
-if (Same) {
+if (Same && FromTD) {
   OS << "template " << FromTD->getNameAsString();
 } else if (!PrintTree) {
   OS << (FromDefault ? "(default) template " : "template ");


Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4862,6 +4862,8 @@
InitializationSequence &Sequence,
const InitializedEntity &Entity,
Expr *Initializer) {
+  assert(Initializer && "Initializer needs to be not NULL");
+
   bool ArrayDecay = false;
   QualType ArgType = Initializer->getType();
   QualType ArgPointee;
@@ -5237,11 +5239,11 @@
 DeclAccessPair dap;
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
+} else if (Initializer && Initializer->getType() == Context.OverloadTy &&
!S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
  false, dap))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
-else if (Initializer->getType()->isFunctionType() &&
+else if (Initializer && Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
   SetFailed(InitializationSequence::FK_AddressOfUnaddressableFunction);
 else
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2346,7 +2346,7 @@
 success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
   Args, Features);
 
-  if (!success)
+  if (!success && A)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 
   if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/

Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-05-01 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55747.
apelete added a comment.

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

Changes since last revision:

- fast forward rebase on git master branch.


http://reviews.llvm.org/D19278

Files:
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp

Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -8705,6 +8705,7 @@
 
 void Sema::diagnoseEquivalentInternalLinkageDeclarations(
 SourceLocation Loc, const NamedDecl *D, ArrayRef Equiv) {
+  assert(D && "named declaration must be not NULL");
   Diag(Loc, diag::ext_equivalent_internal_linkage_decl_in_modules) << D;
 
   Module *M = getOwningModule(const_cast(D));
@@ -9185,7 +9186,9 @@
 !ToRefTy->getPointeeType()->isIncompleteType() &&
 S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) {
   BaseToDerivedConversion = 3;
-} else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
+} else if (FromExpr &&
+   !FromExpr->isLValue() &&
+   ToTy->isLValueReferenceType() &&
ToTy.getNonReferenceType().getCanonicalType() ==
FromTy.getNonReferenceType().getCanonicalType()) {
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue)
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -985,6 +985,7 @@
 (VD && DSAStack->isForceVarCapturing()))
   return VD ? VD : Info.second;
 auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
+assert(DVarPrivate.PrivateCopy && "DSAStackTy object must be not NULL");
 if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
   return VD ? VD : cast(DVarPrivate.PrivateCopy->getDecl());
 DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(),
@@ -3994,6 +3995,7 @@
 static ExprResult
 tryBuildCapture(Sema &SemaRef, Expr *Capture,
 llvm::MapVector &Captures) {
+  assert(Capture && "cannot build capture if expression is NULL");
   if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
 return SemaRef.PerformImplicitConversion(
 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
@@ -4251,7 +4253,7 @@
 SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 0 << CollapseLoopCountExpr->getSourceRange();
-  else
+  else if (OrderedLoopCountExpr)
 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 1 << OrderedLoopCountExpr->getSourceRange();
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -434,6 +434,9 @@
 /// error, false otherwise.
 bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
 Scope *S) {
+  assert(New && "New function declaration is NULL, aborting merge.");
+  assert(Old && "Old function declaration is NULL, aborting merge.");
+
   bool Invalid = false;
 
   // The declaration context corresponding to the scope is the semantic
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2299,6 +2299,7 @@
 
 unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
  unsigned AddrSpace) {
+  assert(D && "variable declaration must be not NULL");
   if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
 if (D->hasAttr())
   AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -1314,6 +1314,7 @@
 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
   }
+  assert(V && "consta

Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-05-01 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55748.
apelete added a comment.

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

Changes since last revision:

- fast forward rebase on git master branch.


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::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, 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);
 
   const SourceManager &SourceMgr;
Index: lib/Format/AffectedRangeManager.cpp
===
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -48,7 +48,7 @@
   continue;
 }
 
-if (nonPPLineAffected(Line, PreviousLine))
+if (nonPPLineAffected(*Line, PreviousLine))
   SomeLineAffected = true;
 
 PreviousLine = Line;
@@ -98,25 +98,28 @@
   }
 }
 
-bool AffectedRangeManager::nonPPLineAffected(
-AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+bool AffectedRangeMLanager::nonPPLineAffected(
+AnnotatedLine &Line, const AnnotatedLine *PreviousLine) {
   bool SomeLineAffected = false;

Re: [PATCH] D19084: [clang-analyzer] fix warnings emitted on clang code base

2016-05-01 Thread Apelete Seketeli via cfe-commits
apelete added a reviewer: rjmccall.
apelete added a comment.

Waiting for review, could someone please have a look at this one ?


http://reviews.llvm.org/D19084



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-05-01 Thread Apelete Seketeli via cfe-commits
apelete added a reviewer: pcc.
apelete added a comment.

Waiting for review, could someone please have a look at this one ?


http://reviews.llvm.org/D19278



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-05-01 Thread Apelete Seketeli via cfe-commits
apelete added a comment.

Waiting for review, could someone please have a look at this one ?


http://reviews.llvm.org/D19385



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-05-01 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55757.
apelete added a comment.

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

Changes since last revision:

- lib/Format/AffectedRangeManager.cpp: fix typo in class name.


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::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, 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);
 
   const SourceManager &SourceMgr;
Index: lib/Format/AffectedRangeManager.cpp
===
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -48,7 +48,7 @@
   continue;
 }
 
-if (nonPPLineAffected(Line, PreviousLine))
+if (nonPPLineAffected(*Line, PreviousLine))
   SomeLineAffected = true;
 
 PreviousLine = Line;
@@ -99,24 +99,27 @@
 }
 
 bool AffectedRangeManager::nonPPLineAffected(
-AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+AnnotatedLine &Line, const AnnotatedLine *PreviousLine) {
   bool SomeLineAffected = false;
-  Line->ChildrenAffected =
- 

[PATCH] D19829: [scan-build] fix dead store warnings emitted on clang code base

2016-05-02 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added reviewers: rjmccall, rtrieu, rsmith.
apelete added a subscriber: cfe-commits.

This fixes dead store warnings of the type "dead assignment" reported
by CLang Static Analyzer on the following files:

- lib/Sema/SemaDeclCXX.cpp,
- lib/Sema/SemaExpr.cpp,
- lib/Sema/SemaLookup.cpp,
- lib/Sema/SemaTemplate.cpp.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19829

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaLookup.cpp
  lib/Sema/SemaTemplate.cpp

Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -6243,8 +6243,6 @@
 SourceRange(TemplateParams->getTemplateLoc(),
 TemplateParams->getRAngleLoc()))
 << SourceRange(LAngleLoc, RAngleLoc);
-else
-  isExplicitSpecialization = true;
   } else {
 assert(TUK == TUK_Friend && "should have a 'template<>' for this decl");
   }
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -4907,12 +4907,6 @@
  bool NeedDefinition, bool Recover) {
   assert(!isVisible(Decl) && "missing import for non-hidden decl?");
 
-  // Suggest importing a module providing the definition of this entity, if
-  // possible.
-  NamedDecl *Def = getDefinitionToImport(Decl);
-  if (!Def)
-Def = Decl;
-
   // FIXME: Add a Fix-It that imports the corresponding module or includes
   // the header.
   Module *Owner = getOwningModule(Decl);
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9634,6 +9634,7 @@
   while (true) {
 IsDereference = NextIsDereference;
 NextIsDereference = false;
+(void) NextIsDereference;
 
 E = E->IgnoreParenImpCasts();
 if (const MemberExpr *ME = dyn_cast(E)) {
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12396,6 +12396,7 @@
   Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
 << TypeWithKeyword::getTagTypeKindName(Kind) << Name;
   isExplicitSpecialization = true;
+  (void) isExplicitSpecialization;
 }
   }
 


Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -6243,8 +6243,6 @@
 SourceRange(TemplateParams->getTemplateLoc(),
 TemplateParams->getRAngleLoc()))
 << SourceRange(LAngleLoc, RAngleLoc);
-else
-  isExplicitSpecialization = true;
   } else {
 assert(TUK == TUK_Friend && "should have a 'template<>' for this decl");
   }
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -4907,12 +4907,6 @@
  bool NeedDefinition, bool Recover) {
   assert(!isVisible(Decl) && "missing import for non-hidden decl?");
 
-  // Suggest importing a module providing the definition of this entity, if
-  // possible.
-  NamedDecl *Def = getDefinitionToImport(Decl);
-  if (!Def)
-Def = Decl;
-
   // FIXME: Add a Fix-It that imports the corresponding module or includes
   // the header.
   Module *Owner = getOwningModule(Decl);
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9634,6 +9634,7 @@
   while (true) {
 IsDereference = NextIsDereference;
 NextIsDereference = false;
+(void) NextIsDereference;
 
 E = E->IgnoreParenImpCasts();
 if (const MemberExpr *ME = dyn_cast(E)) {
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12396,6 +12396,7 @@
   Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
 << TypeWithKeyword::getTagTypeKindName(Kind) << Name;
   isExplicitSpecialization = true;
+  (void) isExplicitSpecialization;
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19830: [scan-build] fix dead store warnings emitted on clang code base

2016-05-02 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added a reviewer: doug.gregor.
apelete added a subscriber: cfe-commits.

This fixes dead store warnings of the type "dead assignment" reported
by CLang Static Analyzer on the following files:

- lib/Lex/Lexer.cpp,
- lib/Lex/ModuleMap.cpp.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19830

Files:
  lib/Lex/Lexer.cpp
  lib/Lex/ModuleMap.cpp

Index: lib/Lex/ModuleMap.cpp
===
--- lib/Lex/ModuleMap.cpp
+++ lib/Lex/ModuleMap.cpp
@@ -2197,6 +2197,7 @@
 if (Framework) {
   Diags.Report(StarLoc, diag::err_mmap_inferred_framework_submodule);
   Framework = false;
+  (void) Framework;
 }
   } else if (Explicit) {
 Diags.Report(StarLoc, diag::err_mmap_explicit_inferred_framework);
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -672,6 +672,7 @@
   // directive or it was one that can't occur in the preamble at this
   // point. Roll back the current token to the location of the '#'.
   InPreprocessorDirective = false;
+  (void) InPreprocessorDirective;
   TheTok = HashTok;
 }
 


Index: lib/Lex/ModuleMap.cpp
===
--- lib/Lex/ModuleMap.cpp
+++ lib/Lex/ModuleMap.cpp
@@ -2197,6 +2197,7 @@
 if (Framework) {
   Diags.Report(StarLoc, diag::err_mmap_inferred_framework_submodule);
   Framework = false;
+  (void) Framework;
 }
   } else if (Explicit) {
 Diags.Report(StarLoc, diag::err_mmap_explicit_inferred_framework);
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -672,6 +672,7 @@
   // directive or it was one that can't occur in the preamble at this
   // point. Roll back the current token to the location of the '#'.
   InPreprocessorDirective = false;
+  (void) InPreprocessorDirective;
   TheTok = HashTok;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-02 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added a reviewer: akyrtzi.
apelete added a subscriber: cfe-commits.

This fixes dead store warnings of the type "dead assignment" reported
by CLang Static Analyzer on the following file:

- tools/c-index-test/c-index-test.c.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19831

Files:
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1436,6 +1436,7 @@
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
   Record = Parent = p;
+  (void) Record;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);


Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1436,6 +1436,7 @@
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
   Record = Parent = p;
+  (void) Record;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-02 Thread Apelete Seketeli via cfe-commits
apelete added a comment.

In http://reviews.llvm.org/D19831#419140, @dblaikie wrote:

> Any reason not to remove the story instead?


What do you mean by "remove the story" ?


http://reviews.llvm.org/D19831



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-02 Thread Apelete Seketeli via cfe-commits
apelete added a comment.

In http://reviews.llvm.org/D19831#419456, @dblaikie wrote:

> Sorry, I meant remove the /store/, if it's dead. The do/while loop
>  overwrites the store immediately, so just remove the assignment to Record?


Makes sense, I overlooked that. Will fix in next revision.


http://reviews.llvm.org/D19831



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-02 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 55952.
apelete added a comment.

[scan-build] fix dead store warnings emitted on clang code base

Changes since last revision:

- remove dead store since the do {} while() loop overwrite it immediatly anyway.


http://reviews.llvm.org/D19831

Files:
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1435,7 +1435,6 @@
 CXCursor Parent, Record;
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
-  Record = Parent = p;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);


Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1435,7 +1435,6 @@
 CXCursor Parent, Record;
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
-  Record = Parent = p;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-03 Thread Apelete Seketeli via cfe-commits
apelete added inline comments.


Comment at: tools/c-index-test/c-index-test.c:1440
@@ -1440,3 +1439,3 @@
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);
 RecordIsAnonymous = clang_Cursor_isAnonymous(Record);

This line now causes a new "uninitialized argument value" warning because 
Parent variable isn't initialized anymore and Record variable is being passed 
here without being initialized either consequently.

Will fix in next revision.


http://reviews.llvm.org/D19831



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-03 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 56042.
apelete added a comment.

[scan-build] fix dead store warnings emitted on clang code base

Changes since last revision:

- Initialize 'CXCursor Parent' variable to avoid passing 'Record' variable as 
an un-initialized argument thereafter.


http://reviews.llvm.org/D19831

Files:
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1432,10 +1432,10 @@
 CXString FieldSpelling = clang_getCursorSpelling(cursor);
 const char *FieldName = clang_getCString(FieldSpelling);
 /* recurse to get the first parent record that is not anonymous. */
-CXCursor Parent, Record;
+CXCursor Record;
+CXCursor Parent = p;
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
-  Record = Parent = p;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);


Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1432,10 +1432,10 @@
 CXString FieldSpelling = clang_getCursorSpelling(cursor);
 const char *FieldName = clang_getCString(FieldSpelling);
 /* recurse to get the first parent record that is not anonymous. */
-CXCursor Parent, Record;
+CXCursor Record;
+CXCursor Parent = p;
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
-  Record = Parent = p;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-03 Thread Apelete Seketeli via cfe-commits
apelete added a comment.

In http://reviews.llvm.org/D19831#420115, @dblaikie wrote:

> Looks good to me - go ahead & commit whenever you're ready.


If this last revision is good for you, please go ahead and commit this for me 
(I don't have commit access).

Thanks.


http://reviews.llvm.org/D19831



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-03 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 56059.
apelete added a comment.

[scan-build] fix dead store warnings emitted on clang code base

Changes since last revision:

- Move 'Record' and 'Parent' variables into if() {} scope where they are 
actually used.


http://reviews.llvm.org/D19831

Files:
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1432,10 +1432,10 @@
 CXString FieldSpelling = clang_getCursorSpelling(cursor);
 const char *FieldName = clang_getCString(FieldSpelling);
 /* recurse to get the first parent record that is not anonymous. */
-CXCursor Parent, Record;
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
-  Record = Parent = p;
+  CXCursor Record;
+  CXCursor Parent = p;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);


Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1432,10 +1432,10 @@
 CXString FieldSpelling = clang_getCursorSpelling(cursor);
 const char *FieldName = clang_getCString(FieldSpelling);
 /* recurse to get the first parent record that is not anonymous. */
-CXCursor Parent, Record;
 unsigned RecordIsAnonymous = 0;
 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
-  Record = Parent = p;
+  CXCursor Record;
+  CXCursor Parent = p;
   do {
 Record = Parent;
 Parent = clang_getCursorSemanticParent(Record);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19831: [scan-build] fix dead store warnings emitted on clang code base

2016-05-03 Thread Apelete Seketeli via cfe-commits
apelete added a comment.

In http://reviews.llvm.org/D19831#420410, @dblaikie wrote:

> Thanks - do you need someone (me) to commit this, or do you have commit
>  access?


I would appreciate if you could commit this for me since I don't have commit 
access.
Thanks.


http://reviews.llvm.org/D19831



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19084: [clang-analyzer] fix warnings emitted on clang code base

2016-05-05 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 56248.
apelete added a comment.

[scan-build] fix warnings emitted on Clang AST code base

Changes since last revision:

- split patch into AST changes unit to ease review process.


http://reviews.llvm.org/D19084

Files:
  lib/AST/ASTDiagnostic.cpp
  lib/AST/DeclObjC.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/NestedNameSpecifier.cpp

Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -456,7 +456,9 @@
   Buffer = NewBuffer;
   BufferCapacity = NewCapacity;
 }
-
+
+assert(Buffer && "Buffer cannot be NULL");
+
 memcpy(Buffer + BufferSize, Start, End - Start);
 BufferSize += End-Start;
   }
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -1989,6 +1989,7 @@
 static bool HandleLValueArrayAdjustment(EvalInfo &Info, const Expr *E,
 LValue &LVal, QualType EltTy,
 int64_t Adjustment) {
+  assert(E && "expression to be evaluated must be not NULL");
   CharUnits SizeOfPointee;
   if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfPointee))
 return false;
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);
+}
   }
 }
   }
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -1683,7 +1683,7 @@
   ToName = ToTD->getQualifiedNameAsString();
 }
 
-if (Same) {
+if (Same && FromTD) {
   OS << "template " << FromTD->getNameAsString();
 } else if (!PrintTree) {
   OS << (FromDefault ? "(default) template " : "template ");


Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -456,7 +456,9 @@
   Buffer = NewBuffer;
   BufferCapacity = NewCapacity;
 }
-
+
+assert(Buffer && "Buffer cannot be NULL");
+
 memcpy(Buffer + BufferSize, Start, End - Start);
 BufferSize += End-Start;
   }
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -1989,6 +1989,7 @@
 static bool HandleLValueArrayAdjustment(EvalInfo &Info, const Expr *E,
 LValue &LVal, QualType EltTy,
 int64_t Adjustment) {
+  assert(E && "expression to be evaluated must be not NULL");
   CharUnits SizeOfPointee;
   if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfPointee))
 return false;
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);
+}
   }
 }
   }
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -1683,7 +1683,7 @@
   ToName = ToTD->getQualifiedNameAsString();
 }
 
-if (Same) {
+if (Same && FromTD) {
   OS << "template " << FromTD->getNameAsString();
 } else if (!PrintTree) {
   OS << (FromDefault ? "(default) template " : "template ");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19959: [scan-build] fix warning emitted on Clang Driver code baseFix a "logic error" warning of the type Called c++ object pointer isnull" reported by Clang Static Analyzer on the file:- lib/

2016-05-05 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added reviewers: kevin.qin, rsmith.
apelete added a subscriber: cfe-commits.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19959

Files:
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2346,7 +2346,7 @@
 success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
   Args, Features);
 
-  if (!success)
+  if (!success && A)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 
   if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2346,7 +2346,7 @@
 success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
   Args, Features);
 
-  if (!success)
+  if (!success && A)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 
   if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-05-05 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 56253.
apelete added a comment.

[scan-build] fix warnings emitted on Clang Sema code base

Changes since last revision:

- split patch into Sema changes unit to ease review process,
- cherry-pick Sema changes from http://reviews.llvm.org/D19084,
- cherry-pick Sema changes from http://reviews.llvm.org/D19385.


http://reviews.llvm.org/D19278

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaLookup.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp

Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -8705,6 +8705,7 @@
 
 void Sema::diagnoseEquivalentInternalLinkageDeclarations(
 SourceLocation Loc, const NamedDecl *D, ArrayRef Equiv) {
+  assert(D && "named declaration must be not NULL");
   Diag(Loc, diag::ext_equivalent_internal_linkage_decl_in_modules) << D;
 
   Module *M = getOwningModule(const_cast(D));
@@ -9185,7 +9186,9 @@
 !ToRefTy->getPointeeType()->isIncompleteType() &&
 S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) {
   BaseToDerivedConversion = 3;
-} else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
+} else if (FromExpr &&
+   !FromExpr->isLValue() &&
+   ToTy->isLValueReferenceType() &&
ToTy.getNonReferenceType().getCanonicalType() ==
FromTy.getNonReferenceType().getCanonicalType()) {
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue)
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -985,6 +985,7 @@
 (VD && DSAStack->isForceVarCapturing()))
   return VD ? VD : Info.second;
 auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
+assert(DVarPrivate.PrivateCopy && "DSAStackTy object must be not NULL");
 if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
   return VD ? VD : cast(DVarPrivate.PrivateCopy->getDecl());
 DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(),
@@ -3994,6 +3995,7 @@
 static ExprResult
 tryBuildCapture(Sema &SemaRef, Expr *Capture,
 llvm::MapVector &Captures) {
+  assert(Capture && "cannot build capture if expression is NULL");
   if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
 return SemaRef.PerformImplicitConversion(
 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
@@ -4251,7 +4253,7 @@
 SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 0 << CollapseLoopCountExpr->getSourceRange();
-  else
+  else if (OrderedLoopCountExpr)
 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 1 << OrderedLoopCountExpr->getSourceRange();
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/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4862,6 +4862,8 @@
InitializationSequence &Sequence,
const InitializedEntity &Entity,
Expr *Initializer) {
+  assert(Initializer && "Initializer needs to be not NULL");
+
   bool ArrayDecay = false;
   QualType ArgType = Initializer->getType();
   QualType ArgPointee;
@@ -5237,11 +5239,11 @@
 DeclAccessPair dap;
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
+} else if (Initializer && Initializer->getType() == Context.OverloadTy &&
!S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
  false, dap))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
-else if (Initializer->getType()->isFunctionType() &&
+else if (Initializer && Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
   SetFailed(InitializationSequence::FK_AddressOfUnaddressableFunction);
 else
Index: lib/Sema/SemaExprCXX.cpp
==

[PATCH] D19960: [scan-build] fix warnings emitted on Clang CodeGen code base

2016-05-05 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added reviewers: dblaikie, pcc.
apelete added a subscriber: cfe-commits.

Fix "Logic error" warnings of the type "Called c++ object pointer is
null" reported by Clang Static Analyzer on the following files:

- lib/CodeGen/CGDebugInfo.cpp,
- lib/CodeGen/CodeGenModule.cpp.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19960

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2299,6 +2299,7 @@
 
 unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
  unsigned AddrSpace) {
+  assert(D && "variable declaration must be not NULL");
   if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
 if (D->hasAttr())
   AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -1314,6 +1314,7 @@
 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
   }
+  assert(V && "constant must be not NULL at this point");
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy,
   cast_or_null(V->stripPointerCasts(;


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2299,6 +2299,7 @@
 
 unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
  unsigned AddrSpace) {
+  assert(D && "variable declaration must be not NULL");
   if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
 if (D->hasAttr())
   AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -1314,6 +1314,7 @@
 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
   }
+  assert(V && "constant must be not NULL at this point");
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(
   TheCU, Name, TTy,
   cast_or_null(V->stripPointerCasts(;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19962: [scan-build] fix warnings emitted on Clang StaticAnalyzer code base

2016-05-05 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added a reviewer: zaks.anna.
apelete added a subscriber: cfe-commits.

This patch fixes a few "Logic error" warnings of the type "Called c++
object pointer is null" reported by Clang Static Analyzer on the
following files:

- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp,
- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19962

Files:
  lib/StaticAnalyzer/Checkers/NullabilityChecker.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::iterator DI = Diags.begin(),
DE = Diags.end(); DI != DE; ++DI) {
Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =


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::iterator DI = Diags.begin(),
DE = Diags.end(); DI != DE; ++DI) {
Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-05-05 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 56259.
apelete added a comment.

[scan-build] fix warnings emitted on Clang Format code base

Changes since last revision:

- split patch into Format unit to ease review process.


http://reviews.llvm.org/D19385

Files:
  lib/Format/AffectedRangeManager.cpp
  lib/Format/AffectedRangeManager.h

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);
 
   const SourceManager &SourceMgr;
Index: lib/Format/AffectedRangeManager.cpp
===
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -48,7 +48,7 @@
   continue;
 }
 
-if (nonPPLineAffected(Line, PreviousLine))
+if (nonPPLineAffected(*Line, PreviousLine))
   SomeLineAffected = true;
 
 PreviousLine = Line;
@@ -99,24 +99,27 @@
 }
 
 bool AffectedRangeManager::nonPPLineAffected(
-AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+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/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);
 
   const SourceManager &SourceMgr;
Index: lib/Format/AffectedRangeManager.cpp
===
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -48,7 +48,7 @@
   continue;
 }
 
-if (nonPPLineAffected(Line, PreviousLine))
+if (nonPPLineAffected(*Line, PreviousLine))
   SomeLineAffected = true;
 
 PreviousLine = Line;
@@ -99,24 +99,27 @@
 }
 
 bool AffectedRangeManager::nonPPLineAffected(
-AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+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 o

[PATCH] D19963: [scan-build] fix warnings emitted on Clang Frontend code baseFix "Logic error" warnings of the type "Called C++ object pointer isnull" reported by Clang Static Analyzer on the followin

2016-05-05 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added reviewers: akyrtzi, rsmith.
apelete added a subscriber: cfe-commits.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19963

Files:
  lib/Frontend/CompilerInstance.cpp

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, 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/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, 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();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19960: [scan-build] fix warnings emitted on Clang CodeGen code base

2016-05-09 Thread Apelete Seketeli via cfe-commits
apelete added inline comments.


Comment at: lib/CodeGen/CGDebugInfo.cpp:1317
@@ -1316,2 +1316,3 @@
   }
+  assert(V && "constant must be not NULL at this point");
   TemplateParams.push_back(DBuilder.createTemplateValueParameter(

dblaikie wrote:
> It looks like this assertion could actually be a different assertion a little 
> higher up.
> 
> For 'V' to be non-null, one of the if/else if chain above must fire.
> 
> So change the last else if to an else, and the dyn_cast to a cast, and the 
> cast will fail an internal assertion if it's not valid (& the analyzer can 
> easily then see that at least one of the assignments to V happens - whether 
> or not the analyzer assumes that all the initializers of V are non-null, 
> that's a separate issue...)
I do not understand what you are suggesting here.
Are you suggesting I should try those changes and see for myself that at least 
one of the assignments to V actually happens (which would mean that the warning 
is a false positive), or are you suggesting that the right way to fix it is to 
remove the assert and replace the last 'else if' construct with an 'else' ?


Comment at: lib/CodeGen/CodeGenModule.cpp:2302
@@ -2301,2 +2301,3 @@
  unsigned AddrSpace) {
+  assert(D && "variable declaration must be not NULL");
   if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {

dblaikie wrote:
> Again, a bit confused about whether you're proposing fixing nearly every 
> pointer parameter in Clang and LLVM to assert non-null... I think we'd need a 
> discussion about what that looks like.
Sorry my intentions were not clear.
The only function pointer parameters I'm asserting are the ones that trigger a 
warning when running scan-build.
This might not be the right way to fix the issue, I will be waiting for you 
advice in that case (please have a look at my reply to your concern on the 
mailing list).


http://reviews.llvm.org/D19960



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19962: [scan-build] fix warnings emitted on Clang StaticAnalyzer code base

2016-05-09 Thread Apelete Seketeli via cfe-commits
apelete added inline comments.


Comment at: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp:300
@@ -299,2 +299,3 @@
 
+  assert(SM && "SourceManager is NULL, cannot iterate through the 
diagnostics");
 

dblaikie wrote:
> This assertion seems to be equivalent to replacing the prior 'if' with an 
> assertion of the same condition, no? Is that correct? (& if it is, we should 
> just do that)
You're right, I overlooked the simplification.
Will fix in next revision.


http://reviews.llvm.org/D19962



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19962: [scan-build] fix warnings emitted on Clang StaticAnalyzer code base

2016-05-09 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 56556.
apelete added a comment.

[scan-build] fix warnings emitted on Clang StaticAnalyzer code base

- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp: factorize assert and check on 
'!Diags.empty' condition.


http://reviews.llvm.org/D19962

Files:
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -294,9 +294,8 @@
   SmallVector Fids;
   const SourceManager* SM = nullptr;
 
-  if (!Diags.empty())
-SM = &Diags.front()->path.front()->getLocation().getManager();
-
+  assert(!Diags.empty() && "cannot iterate through empty PathDiagnostic");
+  SM = &Diags.front()->path.front()->getLocation().getManager();
 
   for (std::vector::iterator DI = Diags.begin(),
DE = Diags.end(); DI != DE; ++DI) {
Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =


Index: lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
===
--- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -294,9 +294,8 @@
   SmallVector Fids;
   const SourceManager* SM = nullptr;
 
-  if (!Diags.empty())
-SM = &Diags.front()->path.front()->getLocation().getManager();
-
+  assert(!Diags.empty() && "cannot iterate through empty PathDiagnostic");
+  SM = &Diags.front()->path.front()->getLocation().getManager();
 
   for (std::vector::iterator DI = Diags.begin(),
DE = Diags.end(); DI != DE; ++DI) {
Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19084: [scan-build] fix warnings emitted on Clang AST code base

2016-05-12 Thread Apelete Seketeli via cfe-commits
apelete added inline comments.


Comment at: lib/AST/ASTDiagnostic.cpp:1686
@@ -1685,3 +1685,3 @@
 
-if (Same) {
+if (Same && FromTD) {
   OS << "template " << FromTD->getNameAsString();

rtrieu wrote:
> dblaikie wrote:
> > Should this be a condition, or just an assertion?
> This should be an assertion.  Same == true implies FromTD and ToTD are not 
> null.
What do you mean by "This should be an assertion" ?
There's already an assertion on FromTD and ToTD values at the beginning of 
PrintTemplateTemplate() so duplicating it here didn't make sense to me: should 
I replace the if() with an assertion anyway ?


Comment at: lib/AST/ExprConstant.cpp:1992
@@ -1991,2 +1991,3 @@
 int64_t Adjustment) {
+  assert(E && "expression to be evaluated must be not NULL");
   CharUnits SizeOfPointee;

dblaikie wrote:
> Does the static analyzer assume any pointer parameter may be null? (I didn't 
> think it did that - I thought it only assumed it could be null if there was a 
> null test somewhere in the function?) That seems a bit too pessimistic in 
> most codebases, especially LLVM - we pass a lot of non-null pointers around.
Not all pointer parameters trigger a warning during static analysis of Clang 
codebase, but for the ones that do the reason isn't always clear to me (I'm 
probably missing some background on static analysis here).

Let me know if you think the warning here should be ignored.


Comment at: lib/AST/NestedNameSpecifier.cpp:460
@@ +459,3 @@
+
+assert(Buffer && "Buffer cannot be NULL");
+

dblaikie wrote:
> Again, is this assuming that the Buffer parameter may be null? That seems 
> unlikely to be useful in the LLVM codebase where we have lots of guaranteed 
> non-null pointers floating around (I'm surprised this wouldn't cause tons of 
> analyzer warnings, so presumably it's something more subtle?)
Code path proposed by the analyzer is the following:

484. NestedNameSpecifierLocBuilder::
485. NestedNameSpecifierLocBuilder(const NestedNameSpecifierLocBuilder &Other) 
486.   : Representation(Other.Representation), Buffer(nullptr),
487. BufferSize(0), BufferCapacity(0)
488. {
...
500.   Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
501. BufferCapacity);
502. }
The constructor is called on line 484 and it initalizes Buffer to nullptr, 
BufferSIze to 0 and BufferCapacity to 0 as shown above.
Then, after evaluating all branches in the constructor body to false, it calls 
Append() with the parameters previously initialized:

441.   void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize,
442 unsigned &BufferCapacity) {
443. if (Start == End)
444.   return;
445.
446. if (BufferSize + (End - Start) > BufferCapacity) {
...
458. }
459.
460. memcpy(Buffer + BufferSize, Start, End - Start);

At this point, after evaluating the branches at lines 443 and 446 to false, the 
analyzer concludes that 'Buffer + BufferSize' is a "Null pointer passed as an 
argument to a 'nonnull' parameter", hence the assert I proposed just before 
this line.

It turns out that this suggested codepath is indeed unlikely because either:
- Buffer parameter is null and so is BufferCapacity when Append() is called, in 
which case branch at line 446 is unlikely to evaluate to false, or
- Buffer parameter is initialized to a non-null value in the constructor at 
line 494 and is passed as a non-null parameter when Append() is called.

I chose however to trust the tool and prevent unforseen conditions to lead to 
that path by asserting Buffer value.

Let me know if you think the warning here should be ignored.


http://reviews.llvm.org/D19084



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19829: [scan-build] fix dead store warnings emitted on clang code base

2016-05-17 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 57560.
apelete added a comment.

[scan-build] fix dead store warnings emitted on clang code base

Changes since last revision:

- lib/Sema/SemaLookup.cpp: remove changes since they were already applied 
upstream,
- lib/Sema/SemaExpr.cpp: move 'IsDereference' and 'NextIsDereference' variables 
into the code block where they are used.


http://reviews.llvm.org/D19829

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaTemplate.cpp

Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -6248,8 +6248,6 @@
 SourceRange(TemplateParams->getTemplateLoc(),
 TemplateParams->getRAngleLoc()))
 << SourceRange(LAngleLoc, RAngleLoc);
-else
-  isExplicitSpecialization = true;
   } else {
 assert(TUK == TUK_Friend && "should have a 'template<>' for this decl");
   }
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9692,16 +9692,16 @@
 
   // Track if the current expression is the result of a derefence, and if the
   // next checked expression is the result of a derefence.
+  // These variables are only updated when processing MemberExpr
+  // chains in the loop below.
   bool IsDereference = false;
   bool NextIsDereference = false;
 
   // Loop to process MemberExpr chains.
   while (true) {
-IsDereference = NextIsDereference;
-NextIsDereference = false;
-
 E = E->IgnoreParenImpCasts();
 if (const MemberExpr *ME = dyn_cast(E)) {
+  IsDereference = NextIsDereference;
   NextIsDereference = ME->isArrow();
   const ValueDecl *VD = ME->getMemberDecl();
   if (const FieldDecl *Field = dyn_cast(VD)) {
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12470,6 +12470,7 @@
   Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
 << TypeWithKeyword::getTagTypeKindName(Kind) << Name;
   isExplicitSpecialization = true;
+  (void) isExplicitSpecialization;
 }
   }
 


Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -6248,8 +6248,6 @@
 SourceRange(TemplateParams->getTemplateLoc(),
 TemplateParams->getRAngleLoc()))
 << SourceRange(LAngleLoc, RAngleLoc);
-else
-  isExplicitSpecialization = true;
   } else {
 assert(TUK == TUK_Friend && "should have a 'template<>' for this decl");
   }
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -9692,16 +9692,16 @@
 
   // Track if the current expression is the result of a derefence, and if the
   // next checked expression is the result of a derefence.
+  // These variables are only updated when processing MemberExpr
+  // chains in the loop below.
   bool IsDereference = false;
   bool NextIsDereference = false;
 
   // Loop to process MemberExpr chains.
   while (true) {
-IsDereference = NextIsDereference;
-NextIsDereference = false;
-
 E = E->IgnoreParenImpCasts();
 if (const MemberExpr *ME = dyn_cast(E)) {
+  IsDereference = NextIsDereference;
   NextIsDereference = ME->isArrow();
   const ValueDecl *VD = ME->getMemberDecl();
   if (const FieldDecl *Field = dyn_cast(VD)) {
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12470,6 +12470,7 @@
   Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
 << TypeWithKeyword::getTagTypeKindName(Kind) << Name;
   isExplicitSpecialization = true;
+  (void) isExplicitSpecialization;
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19084: [scan-build] fix warnings emitted on Clang AST code base

2016-05-18 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 57571.
apelete retitled this revision from "[scan-build] fix warnings emitted on Clang 
AST code base " to "[scan-build] fix warnings emitted on Clang AST code base".
apelete added a comment.

[scan-build] fix warnings emitted on Clang AST code base

Changes since last revision:

- lib/AST/ASTDiagnostic.cpp: replace if() condition by assert to ensure that 
template diffing print message is done only when both 'FromTD' and 'ToTD' are 
non-null.


http://reviews.llvm.org/D19084

Files:
  lib/AST/ASTDiagnostic.cpp
  lib/AST/DeclObjC.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/NestedNameSpecifier.cpp

Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -456,7 +456,9 @@
   Buffer = NewBuffer;
   BufferCapacity = NewCapacity;
 }
-
+
+assert(Buffer && "Buffer cannot be NULL");
+
 memcpy(Buffer + BufferSize, Start, End - Start);
 BufferSize += End-Start;
   }
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -1989,6 +1989,7 @@
 static bool HandleLValueArrayAdjustment(EvalInfo &Info, const Expr *E,
 LValue &LVal, QualType EltTy,
 int64_t Adjustment) {
+  assert(E && "expression to be evaluated must be not NULL");
   CharUnits SizeOfPointee;
   if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfPointee))
 return false;
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);
+}
   }
 }
   }
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -1684,6 +1684,8 @@
 }
 
 if (Same) {
+  assert((FromTD && ToTD) &&
+ "Same implies both template arguments are non-null.");
   OS << "template " << FromTD->getNameAsString();
 } else if (!PrintTree) {
   OS << (FromDefault ? "(default) template " : "template ");


Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -456,7 +456,9 @@
   Buffer = NewBuffer;
   BufferCapacity = NewCapacity;
 }
-
+
+assert(Buffer && "Buffer cannot be NULL");
+
 memcpy(Buffer + BufferSize, Start, End - Start);
 BufferSize += End-Start;
   }
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -1989,6 +1989,7 @@
 static bool HandleLValueArrayAdjustment(EvalInfo &Info, const Expr *E,
 LValue &LVal, QualType EltTy,
 int64_t Adjustment) {
+  assert(E && "expression to be evaluated must be not NULL");
   CharUnits SizeOfPointee;
   if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfPointee))
 return false;
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);
+}
   }
 }
   }
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -1684,6 +1684,8 @@
 }
 
 if (Same) {
+  assert((FromTD && ToTD) &&
+ "Same implies both template arguments are non-null.");
   OS << "template " << FromTD->getNameAsString();
 } else if (!PrintTree) {
   OS << (FromDefault ? "(default) template " : "template ");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[scan-build] Fix reported logic error and api bugs

2016-04-03 Thread Apelete Seketeli via cfe-commits
Hello,

Here are a few changes that try to address some logic error bugs
reported by running scan-build over the Clang code base.

I have no background in compiler technology and I may have been trying
to fix false positives; here is a quick overview of what scan-build
reported, let me know if the fixes are relevant:

Bug Group: Logic error
Bug Type: Called C++ object pointer is null
Files: lib/Driver/Tools.cpp

Bug Group: Logic error
Bug Type: Called C++ object pointer is null
Files: lib/Sema/SemaInit.cpp

Bug Group: API
Bug Type: Argument with 'nonnull' attribute passed null
Files: lib/AST/NestedNameSpecifier.cpp

Cheers.
-- 
Apelete
diff --git a/lib/AST/NestedNameSpecifier.cpp b/lib/AST/NestedNameSpecifier.cpp
index ede3862..a3b1076 100644
--- a/lib/AST/NestedNameSpecifier.cpp
+++ b/lib/AST/NestedNameSpecifier.cpp
@@ -456,9 +456,11 @@ namespace {
   Buffer = NewBuffer;
   BufferCapacity = NewCapacity;
 }
-
-memcpy(Buffer + BufferSize, Start, End - Start);
-BufferSize += End-Start;
+
+if (Buffer) {
+  memcpy(Buffer + BufferSize, Start, End - Start);
+  BufferSize += End-Start;
+}
   }
   
   /// \brief Save a source location to the given buffer.
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 824ee72..2ac5416 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2334,7 +2334,7 @@ static void getAArch64TargetFeatures(const Driver &D, const ArgList &Args,
 success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
   Args, Features);
 
-  if (!success)
+  if (!success && A)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 
   if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index bd8522d..dc4e967 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -4860,6 +4860,8 @@ static bool tryObjCWritebackConversion(Sema &S,
InitializationSequence &Sequence,
const InitializedEntity &Entity,
Expr *Initializer) {
+  assert(Initializer && "Initializer needs to be not NULL");
+
   bool ArrayDecay = false;
   QualType ArgType = Initializer->getType();
   QualType ArgPointee;
@@ -5235,11 +5237,11 @@ void InitializationSequence::InitializeFrom(Sema &S,
 DeclAccessPair dap;
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
+} else if (Initializer && Initializer->getType() == Context.OverloadTy &&
!S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
  false, dap))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
-else if (Initializer->getType()->isFunctionType() &&
+else if (Initializer && Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
   SetFailed(InitializationSequence::FK_AddressOfUnaddressableFunction);
 else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D19084: [clang-analyzer] fix warnings emitted on clang code base

2016-04-13 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added a subscriber: cfe-commits.

The following warnings were reported while running clang analyzer on Clang code 
base:

API: argument with 'nonnull' attribute passed null, on file:
- lib/AST/NestedNameSpecifier.cpp.

Logic error: called C++ object pointer is null, on files:
- lib/Sema/SemaInit.cpp,
- lib/Driver/Tools.cpp,
- lib/AST/ASTDiagnostic.cpp.

Fixes T123 (please note that first revision was sent only to
cfe-commits mailing list, not reviewed yet).

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19084

Files:
  lib/AST/ASTDiagnostic.cpp
  lib/AST/NestedNameSpecifier.cpp
  lib/Driver/Tools.cpp
  lib/Sema/SemaInit.cpp

Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4862,6 +4862,8 @@
InitializationSequence &Sequence,
const InitializedEntity &Entity,
Expr *Initializer) {
+  assert(Initializer && "Initializer needs to be not NULL");
+
   bool ArrayDecay = false;
   QualType ArgType = Initializer->getType();
   QualType ArgPointee;
@@ -5237,11 +5239,11 @@
 DeclAccessPair dap;
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
+} else if (Initializer && Initializer->getType() == Context.OverloadTy &&
!S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
  false, dap))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
-else if (Initializer->getType()->isFunctionType() &&
+else if (Initializer && Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
   SetFailed(InitializationSequence::FK_AddressOfUnaddressableFunction);
 else
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2339,7 +2339,7 @@
 success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
   Args, Features);
 
-  if (!success)
+  if (!success && A)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 
   if (Args.getLastArg(options::OPT_mgeneral_regs_only)) {
Index: lib/AST/NestedNameSpecifier.cpp
===
--- lib/AST/NestedNameSpecifier.cpp
+++ lib/AST/NestedNameSpecifier.cpp
@@ -456,7 +456,9 @@
   Buffer = NewBuffer;
   BufferCapacity = NewCapacity;
 }
-
+
+assert(Buffer && "Buffer cannot be NULL");
+
 memcpy(Buffer + BufferSize, Start, End - Start);
 BufferSize += End-Start;
   }
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -1683,7 +1683,7 @@
   ToName = ToTD->getQualifiedNameAsString();
 }
 
-if (Same) {
+if (Same && FromTD) {
   OS << "template " << FromTD->getNameAsString();
 } else if (!PrintTree) {
   OS << (FromDefault ? "(default) template " : "template ");


Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4862,6 +4862,8 @@
InitializationSequence &Sequence,
const InitializedEntity &Entity,
Expr *Initializer) {
+  assert(Initializer && "Initializer needs to be not NULL");
+
   bool ArrayDecay = false;
   QualType ArgType = Initializer->getType();
   QualType ArgPointee;
@@ -5237,11 +5239,11 @@
 DeclAccessPair dap;
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
+} else if (Initializer && Initializer->getType() == Context.OverloadTy &&
!S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
  false, dap))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
-else if (Initializer->getType()->isFunctionType() &&
+else if (Initializer && Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
   SetFailed(InitializationSequence::FK_AddressOfUnaddressableFunction);
 else
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2339,7 +2339,7 @@
 success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),

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

2016-04-19 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added a subscriber: cfe-commits.

This partch fixes a few "Logic error" warnings of the type "Called c++
object pointer is null" reported by Clang Static Analyzer on the
following files:

- lib/AST/ExprConstant.cpp,
- lib/CodeGen/CGDebugInfo.cpp,
- lib/CodeGen/CodeGenModule.cpp,
- lib/Sema/SemaDeclCXX.cpp,
- lib/Sema/SemaOpenMP.cpp,
- lib/Sema/SemaOverload.cpp,
- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19278

Files:
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp

Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -8721,6 +8721,7 @@
 
 void Sema::diagnoseEquivalentInternalLinkageDeclarations(
 SourceLocation Loc, const NamedDecl *D, ArrayRef Equiv) {
+  assert(D && "named declaration must be not NULL");
   Diag(Loc, diag::ext_equivalent_internal_linkage_decl_in_modules) << D;
 
   Module *M = getOwningModule(const_cast(D));
@@ -9201,7 +9202,9 @@
 !ToRefTy->getPointeeType()->isIncompleteType() &&
 S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) {
   BaseToDerivedConversion = 3;
-} else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
+} else if (FromExpr &&
+   ToTy->isLValueReferenceType() &&
+   !FromExpr->isLValue() &&
ToTy.getNonReferenceType().getCanonicalType() ==
FromTy.getNonReferenceType().getCanonicalType()) {
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue)
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -939,6 +939,7 @@
 (VD && DSAStack->isForceVarCapturing()))
   return VD ? VD : Info.second;
 auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
+assert(DVarPrivate.PrivateCopy && "DSAStackTy object must be not NULL");
 if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
   return VD ? VD : cast(DVarPrivate.PrivateCopy->getDecl());
 DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(),
@@ -3924,6 +3925,7 @@
 static ExprResult
 tryBuildCapture(Sema &SemaRef, Expr *Capture,
 llvm::MapVector &Captures) {
+  assert(Capture && "cannot build capture if expression is NULL");
   if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
 return SemaRef.PerformImplicitConversion(
 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
@@ -4177,7 +4179,7 @@
 SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 0 << CollapseLoopCountExpr->getSourceRange();
-  else
+  else if (OrderedLoopCountExpr)
 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 1 << OrderedLoopCountExpr->getSourceRange();
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -434,6 +434,9 @@
 /// error, false otherwise.
 bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
 Scope *S) {
+  assert(New && "New function decalration is NULL, aborting merge.");
+  assert(Old && "Old function decalration is NULL, aborting merge.");
+
   bool Invalid = false;
 
   // The declaration context corresponding to the scope is the semantic
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2303,6 +2303,7 @@
 
 unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
  unsigned AddrSpace) {
+  assert(D && "variable declaration must be not NULL");
   if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
 if (D->hasAttr())
   AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
Index: lib/CodeGen/CGDebugInfo.cpp
===

Re: [PATCH] D19084: [clang-analyzer] fix warnings emitted on clang code base

2016-04-19 Thread Apelete Seketeli via cfe-commits
apelete added a comment.

Ping :).
Can someone help this one find its way into he main repo ?


http://reviews.llvm.org/D19084



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-04-19 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 54246.
apelete added a comment.

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

Following changes were done since last revision:

- fix a typo in lib/Sema/SemaDeclCXX.cpp: decalration ==> declaration.


http://reviews.llvm.org/D19278

Files:
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp

Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -8705,6 +8705,7 @@
 
 void Sema::diagnoseEquivalentInternalLinkageDeclarations(
 SourceLocation Loc, const NamedDecl *D, ArrayRef Equiv) {
+  assert(D && "named declaration must be not NULL");
   Diag(Loc, diag::ext_equivalent_internal_linkage_decl_in_modules) << D;
 
   Module *M = getOwningModule(const_cast(D));
@@ -9185,7 +9186,9 @@
 !ToRefTy->getPointeeType()->isIncompleteType() &&
 S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) {
   BaseToDerivedConversion = 3;
-} else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
+} else if (FromExpr &&
+   ToTy->isLValueReferenceType() &&
+   !FromExpr->isLValue() &&
ToTy.getNonReferenceType().getCanonicalType() ==
FromTy.getNonReferenceType().getCanonicalType()) {
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue)
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -939,6 +939,7 @@
 (VD && DSAStack->isForceVarCapturing()))
   return VD ? VD : Info.second;
 auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
+assert(DVarPrivate.PrivateCopy && "DSAStackTy object must be not NULL");
 if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
   return VD ? VD : cast(DVarPrivate.PrivateCopy->getDecl());
 DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(),
@@ -3924,6 +3925,7 @@
 static ExprResult
 tryBuildCapture(Sema &SemaRef, Expr *Capture,
 llvm::MapVector &Captures) {
+  assert(Capture && "cannot build capture if expression is NULL");
   if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
 return SemaRef.PerformImplicitConversion(
 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
@@ -4177,7 +4179,7 @@
 SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 0 << CollapseLoopCountExpr->getSourceRange();
-  else
+  else if (OrderedLoopCountExpr)
 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 1 << OrderedLoopCountExpr->getSourceRange();
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -434,6 +434,9 @@
 /// error, false otherwise.
 bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
 Scope *S) {
+  assert(New && "New function declaration is NULL, aborting merge.");
+  assert(Old && "Old function declaration is NULL, aborting merge.");
+
   bool Invalid = false;
 
   // The declaration context corresponding to the scope is the semantic
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2303,6 +2303,7 @@
 
 unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
  unsigned AddrSpace) {
+  assert(D && "variable declaration must be not NULL");
   if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
 if (D->hasAttr())
   AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -1312,6 +1312,7 @@
 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
 V = CGM.getCXXABI().EmitMemberDataPointer(M

Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-04-19 Thread Apelete Seketeli via cfe-commits
apelete marked an inline comment as done.
apelete added a comment.

http://reviews.llvm.org/D19278



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-04-19 Thread Apelete Seketeli via cfe-commits
apelete updated this revision to Diff 54269.
apelete added a comment.

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

Following changes were done since last revision:

- lib/Sema/SemaOverload.cpp: avoid interleaving (FromExpr) and 
(!FromExpr->isLValue()) conditions in if() statement for better readability.


http://reviews.llvm.org/D19278

Files:
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp

Index: lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -693,6 +693,8 @@
 !Param->getType()->isReferenceType())
   continue;
 
+assert(ArgExpr && "cannot get the type of a NULL expression");
+
 NullConstraint Nullness = getNullConstraint(*ArgSVal, State);
 
 Nullability RequiredNullability =
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -8705,6 +8705,7 @@
 
 void Sema::diagnoseEquivalentInternalLinkageDeclarations(
 SourceLocation Loc, const NamedDecl *D, ArrayRef Equiv) {
+  assert(D && "named declaration must be not NULL");
   Diag(Loc, diag::ext_equivalent_internal_linkage_decl_in_modules) << D;
 
   Module *M = getOwningModule(const_cast(D));
@@ -9185,7 +9186,9 @@
 !ToRefTy->getPointeeType()->isIncompleteType() &&
 S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) {
   BaseToDerivedConversion = 3;
-} else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
+} else if (FromExpr &&
+   !FromExpr->isLValue() &&
+   ToTy->isLValueReferenceType() &&
ToTy.getNonReferenceType().getCanonicalType() ==
FromTy.getNonReferenceType().getCanonicalType()) {
   S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue)
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -939,6 +939,7 @@
 (VD && DSAStack->isForceVarCapturing()))
   return VD ? VD : Info.second;
 auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
+assert(DVarPrivate.PrivateCopy && "DSAStackTy object must be not NULL");
 if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
   return VD ? VD : cast(DVarPrivate.PrivateCopy->getDecl());
 DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, MatchesAlways(),
@@ -3924,6 +3925,7 @@
 static ExprResult
 tryBuildCapture(Sema &SemaRef, Expr *Capture,
 llvm::MapVector &Captures) {
+  assert(Capture && "cannot build capture if expression is NULL");
   if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
 return SemaRef.PerformImplicitConversion(
 Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
@@ -4177,7 +4179,7 @@
 SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 0 << CollapseLoopCountExpr->getSourceRange();
-  else
+  else if (OrderedLoopCountExpr)
 SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
  diag::note_omp_collapse_ordered_expr)
 << 1 << OrderedLoopCountExpr->getSourceRange();
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -434,6 +434,9 @@
 /// error, false otherwise.
 bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
 Scope *S) {
+  assert(New && "New function declaration is NULL, aborting merge.");
+  assert(Old && "Old function declaration is NULL, aborting merge.");
+
   bool Invalid = false;
 
   // The declaration context corresponding to the scope is the semantic
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2303,6 +2303,7 @@
 
 unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
  unsigned AddrSpace) {
+  assert(D && "variable declaration must be not NULL");
   if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
 if (D->hasAttr())
   AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -1312,6 +1312,7 @@
 CGM.getContext().toCharUnitsFromBits((int6

Re: [PATCH] D19278: [scan-build] fix logic error warnings emitted on clang code base

2016-04-19 Thread Apelete Seketeli via cfe-commits
apelete marked an inline comment as done.
apelete added a comment.

http://reviews.llvm.org/D19278



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-04-21 Thread Apelete Seketeli via cfe-commits
apelete created this revision.
apelete added reviewers: rjmccall, zaks.anna, rsmith.
apelete added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Fixing another set of "Logic error" warnings of the type "Called c++
object pointer is null" reported by Clang Static Analyzer on the
following files:

- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
- lib/Sema/SemaLookup.cpp,
- lib/Sema/SemaExprCXX.cpp,
- lib/Frontend/CompilerInstance.cpp,
- lib/Format/Format.cpp,
- lib/AST/DeclObjC.cpp.

Signed-off-by: Apelete Seketeli 

http://reviews.llvm.org/D19385

Files:
  lib/AST/DeclObjC.cpp
  lib/Format/Format.cpp
  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::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, 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/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1646,12 +1646,16 @@
   // Returns \c true if line or one if its children is affected.
   bool nonPPLineAffected(AnnotatedLine *Line,
  const AnnotatedLine *PreviousLine) {
+assert(Line && "line is NULL, cannot determine if affected by input SourceRanges");
+
 bool SomeLineAffected = false;
 Line->ChildrenAffected =
 computeAffectedLines(Line->Children.begin(), Line->Children.end());
 if (Line->ChildrenAffected)
   SomeLineAffected = true;
 
+assert(Line->First && "cannot process line with a NULL first token");
+
 // 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
Index: lib/AST/DeclObjC.cpp

Re: [PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base

2016-04-22 Thread Apelete Seketeli via cfe-commits
apelete added inline comments.


Comment at: lib/Frontend/CompilerInstance.cpp:763
@@ -762,8 +762,3 @@
   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,

rjmccall wrote:
> What's the justification for this one?
CompilerInstance::InitializeSourceManager() could call 
CompilerInstance::InitializeSourceManager() and pass a null pointer value via 
the 5th parameter 'HS':

718. bool CompilerInstance::InitializeSourceManager(const FrontendInputFile 
&Input){
719.   return InitializeSourceManager(
720.   Input, getDiagnostics(), getFileManager(), getSourceManager(),
721.   hasPreprocessor() ? &getPreprocessor().getHeaderSearchInfo() : 
nullptr,
722.   getDependencyOutputOpts(), getFrontendOpts());
723. }

In that case, 'HS' object pointer would be null at this point.
I chose not to assert 'HS' and just check it because we already check if 'File' 
is assigned a null pointer as the result of HS->LookupFile() below.

Should it be fixed otherwise ?


http://reviews.llvm.org/D19385



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits