From e980c65c7639030f547326afee1810ec5c6dcebe Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Wed, 2 Sep 2015 18:10:38 -0700 Subject: [PATCH] Fix remaining warnings, enable warnings as errors Turn on -WX for MSVC builds of the LLILC code, if LLVM hasn't already enabled it (via LLVM_ENABLE_WERROR ON). Make some variable definitions conditional if the only uses are in asserts. --- CMakeLists.txt | 9 +++++++++ lib/GcInfo/CMakeLists.txt | 4 ---- lib/Jit/CMakeLists.txt | 2 -- lib/Reader/CMakeLists.txt | 4 ---- lib/Reader/readerir.cpp | 13 ++++++++++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cd853c..a928901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -261,6 +261,15 @@ if (DEBUG) add_definitions( -DDEBUG -D_DEBUG ) endif() +# Add appropriate flags for MSVC +if (MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHsc") + # Force -WX on even if it's not enabled for LLVM. + if (NOT LLVM_ENABLE_WERROR) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -WX") + endif() +endif() + # Add appropriate flags for GCC if (LLVM_COMPILER_IS_GCC_COMPATIBLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -fno-rtti") diff --git a/lib/GcInfo/CMakeLists.txt b/lib/GcInfo/CMakeLists.txt index 3fe8ad1..520e69b 100644 --- a/lib/GcInfo/CMakeLists.txt +++ b/lib/GcInfo/CMakeLists.txt @@ -4,10 +4,6 @@ include_directories(${LLILC_INCLUDES}/clr ${LLILC_INCLUDES}/GcInfo ${LLILC_INCLUDES}/Jit ${LLILC_INCLUDES}/Pal) - -if( WIN32 ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHsc") -endif() add_definitions(-DSTANDALONE_BUILD) diff --git a/lib/Jit/CMakeLists.txt b/lib/Jit/CMakeLists.txt index cdbca50..9d86301 100644 --- a/lib/Jit/CMakeLists.txt +++ b/lib/Jit/CMakeLists.txt @@ -23,8 +23,6 @@ set(LLVM_LINK_COMPONENTS set(LLILCJIT_LINK_LIBRARIES LLILCReader GcInfo) if (WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHsc") - # Create .def file containing a list of exports preceeded by # 'EXPORTS'. The file "LLILCJit.exports" already contains the list, so we # massage it into the correct format here to create "LLILCJit.exports.def". diff --git a/lib/Reader/CMakeLists.txt b/lib/Reader/CMakeLists.txt index 75855ad..d931e7f 100644 --- a/lib/Reader/CMakeLists.txt +++ b/lib/Reader/CMakeLists.txt @@ -8,10 +8,6 @@ include_directories(${LLILC_INCLUDES}/clr set(LLILCJIT_LINK_LIBRARIES GcInfo) -if( WIN32 ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHsc") -endif() - add_definitions(-DSTANDALONE_BUILD) add_llilcjit_library(LLILCReader diff --git a/lib/Reader/readerir.cpp b/lib/Reader/readerir.cpp index 6856e35..759c62f 100644 --- a/lib/Reader/readerir.cpp +++ b/lib/Reader/readerir.cpp @@ -4449,9 +4449,11 @@ IRNode *GenIR::genArrayElemAddress(IRNode *Array, IRNode *Index, StructType *ReferentTy = cast(Ty->getPointerElementType()); unsigned int RawArrayStructFieldIndex = ReferentTy->getNumElements() - 1; +#ifndef NDEBUG Type *ArrayTy = ReferentTy->getElementType(RawArrayStructFieldIndex); assert(ArrayTy->isArrayTy()); assert(ArrayTy->getArrayElementType() == ElementTy); +#endif LLVMContext &Context = *this->JitContext->LLVMContext; @@ -5433,11 +5435,13 @@ void GenIR::jmp(ReaderBaseNS::CallOpcode Opcode, mdToken Token) { IRNode *CallNode = nullptr; rdrCall(&Data, Opcode, &CallNode); +#ifndef NDEBUG const bool IsSynchronizedMethod = ((getCurrentMethodAttribs() & CORINFO_FLG_SYNCH) != 0); assert(!IsSynchronizedMethod); +#endif - // LLVM requires muttail calls to be immediatley followed by a ret. + // LLVM requires musttail calls to be immediatley followed by a ret. if (Function->getReturnType()->isVoidTy()) { LLVMBuilder->CreateRetVoid(); } else { @@ -6805,9 +6809,11 @@ IRNode *GenIR::getTypedAddress(IRNode *Addr, CorInfoType CorInfoType, // The result of the load is an object reference or a typed reference. if (ReferentTy->isStructTy()) { +#ifndef NDEBUG // This is the typed reference case. We shouldn't need a cast here. Type *ExpectedTy = this->getType(CorInfoType, ClassHandle); assert(ReferentTy == ExpectedTy); +#endif } else { // This is the object reference case so addr should be ptr to managed // ptr to struct. @@ -7384,7 +7390,6 @@ IRNode *GenIR::makeRefAny(CORINFO_RESOLVED_TOKEN *ResolvedToken, Value *CastObject; if (!isManagedPointerType(Object->getType())) { assert(Object->getType()->isIntegerTy()); - IntegerType *ObjectType = cast(Object->getType()); // Not clear what should happen on a size mismatch, so we'll just let // LLVM do what it thinks is reasonable. CastObject = LLVMBuilder->CreateIntToPtr(Object, ExpectedObjectTy); @@ -7499,8 +7504,10 @@ void GenIR::maintainOperandStack(FlowGraphNode *CurrentBlock) { // We need to be very careful about reasoning about or iterating through // instructions in empty blocks or blocks with no terminators. +#ifndef NDEBUG Instruction *TermInst = SuccessorBlock->getTerminator(); const bool SuccessorDegenerate = (TermInst == nullptr); +#endif Instruction *CurrentInst = SuccessorBlock->empty() ? nullptr : SuccessorBlock->begin(); PHINode *Phi = nullptr; @@ -8058,7 +8065,7 @@ IRNode *GenIR::generateIsHardwareAccelerated(CORINFO_CLASS_HANDLE Class) { bool GenIR::checkVectorSignature(std::vector Args, std::vector Types) { assert(Args.size() == Types.size()); - for (int Counter = 0; Counter < Args.size(); ++Counter) { + for (unsigned int Counter = 0; Counter < Args.size(); ++Counter) { assert(Args[Counter]); if (Args[Counter]->getType() != Types[Counter]) { assert(UNREACHED);