This commit enables and fixes warnings for linux build
authorKirill Frolov <k.frolov@samsung.com>
Wed, 11 Nov 2020 12:01:21 +0000 (15:01 +0300)
committerAlexander Soldatov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Fri, 13 Nov 2020 12:14:25 +0000 (15:14 +0300)
Removed -Wno-unused-variable and fixed warnings.

Removed -Wno-tautological-compare and -Wno-invalid-offsetof

Warnings turned off for microsoft's code (we can't change it).

Adding -Wnarrowing, removing -Wno-null-conversion.

Ignoring GCC pragmas with Visual Studio.

Also all compiler settings moved from CMakeLists.txt to
compileoptions.cmake.

20 files changed:
CMakeLists.txt
compileoptions.cmake
src/debug/netcoredbg/CMakeLists.txt
src/debug/netcoredbg/cliprotocol.cpp
src/debug/netcoredbg/cputil.h
src/debug/netcoredbg/frames.h
src/debug/netcoredbg/iprotocol.cpp
src/debug/netcoredbg/manageddebugger.cpp
src/debug/netcoredbg/miprotocol.cpp
src/debug/netcoredbg/modules.cpp
src/debug/netcoredbg/modules.h
src/debug/netcoredbg/platform.cpp
src/debug/netcoredbg/symbolreader.cpp
src/debug/netcoredbg/symbolreader.h
src/debug/netcoredbg/typeprinter.cpp
src/debug/netcoredbg/typeprinter.h
src/debug/netcoredbg/valueprint.cpp
src/debug/netcoredbg/valueprint.h
src/debug/netcoredbg/valuewrite.h
src/debug/netcoredbg/vscodeprotocol.cpp

index 744f8928bfe102f9f0ead67388fc9f5afa9c6676..174833c057613ea0601fd674350b5605b7b33a45 100644 (file)
@@ -8,12 +8,6 @@ set(DOTNET_CHANNEL "3.1" CACHE STRING ".NET SDK channel")
 set(BUILD_MANAGED ON CACHE BOOL "Build managed part")
 set(DBGSHIM_RUNTIME_DIR "" CACHE FILEPATH "Path to dbgshim library directory (at runtime)")
 
-if (WIN32)
-    set(CMAKE_CXX_STANDARD 11)
-else()
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-null-conversion")
-endif()
-
 function(clr_unknown_arch)
     message(FATAL_ERROR "Only AMD64, ARM64, ARM, ARMEL, I386 and WASM are supported")
 endfunction()
index 7329fdd54975ab069ae26adfe68b570669edc963..50065345c7b6f51d8056927c203d952ba99e7e2e 100644 (file)
@@ -1,4 +1,6 @@
 if (CLR_CMAKE_PLATFORM_UNIX)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
   # Disable frame pointer optimizations so profilers can get better call stacks
   add_compile_options(-fno-omit-frame-pointer)
 
@@ -28,13 +30,8 @@ if (CLR_CMAKE_PLATFORM_UNIX)
     add_compile_options(-Werror)
   endif(CLR_CMAKE_WARNINGS_ARE_ERRORS)
 
-  # Disabled warnings
-  add_compile_options(-Wno-unused-private-field)
-  add_compile_options(-Wno-unused-variable)
   # Explicit constructor calls are not supported by clang (this->ClassName::ClassName())
   add_compile_options(-Wno-microsoft)
-  # This warning is caused by comparing 'this' to NULL
-  add_compile_options(-Wno-tautological-compare)
   # There are constants of type BOOL used in a condition. But BOOL is defined as int
   # and so the compiler thinks that there is a mistake.
   add_compile_options(-Wno-constant-logical-operand)
@@ -45,8 +42,6 @@ if (CLR_CMAKE_PLATFORM_UNIX)
 
   add_compile_options(-Wno-unknown-warning-option)
 
-  #These seem to indicate real issues
-  add_compile_options(-Wno-invalid-offsetof)
   # The following warning indicates that an attribute __attribute__((__ms_struct__)) was applied
   # to a struct or a class that has virtual members or a base class. In that case, clang
   # may not generate the same object layout as MSVC.
@@ -55,8 +50,11 @@ if (CLR_CMAKE_PLATFORM_UNIX)
   # Some architectures (e.g., ARM) assume char type is unsigned while CoreCLR assumes char is signed
   # as x64 does. It has been causing issues in ARM (https://github.com/dotnet/coreclr/issues/4746)
   add_compile_options(-fsigned-char)
+
+  add_compile_options(-Wall -Wextra -Walign-cast -Wstrict-aliasing -Wno-unused-parameter -Wnarrowing)
 endif(CLR_CMAKE_PLATFORM_UNIX)
 
+
 if(CLR_CMAKE_PLATFORM_UNIX_ARM AND NOT DEFINED CLR_CMAKE_TARGET_TIZEN_LINUX)
    # Because we don't use CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to use clang
    # we have to set the triple by adding a compiler argument
@@ -71,6 +69,7 @@ endif()
 
 if (WIN32)
   # Compile options for targeting windows
+  set(CMAKE_CXX_STANDARD 11)
 
   # The following options are set by the razzle build
   add_compile_options(/TP) # compile all files as C++
index 5b214941c438d4321d117f49de418f2b01e046d0..a9e3313a86948fe5e4f808248fbc3b6d6458075d 100644 (file)
@@ -14,6 +14,9 @@ endif()
 add_compile_options(-D_MIDL_USE_GUIDDEF_)
 file(GLOB CORGUIDS_SOURCES "${CORECLR_DIR}/src/pal/prebuilt/idl/*_i.cpp")
 add_library(corguids STATIC ${CORGUIDS_SOURCES})
+if (NOT WIN32)
+    target_compile_options(corguids PRIVATE -Wno-unused-parameter)
+endif()
 
 # Include coreclr headers
 
index 67d12e838ab29cf9b1e9bb54ab779d4597d5785a..e9d9c5444a268ff946d2bcd9b51750a870aa9905 100644 (file)
@@ -504,7 +504,6 @@ HRESULT CLIProtocol::PrintVariable(int threadId, uint64_t frameId, std::list<std
         {
             ss << ": {";
         }
-        HRESULT re = m_debugger->GetVariables(v.variablesReference, VariablesBoth, 0, v.namedVariables, children);
         int count = 0;
         for (auto &child : children)
         {
index a98327123a46a79b7508a25e1c689afd283e13af..97c487adfdf7f466c578ddcf0aa3d9d3e2b92f94 100644 (file)
@@ -5,7 +5,12 @@
 
 #include <string>
 #include <vector>
+
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <corerror.h>
+#pragma GCC diagnostic pop
 
 #ifdef _MSC_VER
 std::string to_utf8(const wchar_t *wstr);
index 3501ff2b6fadc55ef3c7dcd226487a8e12052fd3..6398603f1086c0ea6a328bc8a72acbe974dcd6e0 100644 (file)
@@ -3,8 +3,12 @@
 // See the LICENSE file in the project root for more information.
 #pragma once
 
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <cor.h>
 #include <cordebug.h>
+#pragma GCC diagnostic pop
 
 #include <vector>
 
index 2ac44348418feb6dfd34872dba4c049ece9475aa..0ea72aaac9f3e8be1348e7a30eb69aa6dbfb25e0 100644 (file)
@@ -79,7 +79,7 @@ bool IProtocol::GetIndices(const std::vector<std::string> &args, int &index1, in
 
 BreakType IProtocol::GetBreakpointType(const std::vector<std::string> &args)
 {
-    int ncnt = 0;
+    unsigned ncnt = 0;
 
     if (args.empty())
         return BreakType::Error;
index 951a6e72519d39a9ed215b44cd0b0d7288164cda..8e9abcc835854a6f5d59239e0f008f2af1808082 100644 (file)
@@ -718,6 +718,7 @@ public:
 #ifdef FEATURE_PAL
             exitCode = hook::waitpid.GetExitCode();
 #else
+            HRESULT Status = S_OK;
             HPROCESS hProcess;
             DWORD dwExitCode = 0;
             if (SUCCEEDED(pProcess->GetHandle(&hProcess)))
index ec8fdca75f72602976e7514fd46674542a055716..57d48e05a526b7736bbccc606a8f1eb8c34a9dc8 100644 (file)
@@ -147,9 +147,6 @@ HRESULT MIProtocol::PrintFrames(int threadId, std::string &output, int lowFrame,
 
 HRESULT MIProtocol::PrintVariables(const std::vector<Variable> &variables, std::string &output)
 {
-    const bool printValues = true;
-    const bool printTypes = false;
-
     std::ostringstream ss;
     ss << "variables=[";
     const char *sep = "";
@@ -1176,7 +1173,7 @@ void MIProtocol::Printf(const char *fmt, ...)
     if (n < 0)
         return;
 
-    if (n >= sizeof(buffer))
+    if (n >= int(sizeof(buffer)))
     {
         strbuffer.resize(n);
 
@@ -1184,7 +1181,7 @@ void MIProtocol::Printf(const char *fmt, ...)
         n = vsnprintf(&strbuffer[0], strbuffer.size() + 1, fmt, arg);
         va_end(arg);
 
-        if (n < 0 || n > strbuffer.size())
+        if (n < 0 || n > int(strbuffer.size()))
             return;
         out = strbuffer.c_str();
     }
index 2124bef7e3747d29819421be45be1b98ac8e2d29..9bf6ce8b853f1b615fd18727017c18d81d4334fb 100644 (file)
@@ -580,7 +580,6 @@ HRESULT Modules::ForEachModule(std::function<HRESULT(ICorDebugModule *pModule)>
 
 HRESULT Modules::FillSourcesCodeLinesForModule(IMetaDataImport *pMDImport, SymbolReader *symbolReader)
 {
-    HRESULT Status;
     ULONG numTypedefs = 0;
     HCORENUM fEnum = NULL;
     mdTypeDef typeDef;
@@ -603,6 +602,7 @@ HRESULT Modules::FillSourcesCodeLinesForModule(IMetaDataImport *pMDImport, Symbo
                 std::string fullPath = to_utf8(point.document);
 
 #ifdef WIN32
+                HRESULT Status = S_OK;
                 std::string initialFullPath = fullPath;
                 IfFailRet(SymbolReader::StringToUpper(fullPath));
                 m_sourceCaseSensitiveFullPaths[fullPath] = initialFullPath;
index 90008caa86d3a15233139eaaa667b7fdd288a100..445e6a8adc3b16c3e88f58d3397735448385cb93 100644 (file)
@@ -4,7 +4,12 @@
 
 #pragma once
 
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <cor.h>
+#pragma GCC diagnostic pop
+
 #include <cordebug.h>
 
 #include <functional>
index 75c1d66f58920775a3655d41226174ba4934c679..3fa34499ff5d8cfc8355d8be115144da4874a7f0 100644 (file)
@@ -556,7 +556,7 @@ void AddFilesFromDirectoryToTpaList(const std::string &directory, std::string &t
 
     // Walk the directory for each extension separately so that we first get files with .ni.dll extension,
     // then files with .dll extension, etc.
-    for (int extIndex = 0; extIndex < sizeof(tpaExtensions) / sizeof(tpaExtensions[0]); extIndex++)
+    for (size_t extIndex = 0; extIndex < sizeof(tpaExtensions) / sizeof(tpaExtensions[0]); extIndex++)
     {
         const char* ext = tpaExtensions[extIndex];
         int extLength = strlen(ext);
index 76349abf737781ce4c23af6905dc705f720099b5..df1a617ba393dc8bd194bc3f29b9fc07d66c1097 100644 (file)
@@ -388,8 +388,6 @@ HRESULT SymbolReader::PrepareSymbolReader()
 
 HRESULT SymbolReader::ResolveSequencePoint(const char *filename, ULONG32 lineNumber, TADDR mod, mdMethodDef* pToken, ULONG32* pIlOffset)
 {
-    HRESULT Status = S_OK;
-
     if (m_symbolReaderHandle != 0)
     {
         _ASSERTE(resolveSequencePointDelegate != nullptr);
@@ -409,8 +407,6 @@ HRESULT SymbolReader::GetSequencePointByILOffset(
     ULONG64 ilOffset,
     SequencePoint *sequencePoint)
 {
-    HRESULT Status = S_OK;
-
     if (m_symbolReaderHandle != 0)
     {
         _ASSERTE(getSequencePointByILOffsetDelegate != nullptr);
@@ -429,8 +425,6 @@ HRESULT SymbolReader::GetSequencePointByILOffset(
 
 HRESULT SymbolReader::GetStepRangesFromIP(ULONG32 ip, mdMethodDef MethodToken, ULONG32 *ilStartOffset, ULONG32 *ilEndOffset)
 {
-    HRESULT Status = S_OK;
-
     if (m_symbolReaderHandle != 0)
     {
         _ASSERTE(getStepRangesFromIPDelegate != nullptr);
@@ -456,8 +450,6 @@ HRESULT SymbolReader::GetNamedLocalVariableAndScope(
     ULONG32* pIlStart,
     ULONG32* pIlEnd)
 {
-    HRESULT Status = S_OK;
-
     if (!m_symbolReaderHandle)
         return E_FAIL;
 
@@ -488,8 +480,6 @@ HRESULT SymbolReader::GetNamedLocalVariableAndScope(
 
 HRESULT SymbolReader::GetSequencePoints(mdMethodDef methodToken, std::vector<SequencePoint> &points)
 {
-    HRESULT Status = S_OK;
-
     if (m_symbolReaderHandle != 0)
     {
         _ASSERTE(getSequencePointsDelegate != nullptr);
index 2124b7dd85a5aa5af5e0ce33a18205a45b3b6a73..4fe39f2308c8ba95a4be9cae1169fa42e52d777d 100644 (file)
@@ -5,8 +5,12 @@
 // Copyright (c) 2017 Samsung Electronics Co., LTD
 #pragma once
 
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <cor.h>
 #include <cordebug.h>
+#pragma GCC diagnostic pop
 
 #include <string>
 #include <vector>
index 417b0fef26cd3f24e94a3a0d0e7f5abdd544c2dc..14f687b859d770ee8235381927d99375b082dc72 100644 (file)
@@ -630,7 +630,7 @@ PCCOR_SIGNATURE TypePrinter::NameForTypeSig(
 
         case ELEMENT_TYPE_VAR        :
             n  = CorSigUncompressData(typePtr);
-            out = n < args.size() ? args.at(n) : "!" + std::to_string(n);
+            out = n < int(args.size()) ? args.at(n) : "!" + std::to_string(n);
             break;
 
         case ELEMENT_TYPE_MVAR        :
@@ -654,7 +654,6 @@ PCCOR_SIGNATURE TypePrinter::NameForTypeSig(
                 std::list<std::string> genericArgs;
 
                 unsigned numArgs = CorSigUncompressData(typePtr);
-                bool needComma = false;
                 while(numArgs--)
                 {
                     std::string genType;
index 2b255db1e98e285046c6d436f12d5d5ceaa6df03..a45877e99166dcd474805ec23920bf49d80bdc49 100644 (file)
@@ -3,8 +3,12 @@
 // See the LICENSE file in the project root for more information.
 #pragma once
 
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <cor.h>
 #include <cordebug.h>
+#pragma GCC diagnostic pop
 
 #include <list>
 #include <string>
index 31d345401ab5ebbca1d4595850ecc54b62e4c0d5..469a0a2218014d23a81fa5bcb786b07d3c1900f9 100644 (file)
@@ -130,7 +130,6 @@ static HRESULT PrintEnumValue(ICorDebugValue* pInputValue, BYTE* enumValue, stri
 
     //Now that we know the underlying enum type, let's decode the enum variable into OR-ed, human readable enum constants
     fEnum = NULL;
-    bool isFirst = true;
     ULONG64 remainingValue = *((ULONG64*)enumValue);
     while(SUCCEEDED(pMD->EnumFields(&fEnum, currentTypeDef, &fieldDef, 1, &numFields)) && numFields != 0)
     {
index f0425be0b675d0ce4cf6251247c543bdbae3c880..9531b675b0a2f0c6c742a1de172251191bf79cf5 100644 (file)
@@ -3,8 +3,12 @@
 // See the LICENSE file in the project root for more information.
 #pragma once
 
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <cor.h>
 #include <cordebug.h>
+#pragma GCC diagnostic pop
 
 #include <string>
 
index ffd92239e2d059e5fa1ef81f754dfbb6d5130eda..4a125808667fee2f0be62b7a371d42d01bc2f699 100644 (file)
@@ -6,8 +6,13 @@
 
 #include <string>
 
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <cor.h>
 #include <cordebug.h>
+#pragma GCC diagnostic pop
+
 #include "manageddebugger.h"
 
 HRESULT WriteValue(
index 47d8965c4291dad95f0ef04f7360f59ee353db2b..9a73418aa43b2ce2c2a2be1d8bcd4e8ffaf89d45 100644 (file)
 
 #include <exception>
 
+#pragma warning (disable:4068)  // Visual Studio should ignore GCC pragmas
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
 #include <winerror.h>
+#pragma GCC diagnostic pop
 
 #include "vscodeprotocol.h"