[pkg-d-commits] [ldc] 53/74: Fix C++ warnings (#2140)

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:54:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta2
in repository ldc.

commit 151e83dc6b978b2ad423808a8eea1a64e24ae479
Author: kinke <kinke at users.noreply.github.com>
Date:   Fri May 26 13:45:15 2017 +0200

    Fix C++ warnings (#2140)
---
 driver/linker.cpp   |  8 ++++++--
 gen/functions.cpp   |  1 +
 gen/llvmhelpers.cpp |  8 +++++---
 gen/modules.cpp     |  2 +-
 gen/naked.cpp       |  7 +++----
 gen/statements.cpp  |  3 ++-
 gen/tocall.cpp      |  1 +
 gen/toconstelem.cpp |  2 ++
 gen/toir.cpp        |  2 ++
 gen/tollvm.cpp      |  2 ++
 gen/uda.cpp         | 12 ++++++------
 11 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/driver/linker.cpp b/driver/linker.cpp
index bad8a3d..57215db 100644
--- a/driver/linker.cpp
+++ b/driver/linker.cpp
@@ -113,6 +113,8 @@ static std::string getOutputName(bool const sharedLib) {
 //////////////////////////////////////////////////////////////////////////////
 // LTO functionality
 
+#if LDC_LLVM_VER >= 309
+
 namespace {
 
 void addLinkerFlag(std::vector<std::string> &args, const llvm::Twine &flag) {
@@ -209,7 +211,6 @@ void addDarwinLTOFlags(std::vector<std::string> &args) {
 
 /// Adds the required linker flags for LTO builds to args.
 void addLTOLinkFlags(std::vector<std::string> &args) {
-#if LDC_LLVM_VER >= 309
   if (global.params.targetTriple->isOSLinux() ||
       global.params.targetTriple->isOSFreeBSD() ||
       global.params.targetTriple->isOSNetBSD() ||
@@ -220,10 +221,11 @@ void addLTOLinkFlags(std::vector<std::string> &args) {
   } else if (global.params.targetTriple->isOSDarwin()) {
     addDarwinLTOFlags(args);
   }
-#endif
 }
 } // anonymous namespace
 
+#endif // LDC_LLVM_VER >= 309
+
 //////////////////////////////////////////////////////////////////////////////
 
 namespace {
@@ -348,10 +350,12 @@ static int linkObjToBinaryGcc(bool sharedLib) {
     args.push_back("-fsanitize=thread");
   }
 
+#if LDC_LLVM_VER >= 309
   // Add LTO link flags before adding the user link switches, such that the user
   // can pass additional options to the LTO plugin.
   if (opts::isUsingLTO())
     addLTOLinkFlags(args);
+#endif
 
   // additional linker and cc switches (preserve order across both lists)
   for (unsigned ilink = 0, icc = 0;;) {
diff --git a/gen/functions.cpp b/gen/functions.cpp
index 8bd7152..35bc8b0 100644
--- a/gen/functions.cpp
+++ b/gen/functions.cpp
@@ -268,6 +268,7 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) {
     FuncDeclaration *p = fdecl->parent->isFuncDeclaration();
     assert(p);
     AggregateDeclaration *ad = p->isMember2();
+    (void)ad;
     assert(ad);
     dnest = Type::tvoid->pointerTo();
   } else if (fdecl->needThis()) {
diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp
index 1f6b3e4..6e8909f 100644
--- a/gen/llvmhelpers.cpp
+++ b/gen/llvmhelpers.cpp
@@ -315,8 +315,6 @@ void DtoAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
   LOG_SCOPE;
 
   Type *t = lhs->type->toBasetype();
-  Type *t2 = rhs->type->toBasetype();
-
   assert(t->ty != Tvoid && "Cannot assign values of type void.");
 
   if (t->ty == Tbool) {
@@ -344,7 +342,7 @@ void DtoAssign(Loc &loc, DValue *lhs, DValue *rhs, int op,
     }
     DtoStore(r, l);
   } else if (t->ty == Tclass) {
-    assert(t2->ty == Tclass);
+    assert(rhs->type->toBasetype()->ty == Tclass);
     LLValue *l = DtoLVal(lhs);
     LLValue *r = DtoRVal(rhs);
     IF_LOG {
@@ -478,6 +476,7 @@ DValue *DtoCastPtr(Loc &loc, DValue *val, Type *to) {
 
   Type *totype = to->toBasetype();
   Type *fromtype = val->type->toBasetype();
+  (void)fromtype;
   assert(fromtype->ty == Tpointer || fromtype->ty == Tfunction);
 
   LLValue *rval;
@@ -1171,6 +1170,7 @@ LLConstant *DtoConstExpInit(Loc &loc, Type *targetType, Expression *exp) {
       val = llvm::ConstantArray::get(at, elements);
     }
 
+    (void)numTotalVals;
     assert(product == numTotalVals);
     return val;
   }
@@ -1192,9 +1192,11 @@ LLConstant *DtoConstExpInit(Loc &loc, Type *targetType, Expression *exp) {
     llvm::IntegerType *source = llvm::cast<llvm::IntegerType>(llType);
     llvm::IntegerType *target = llvm::cast<llvm::IntegerType>(targetLLType);
 
+    (void)source;
     assert(target->getBitWidth() > source->getBitWidth() &&
            "On initializer integer type mismatch, the target should be wider "
            "than the source.");
+
     return llvm::ConstantExpr::getZExtOrBitCast(val, target);
   }
 
diff --git a/gen/modules.cpp b/gen/modules.cpp
index dd803a2..f4105a4 100644
--- a/gen/modules.cpp
+++ b/gen/modules.cpp
@@ -280,7 +280,7 @@ llvm::Function *buildRegisterDSO(RegistryStyle style,
       getRuntimeFunction(Loc(), gIR->module, "_d_dso_registry");
   const auto recordPtrTy = dsoRegistry->getFunctionType()->getContainedType(1);
 
-  llvm::Function *getTlsAnchorPtr;
+  llvm::Function *getTlsAnchorPtr = nullptr;
   if (style == RegistryStyle::sectionDarwin) {
     getTlsAnchorPtr = buildGetTLSAnchor();
   }
diff --git a/gen/naked.cpp b/gen/naked.cpp
index f66f406..5208e15 100644
--- a/gen/naked.cpp
+++ b/gen/naked.cpp
@@ -269,7 +269,8 @@ void emitABIReturnAsmStmt(IRAsmBlock *asmblock, Loc &loc,
 
   // x86
   if (global.params.targetTriple->getArch() == llvm::Triple::x86) {
-    LINK l = fdecl->linkage;
+    const LINK l = fdecl->linkage;
+    (void)l;
     assert((l == LINKd || l == LINKc || l == LINKwindows) &&
            "invalid linkage for asm implicit return");
 
@@ -406,9 +407,7 @@ DValue *DtoInlineAsmExpr(Loc &loc, FuncDeclaration *fd, Expressions *arguments,
   IF_LOG Logger::println("DtoInlineAsmExpr @ %s", loc.toChars());
   LOG_SCOPE;
 
-  TemplateInstance *ti = fd->toParent()->isTemplateInstance();
-  assert(ti && "invalid inline __asm expr");
-
+  assert(fd->toParent()->isTemplateInstance() && "invalid inline __asm expr");
   assert(arguments->dim >= 2 && "invalid __asm call");
 
   // get code param
diff --git a/gen/statements.cpp b/gen/statements.cpp
index 6d2d0fc..4b16074 100644
--- a/gen/statements.cpp
+++ b/gen/statements.cpp
@@ -328,7 +328,8 @@ public:
       return arg1 == DComputeTarget::Host;
     }
     else {
-      return arg1 == dct->target && (!arg2 || arg2 == dct->tversion);
+      return arg1 == dct->target &&
+             (!arg2 || arg2 == static_cast<dinteger_t>(dct->tversion));
     }
   }
 
diff --git a/gen/tocall.cpp b/gen/tocall.cpp
index aebc042..bba00c4 100644
--- a/gen/tocall.cpp
+++ b/gen/tocall.cpp
@@ -691,6 +691,7 @@ private:
 
     // verify that sret and/or inreg attributes are set
     const AttrBuilder &sretAttrs = irFty.arg_sret->attrs;
+    (void)sretAttrs;
     assert((sretAttrs.contains(LLAttribute::StructRet) ||
             sretAttrs.contains(LLAttribute::InReg)) &&
            "Sret arg not sret or inreg?");
diff --git a/gen/toconstelem.cpp b/gen/toconstelem.cpp
index adec650..481e502 100644
--- a/gen/toconstelem.cpp
+++ b/gen/toconstelem.cpp
@@ -651,6 +651,8 @@ public:
             ++i;
           }
         }
+
+        (void)nexprs;
         assert(i == nexprs);
       }
 
diff --git a/gen/toir.cpp b/gen/toir.cpp
index e23b731..f970952 100644
--- a/gen/toir.cpp
+++ b/gen/toir.cpp
@@ -76,6 +76,7 @@ static void write_struct_literal(Loc loc, LLValue *mem, StructDeclaration *sd,
                                  Expressions *elements) {
   assert(elements && "struct literal has null elements");
   const auto numMissingElements = sd->fields.dim - elements->dim;
+  (void)numMissingElements;
   assert(numMissingElements == 0 || (sd->vthis && numMissingElements == 1));
 
   // might be reset to an actual i8* value so only a single bitcast is emitted
@@ -1550,6 +1551,7 @@ public:
       result = new DImValue(e->type, mem);
     }
 
+    (void)isArgprefixHandled;
     assert(e->argprefix == NULL || isArgprefixHandled);
   }
 
diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp
index c76c890..e8532c8 100644
--- a/gen/tollvm.cpp
+++ b/gen/tollvm.cpp
@@ -285,6 +285,7 @@ llvm::GetElementPtrInst *DtoGEP(LLValue *ptr, llvm::ArrayRef<LLValue *> indices,
                                 bool inBounds, const char *name,
                                 llvm::BasicBlock *bb) {
   LLPointerType *p = isaPointer(ptr);
+  (void)p;
   assert(p && "GEP expects a pointer type");
   auto gep = llvm::GetElementPtrInst::Create(
 #if LDC_LLVM_VER >= 307
@@ -320,6 +321,7 @@ LLValue *DtoGEPi(LLValue *ptr, unsigned i0, unsigned i1, const char *name,
 
 LLConstant *DtoGEPi(LLConstant *ptr, unsigned i0, unsigned i1) {
   LLPointerType *p = isaPointer(ptr);
+  (void)p;
   assert(p && "GEP expects a pointer type");
   LLValue *indices[] = {DtoConstUint(i0), DtoConstUint(i1)};
   return llvm::ConstantExpr::getGetElementPtr(
diff --git a/gen/uda.cpp b/gen/uda.cpp
index 4bbbad4..edf3e7a 100644
--- a/gen/uda.cpp
+++ b/gen/uda.cpp
@@ -131,8 +131,6 @@ const char *getFirstElemString(StructLiteralExp *sle) {
 // @allocSize(1)
 // @allocSize(0,2)
 void applyAttrAllocSize(StructLiteralExp *sle, IrFunction *irFunc) {
-  llvm::Function *func = irFunc->getLLVMFunc();
-
   checkStructElems(sle, {Type::tint32, Type::tint32});
   auto sizeArgIdx = getIntElem(sle, 0);
   auto numArgIdx = getIntElem(sle, 1);
@@ -141,10 +139,6 @@ void applyAttrAllocSize(StructLiteralExp *sle, IrFunction *irFunc) {
   // implicit `this` parameter)
   auto numUserParams = irFunc->irFty.args.size();
 
-  // Get the number of parameters of the function in LLVM IR. This includes
-  // the `this` and sret parameters.
-  auto llvmNumParams = irFunc->irFty.funcType->getNumParams();
-
   // Verify that the index values are valid
   bool error = false;
   if (sizeArgIdx + 1 > sinteger_t(numUserParams)) {
@@ -164,6 +158,10 @@ void applyAttrAllocSize(StructLiteralExp *sle, IrFunction *irFunc) {
 
 // The allocSize attribute is only effective for LLVM >= 3.9.
 #if LDC_LLVM_VER >= 309
+  // Get the number of parameters of the function in LLVM IR. This includes
+  // the `this` and sret parameters.
+  const auto llvmNumParams = irFunc->irFty.funcType->getNumParams();
+
   // Offset to correct indices for sret and this parameters.
   // These parameters can never be used for allocsize, and the user-specified
   // index does not account for these.
@@ -184,6 +182,8 @@ void applyAttrAllocSize(StructLiteralExp *sle, IrFunction *irFunc) {
     builder.addAllocSizeAttr(llvmSizeIdx, llvm::Optional<unsigned>());
   }
 
+  llvm::Function *func = irFunc->getLLVMFunc();
+
 #if LDC_LLVM_VER >= 500
   func->addAttributes(LLAttributeSet::FunctionIndex, builder);
 #else

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list