Fix comparison and narrowing errors reported by GCC
authorAdeel <adeelbm@outlook.com>
Sun, 24 Feb 2019 20:14:06 +0000 (12:14 -0800)
committerAdeel <adeelbm@outlook.com>
Sun, 24 Feb 2019 23:53:32 +0000 (15:53 -0800)
16 files changed:
src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
src/debug/createdump/crashinfo.cpp
src/debug/createdump/datatarget.cpp
src/debug/debug-pal/unix/twowaypipe.cpp
src/unwinder/amd64/unwinder_amd64.cpp
src/vm/callingconvention.h
src/vm/codeversion.h
src/vm/crossloaderallocatorhash.inl
src/vm/inlinetracking.h
src/vm/rejit.h
tests/src/Interop/PInvoke/Decimal/PInvoke/DecNative.cpp
tests/src/Interop/PInvoke/Decimal/ReversePInvoke/RevNative.cpp
tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h
tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalExpStruct/ExpStructAsParamNative.h
tests/src/Interop/StructMarshalling/ReversePInvoke/MarshalSeqStruct/SeqStructDelRevPInvokeNative.h
tests/src/JIT/jit64/mcc/interop/native_i1c.cpp

index eb2333c..7bfe2ea 100644 (file)
@@ -190,7 +190,7 @@ void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList)
 
     // 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 4db2b00..192ed82 100644 (file)
@@ -317,7 +317,7 @@ CrashInfo::EnumerateModuleMappings()
     // Making something like: /proc/123/maps
     char mapPath[128];
     int chars = snprintf(mapPath, sizeof(mapPath), "/proc/%d/maps", m_pid);
-    assert(chars > 0 && chars <= sizeof(mapPath));
+    assert(chars > 0 && (size_t)chars <= sizeof(mapPath));
 
     FILE* mapsFile = fopen(mapPath, "r");
     if (mapsFile == nullptr)
@@ -374,7 +374,7 @@ CrashInfo::EnumerateModuleMappings()
                     std::string coreclrPath;
                     coreclrPath.append(moduleName);
                     size_t last = coreclrPath.rfind(MAKEDLLNAME_A("coreclr"));
-                    if (last != -1) {
+                    if (last != std::string::npos) {
                         m_coreclrPath = coreclrPath.substr(0, last);
                     }
                 }
@@ -909,7 +909,7 @@ CrashInfo::InsertMemoryRegion(const MemoryRegion& region)
     // time to avoid the overlapping pages.
     uint64_t numberPages = region.Size() / PAGE_SIZE;
 
-    for (int p = 0; p < numberPages; p++, start += PAGE_SIZE)
+    for (uint64_t p = 0; p < numberPages; p++, start += PAGE_SIZE)
     {
         MemoryRegion memoryRegionPage(region.Flags(), start, start + PAGE_SIZE);
 
@@ -957,7 +957,7 @@ CrashInfo::ValidRegion(const MemoryRegion& region)
         uint64_t start = region.StartAddress();
 
         uint64_t numberPages = region.Size() / PAGE_SIZE;
-        for (int p = 0; p < numberPages; p++, start += PAGE_SIZE)
+        for (uint64_t p = 0; p < numberPages; p++, start += PAGE_SIZE)
         {
             BYTE buffer[1];
             uint32_t read;
index b0fb6eb..9345450 100644 (file)
@@ -151,7 +151,7 @@ DumpDataTarget::ReadVirtual(
 {
     assert(m_fd != -1);
     size_t read = pread64(m_fd, buffer, size, (off64_t)(ULONG_PTR)address);
-    if (read == -1)
+    if (read == (size_t)-1)
     {
         *done = 0;
         return E_FAIL;
@@ -215,7 +215,7 @@ DumpDataTarget::GetThreadContext(
     memset(context, 0, contextSize);
     for (const ThreadInfo* thread : m_crashInfo->Threads())
     {
-        if (thread->Tid() == threadID)
+        if (thread->Tid() == (pid_t)threadID)
         {
             thread->GetThreadContext(contextFlags, reinterpret_cast<CONTEXT*>(context));
             return S_OK;
index b0acb1d..91afd82 100644 (file)
@@ -117,8 +117,8 @@ int TwoWayPipe::Read(void *buffer, DWORD bufferSize)
     while ((bytesRead = (int)read(m_inboundPipe, buffer, cb)) > 0)
     {
         totalBytesRead += bytesRead;
-        _ASSERTE(totalBytesRead <= bufferSize);
-        if (totalBytesRead >= bufferSize)
+        _ASSERTE(totalBytesRead <= (int)bufferSize);
+        if (totalBytesRead >= (int)bufferSize)
         {
             break;
         }
@@ -144,8 +144,8 @@ int TwoWayPipe::Write(const void *data, DWORD dataSize)
     while ((bytesWritten = (int)write(m_outboundPipe, data, cb)) > 0)
     {
         totalBytesWritten += bytesWritten;
-        _ASSERTE(totalBytesWritten <= dataSize);
-        if (totalBytesWritten >= dataSize)
+        _ASSERTE(totalBytesWritten <= (int)dataSize);
+        if (totalBytesWritten >= (int)dataSize)
         {
             break;
         }
index 65da786..8d989d4 100644 (file)
@@ -134,7 +134,7 @@ public:
     UCHAR operator[](int index)
     {
         int realIndex = m_offset + index;
-        UNWINDER_ASSERT(realIndex < sizeof(m_buffer));
+        UNWINDER_ASSERT(realIndex < (int)sizeof(m_buffer));
         return m_buffer[realIndex];
     }
 };
index eaabaa4..7368fec 100644 (file)
@@ -179,7 +179,7 @@ struct TransitionBlock
         LIMITED_METHOD_CONTRACT;
 
 #if defined(UNIX_AMD64_ABI)
-        return offset >= sizeof(TransitionBlock);
+        return offset >= (int)sizeof(TransitionBlock);
 #else        
         int ofsArgRegs = GetOffsetOfArgumentRegisters();
 
index 821c938..a85a6be 100644 (file)
@@ -105,14 +105,16 @@ private:
         Synthetic
     };
 
+    struct SyntheticStorage
+    {
+        PTR_MethodDesc m_pMethodDesc;
+    };
+
     StorageKind m_storageKind;
     union
     {
         PTR_NativeCodeVersionNode m_pVersionNode;
-        struct SyntheticStorage
-        {
-            PTR_MethodDesc m_pMethodDesc;
-        } m_synthetic;
+        SyntheticStorage m_synthetic;
     };
 #endif // FEATURE_CODE_VERSIONING
 };
@@ -203,15 +205,17 @@ private:
         Synthetic
     };
 
+    struct SyntheticStorage
+    {
+        PTR_Module m_pModule;
+        mdMethodDef m_methodDef;
+    };
+
     StorageKind m_storageKind;
     union
     {
         PTR_ILCodeVersionNode m_pVersionNode;
-        struct SyntheticStorage
-        {
-            PTR_Module m_pModule;
-            mdMethodDef m_methodDef;
-        } m_synthetic;
+        SyntheticStorage m_synthetic;
     };
 };
 
index 51bce4e..a12470c 100644 (file)
@@ -201,7 +201,7 @@ template <class TKey_, class TValue_>
 /*static*/ inline INT32 GCHeapHashDependentHashTrackerHashTraits::Hash(PtrTypeKey *pValue)
 {
     LIMITED_METHOD_CONTRACT;
-    return (INT32)*pValue;
+    return *(INT32*)pValue;
 }
 
 /*static*/ inline INT32 GCHeapHashDependentHashTrackerHashTraits::Hash(PTRARRAYREF arr, INT32 index)
index 976a0e7..58336a4 100644 (file)
@@ -106,7 +106,7 @@ public:
     static count_t Hash(key_t k)
     {
         LIMITED_METHOD_DAC_CONTRACT;
-        return ((count_t)k.m_methodDef ^ (count_t)k.m_module);
+        return k.m_methodDef ^ *(count_t*)k.m_module;
     }
     static const element_t Null()
     {
index 8401ecb..09513e1 100644 (file)
@@ -150,7 +150,7 @@ private:
         typedef CodeVersionManager * key_t;
         static key_t GetKey(const element_t &e) { return e->m_pCodeVersionManager; }
         static BOOL Equals(key_t k1, key_t k2) { return (k1 == k2); }
-        static count_t Hash(key_t k) { return (count_t)k; }
+        static count_t Hash(key_t k) { return *(count_t*)k; }
         static bool IsNull(const element_t &e) { return (e == NULL); }
     };
 
index a853f7e..875d580 100644 (file)
@@ -6,11 +6,11 @@
 #include <xplatform.h>
 #include "platformdefines.h"
 
-DECIMAL g_DECIMAL_MaxValue = { 0, {{ 0, 0 }}, 0xffffffff, {{0xffffffff, 0xffffffff}} };
-DECIMAL g_DECIMAL_MinValue  = { 0, {{ 0, DECIMAL_NEG }}, 0xffffffff, {{0xffffffff, 0xffffffff}} };
+DECIMAL g_DECIMAL_MaxValue = { 0, {{ 0, 0 }}, static_cast<int>(0xffffffff), {{static_cast<int>(0xffffffff), static_cast<int>(0xffffffff)}} };
+DECIMAL g_DECIMAL_MinValue  = { 0, {{ 0, DECIMAL_NEG }}, static_cast<int>(0xffffffff), {{static_cast<int>(0xffffffff), static_cast<int>(0xffffffff)}} };
 DECIMAL g_DECIMAL_Zero = { 0 };
 
-CY g_CY_MaxValue = { { 0xffffffff, 0x7fffffff } };
+CY g_CY_MaxValue = { { static_cast<int>(0xffffffff), static_cast<int>(0x7fffffff) } };
 CY g_CY_MinValue = { { (LONG)0x00000000, (LONG)0x80000000 } };
 CY g_CY_Zero = { { 0 } };
 
index 6f716e8..d586bfa 100644 (file)
@@ -6,11 +6,11 @@
 #include <xplatform.h>
 #include "platformdefines.h"
 
-DECIMAL g_DECIMAL_MaxValue = { 0, {{ 0, 0 }}, 0xffffffff, {{0xffffffff, 0xffffffff}} };
-DECIMAL g_DECIMAL_MinValue  = { 0, {{ 0, DECIMAL_NEG }}, 0xffffffff, {{0xffffffff, 0xffffffff }}};
+DECIMAL g_DECIMAL_MaxValue = { 0, {{ 0, 0 }}, static_cast<int>(0xffffffff), {{static_cast<int>(0xffffffff), static_cast<int>(0xffffffff)}} };
+DECIMAL g_DECIMAL_MinValue  = { 0, {{ 0, DECIMAL_NEG }}, static_cast<int>(0xffffffff), {{static_cast<int>(0xffffffff), static_cast<int>(0xffffffff) }}};
 DECIMAL g_DECIMAL_Zero = { 0 };
 
-CY g_CY_MaxValue = { {0xffffffff, 0x7fffffff} };
+CY g_CY_MaxValue = { {static_cast<int>(0xffffffff), static_cast<int>(0x7fffffff)} };
 CY g_CY_MinValue = { {(LONG)0x00000000, (LONG)0x80000000} };
 CY g_CY_Zero = { {0} };
 
index 3d3bc81..6b38ec9 100644 (file)
@@ -374,8 +374,8 @@ void ChangeNumberSequential(NumberSequential* p)
 
 bool IsCorrectNumberSequential(NumberSequential* p)
 {
-       if(p->i32 != (-0x7fffffff - 1) || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 || 
-               p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 ||
+       if(p->i32 != (-0x7fffffff - 1) || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 ||
+               p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != (unsigned)-1234567890 ||
                p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
        {
                return false;
index 2f6ebc9..0c931c6 100644 (file)
@@ -404,8 +404,8 @@ void ChangeNumberSequential(NumberSequential* p)
 
 bool IsCorrectNumberSequential(NumberSequential* p)
 {
-    if(p->i32 != INT_MIN || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 || 
-        p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 ||
+    if(p->i32 != INT_MIN || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 ||
+        p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != (unsigned)-1234567890 ||
         p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
     {
         return false;
index 43fdb7f..30205ba 100644 (file)
@@ -392,8 +392,8 @@ void ChangeNumberSequential(NumberSequential* p)
 
 bool IsCorrectNumberSequential(NumberSequential* p)
 {
-    if(p->i32 != INT_MIN || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 || 
-        p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 ||
+    if(p->i32 != INT_MIN || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 ||
+        p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != (unsigned)-1234567890 ||
         p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
     {
         return false;
index b20408d..35c70ac 100644 (file)
@@ -4,17 +4,12 @@
 #include <stdarg.h>
 #include "native.h"
 
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wvarargs"
-#endif
-
-MCC_API VType1 sum(float first, ...) {
+MCC_API VType1 sum(double first, ...) {
     VType1 result;
 
     int count = 0;
     float sum = 0.0;
-    float val = first;
+    float val = (float)first;
     va_list args;
 
     // initialize variable arguments.
@@ -22,7 +17,7 @@ MCC_API VType1 sum(float first, ...) {
     while (val != (float)-1) {
         sum += val;
         count++;
-        val = va_arg(args, float);
+        val = (float)va_arg(args, double);
     }
     // reset variable arguments.
     va_end(args);
@@ -53,7 +48,3 @@ MCC_API VType1 sum(float first, ...) {
 
     return result;
 }
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif