Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix comparison and narrowing errors reported by GCC #22821

Merged
merged 7 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 27 additions & 27 deletions src/debug/createdump/crashinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ CrashInfo::QueryInterface(
STDMETHODIMP_(ULONG)
CrashInfo::AddRef()
{
LONG ref = InterlockedIncrement(&m_ref);
LONG ref = InterlockedIncrement(&m_ref);
return ref;
}

Expand All @@ -85,7 +85,7 @@ CrashInfo::Release()
}

HRESULT STDMETHODCALLTYPE
CrashInfo::EnumMemoryRegion(
CrashInfo::EnumMemoryRegion(
/* [in] */ CLRDATA_ADDRESS address,
/* [in] */ ULONG32 size)
{
Expand All @@ -94,10 +94,10 @@ CrashInfo::EnumMemoryRegion(
}

//
// Suspends all the threads and creating a list of them. Should be the first before
// Suspends all the threads and creating a list of them. Should be the first before
// gather any info about the process.
//
bool
bool
CrashInfo::EnumerateAndSuspendThreads()
{
char taskPath[128];
Expand Down Expand Up @@ -176,7 +176,7 @@ CrashInfo::GatherCrashInfo(MINIDUMP_TYPE minidumpType)
{
return false;
}

for (const MemoryRegion& region : m_moduleAddresses)
{
region.Trace();
Expand Down Expand Up @@ -222,7 +222,7 @@ CrashInfo::GatherCrashInfo(MINIDUMP_TYPE minidumpType)
// Add the thread's stack
thread->GetThreadStack(*this);
}
// All the regions added so far has been backed by memory. Now add the rest of
// All the regions added so far has been backed by memory. Now add the rest of
// mappings so the debuggers like lldb see that an address is code (PF_X) even
// if it isn't actually in the core dump.
for (const MemoryRegion& region : m_moduleMappings)
Expand Down Expand Up @@ -256,7 +256,7 @@ CrashInfo::ResumeThreads()
//
// Get the auxv entries to use and add to the core dump
//
bool
bool
CrashInfo::GetAuxvEntries()
{
char auxvPath[128];
Expand All @@ -271,14 +271,14 @@ CrashInfo::GetAuxvEntries()
bool result = false;
elf_aux_entry auxvEntry;

while (read(fd, &auxvEntry, sizeof(elf_aux_entry)) == sizeof(elf_aux_entry))
while (read(fd, &auxvEntry, sizeof(elf_aux_entry)) == sizeof(elf_aux_entry))
{
m_auxvEntries.push_back(auxvEntry);
if (auxvEntry.a_type == AT_NULL)
if (auxvEntry.a_type == AT_NULL)
{
break;
}
if (auxvEntry.a_type < AT_MAX)
if (auxvEntry.a_type < AT_MAX)
{
m_auxvValues[auxvEntry.a_type] = auxvEntry.a_un.a_val;
TRACE("AUXV: %" PRIu " = %" PRIxA "\n", auxvEntry.a_type, auxvEntry.a_un.a_val);
Expand All @@ -296,7 +296,7 @@ CrashInfo::GetAuxvEntries()
bool
CrashInfo::EnumerateModuleMappings()
{
// Here we read /proc/<pid>/maps file in order to parse it and figure out what it says
// Here we read /proc/<pid>/maps file in order to parse it and figure out what it says
// about a library we are looking for. This file looks something like this:
//
// [address] [perms] [offset] [dev] [inode] [pathname] - HEADER is not preset in an actual file
Expand All @@ -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)
Expand All @@ -334,7 +334,7 @@ CrashInfo::EnumerateModuleMappings()
// information.
const void* linuxGateAddress = (const void*)m_auxvValues[AT_SYSINFO_EHDR];

// Reading maps file line by line
// Reading maps file line by line
while ((read = getline(&line, &lineLen, mapsFile)) != -1)
{
uint64_t start, end, offset;
Expand Down Expand Up @@ -374,13 +374,13 @@ 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);
}
}
m_moduleMappings.insert(memoryRegion);
}
else
else
{
m_otherMappings.insert(memoryRegion);
}
Expand Down Expand Up @@ -542,7 +542,7 @@ CrashInfo::GetELFInfo(uint64_t baseAddress)
}

//
// Enumerate the program headers adding the build id note, unwind frame
// Enumerate the program headers adding the build id note, unwind frame
// region and module addresses to the crash info.
//
bool
Expand Down Expand Up @@ -722,7 +722,7 @@ CrashInfo::EnumerateManagedModules(IXCLRDataProcess* pClrDataProcess)
DacpGetModuleData moduleData;
if (SUCCEEDED(hr = moduleData.Request(pClrDataModule.GetPtr())))
{
TRACE("MODULE: %" PRIA PRIx64 " dyn %d inmem %d file %d pe %" PRIA PRIx64 " pdb %" PRIA PRIx64, moduleData.LoadedPEAddress, moduleData.IsDynamic,
TRACE("MODULE: %" PRIA PRIx64 " dyn %d inmem %d file %d pe %" PRIA PRIx64 " pdb %" PRIA PRIx64, moduleData.LoadedPEAddress, moduleData.IsDynamic,
moduleData.IsInMemory, moduleData.IsFileLayout, moduleData.PEFile, moduleData.InMemoryPdbAddress);

if (!moduleData.IsDynamic && moduleData.LoadedPEAddress != 0)
Expand Down Expand Up @@ -849,7 +849,7 @@ CrashInfo::ReadMemory(void* address, void* buffer, size_t size)
}

//
// Add this memory chunk to the list of regions to be
// Add this memory chunk to the list of regions to be
// written to the core dump.
//
void
Expand Down Expand Up @@ -895,7 +895,7 @@ CrashInfo::InsertMemoryRegion(const MemoryRegion& region)
}
else
{
// If the memory region is wholly contained in region found and both have the
// If the memory region is wholly contained in region found and both have the
// same backed by memory state, we're done.
if (found->Contains(region) && (found->IsBackedByMemory() == region.IsBackedByMemory())) {
return;
Expand All @@ -905,11 +905,11 @@ CrashInfo::InsertMemoryRegion(const MemoryRegion& region)
// by memory state is different.
uint64_t start = region.StartAddress();

// The region overlaps/conflicts with one already in the set so add one page at a
// The region overlaps/conflicts with one already in the set so add one page at a
// time to avoid the overlapping pages.
uint64_t numberPages = region.Size() / PAGE_SIZE;

for (int p = 0; p < numberPages; p++, start += PAGE_SIZE)
for (size_t p = 0; p < numberPages; p++, start += PAGE_SIZE)
{
MemoryRegion memoryRegionPage(region.Flags(), start, start + PAGE_SIZE);

Expand All @@ -930,7 +930,7 @@ CrashInfo::InsertMemoryRegion(const MemoryRegion& region)
//
// Get the memory region flags for a start address
//
uint32_t
uint32_t
CrashInfo::GetMemoryRegionFlags(uint64_t start)
{
MemoryRegion search(0, start, start + PAGE_SIZE);
Expand All @@ -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 (size_t p = 0; p < numberPages; p++, start += PAGE_SIZE)
{
BYTE buffer[1];
uint32_t read;
Expand All @@ -981,7 +981,7 @@ CrashInfo::CombineMemoryRegions()

std::set<MemoryRegion> memoryRegionsNew;

// MEMORY_REGION_FLAG_SHARED and MEMORY_REGION_FLAG_PRIVATE are internal flags that
// MEMORY_REGION_FLAG_SHARED and MEMORY_REGION_FLAG_PRIVATE are internal flags that
// don't affect the core dump so ignore them when comparing the flags.
uint32_t flags = m_memoryRegions.begin()->Flags() & (MEMORY_REGION_FLAG_MEMORY_BACKED | MEMORY_REGION_FLAG_PERMISSIONS_MASK);
uint64_t start = m_memoryRegions.begin()->StartAddress();
Expand All @@ -990,7 +990,7 @@ CrashInfo::CombineMemoryRegions()
for (const MemoryRegion& region : m_memoryRegions)
{
// To combine a region it needs to be contiguous, same permissions and memory backed flag.
if ((end == region.StartAddress()) &&
if ((end == region.StartAddress()) &&
(flags == (region.Flags() & (MEMORY_REGION_FLAG_MEMORY_BACKED | MEMORY_REGION_FLAG_PERMISSIONS_MASK))))
{
end = region.EndAddress();
Expand Down Expand Up @@ -1027,7 +1027,7 @@ CrashInfo::CombineMemoryRegions()
//
// Searches for a memory region given an address.
//
const MemoryRegion*
const MemoryRegion*
CrashInfo::SearchMemoryRegions(const std::set<MemoryRegion>& regions, const MemoryRegion& search)
{
std::set<MemoryRegion>::iterator found = regions.find(search);
Expand Down Expand Up @@ -1077,7 +1077,7 @@ CrashInfo::GetStatus(pid_t pid, pid_t* ppid, pid_t* tgid, char** name)
if (name != nullptr)
{
char* n = strchr(line + 6, '\n');
if (n != nullptr)
if (n != nullptr)
{
*n = '\0';
}
Expand Down
4 changes: 2 additions & 2 deletions src/debug/createdump/datatarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ DumpDataTarget::ReadVirtual(
/* [optional][out] */ ULONG32 *done)
{
assert(m_fd != -1);
size_t read = pread64(m_fd, buffer, size, (off64_t)(ULONG_PTR)address);
ssize_t read = pread64(m_fd, buffer, size, (off64_t)(ULONG_PTR)address);
if (read == -1)
{
*done = 0;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/debug/debug-pal/unix/twowaypipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/unwinder/amd64/unwinder_amd64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class InstructionBuffer
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];
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/vm/callingconvention.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/vm/codeversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class MethodDescVersioningState
HRESULT UpdateJumpStampHelper(BYTE* pbCode, INT64 i64OldValue, INT64 i64NewValue, BOOL fContentionPossible);
#endif
PTR_MethodDesc m_pMethodDesc;

enum MethodDescVersioningStateFlags
{
JumpStampMask = 0x3,
Expand Down Expand Up @@ -582,7 +582,7 @@ class CodeVersionManager
void EnterLock();
void LeaveLock();
#endif

#ifdef DEBUG
BOOL LockOwnedByCurrentThread() const;
#endif
Expand Down Expand Up @@ -642,7 +642,7 @@ class CodeVersionManager

//closed MethodDesc -> MethodDescVersioningState
MethodDescVersioningStateHash m_methodDescVersioningStateMap;

CrstExplicitInit m_crstTable;
};

Expand Down
6 changes: 3 additions & 3 deletions tests/src/Interop/PInvoke/Decimal/PInvoke/DecNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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), 0x7fffffff} };
CY g_CY_MinValue = { { (LONG)0x00000000, (LONG)0x80000000 } };
CY g_CY_Zero = { { 0 } };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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), 0x7fffffff} };
CY g_CY_MinValue = { {(LONG)0x00000000, (LONG)0x80000000} };
CY g_CY_Zero = { {0} };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ 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 ||
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 ||
p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ 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 ||
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 ||
p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ 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 ||
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 ||
p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Interop/common/xplatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef ptrdiff_t INT_PTR;
typedef size_t UINT_PTR;

typedef unsigned long long ULONG64;
typedef unsigned long long LONG64;
typedef long long LONG64;
typedef double DOUBLE;
typedef float FLOAT;
typedef int INT, *LPINT;
Expand Down
Loading