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 , const Expr *E,
 LValue , 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 , const Expr *E,
 LValue , 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


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] 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 ,
const InitializedEntity ,
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 ,
const InitializedEntity ,
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
+++ 

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