Skip to content

Commit

Permalink
Fix C4267
Browse files Browse the repository at this point in the history
```
warning C4267: '=' : conversion from 'size_t' to 'int32_t', possible loss of data
```
  • Loading branch information
fjeremic committed Jun 7, 2021
1 parent 98d46b0 commit 5cefde1
Show file tree
Hide file tree
Showing 43 changed files with 126 additions and 126 deletions.
2 changes: 1 addition & 1 deletion compiler/codegen/CodeGenRA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ OMR::CodeGenerator::TR_RegisterPressureState::updateRegisterPressure(TR::Symbol
if (dt == TR::NoType)
dt = symbol->getDataType();

_gprPressure += cg->gprCount(TR::DataType(dt),symbol->getSize());
_gprPressure += cg->gprCount(TR::DataType(dt), static_cast<int32_t>(symbol->getSize()));
_fprPressure += cg->fprCount(TR::DataType(dt));
_vrfPressure += cg->vrfCount(TR::DataType(dt));

Expand Down
8 changes: 4 additions & 4 deletions compiler/compile/OMRSymbolReferenceTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class TR_OpaqueMethodBlock;


OMR::SymbolReferenceTable::SymbolReferenceTable(size_t sizeHint, TR::Compilation *comp) :
baseArray(comp->trMemory(), sizeHint + TR_numRuntimeHelpers),
baseArray(comp->trMemory(), static_cast<uint32_t>(sizeHint + TR_numRuntimeHelpers)),
aliasBuilder(self(), sizeHint, comp),
_trMemory(comp->trMemory()),
_fe(comp->fe()),
Expand Down Expand Up @@ -943,7 +943,7 @@ OMR::SymbolReferenceTable::methodSymRefFromName(TR::ResolvedMethodSymbol * ownin
//
TR::StackMemoryRegion stackMemoryRegion(*trMemory());

int32_t fullSignatureLength = strlen(className) + 1 + strlen(methodName) + strlen(methodSignature);
auto fullSignatureLength = strlen(className) + 1 + strlen(methodName) + strlen(methodSignature);
char *fullSignature = (char*)trMemory()->allocateMemory(1 + fullSignatureLength, stackAlloc);
sprintf(fullSignature, "%s.%s%s", className, methodName, methodSignature);
TR_ASSERT(strlen(fullSignature) == fullSignatureLength, "Computed fullSignatureLength must match actual length of fullSignature");
Expand Down Expand Up @@ -1607,7 +1607,7 @@ OMR::SymbolReferenceTable::findOrCreateAutoSymbolImpl(TR::ResolvedMethodSymbol *

if (isInternalPointer)
{
sym = size ? TR::AutomaticSymbol::createInternalPointer(trHeapMemory(), type, size, comp()->fe()) :
sym = size ? TR::AutomaticSymbol::createInternalPointer(trHeapMemory(), type, static_cast<uint32_t>(size), comp()->fe()) :
TR::AutomaticSymbol::createInternalPointer(trHeapMemory(), type);
_numInternalPointers++;
if (_numInternalPointers > comp()->maxInternalPointers())
Expand All @@ -1617,7 +1617,7 @@ OMR::SymbolReferenceTable::findOrCreateAutoSymbolImpl(TR::ResolvedMethodSymbol *
}
else
{
sym = size ? TR::AutomaticSymbol::create(trHeapMemory(),type,size) :
sym = size ? TR::AutomaticSymbol::create(trHeapMemory(),type,static_cast<uint32_t>(size)) :
TR::AutomaticSymbol::create(trHeapMemory(),type);
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/compile/OSRData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ TR_OSRCompilationData::writeInstruction2SharedSlotMap(uint8_t* buffer) const
uint32_t sectionSize = getSizeOfInstruction2SharedSlotMap();
*((uint32_t*)buffer) = sectionSize; buffer += sizeof(uint32_t);
*((uint32_t*)buffer) = getMaxScratchBufferSize(); buffer += sizeof(uint32_t);
int32_t numberOfMappings = instruction2SharedSlotMap.size();
int32_t numberOfMappings = static_cast<int32_t>(instruction2SharedSlotMap.size());
*((int32_t*)buffer) = numberOfMappings; buffer += sizeof(int32_t);
for (auto itr = instruction2SharedSlotMap.begin(), end = instruction2SharedSlotMap.end(); itr != end; ++itr)
{
Expand Down Expand Up @@ -998,7 +998,7 @@ TR::Compilation& operator<< (TR::Compilation& out, const TR_OSRCompilationData&
const TR_OSRCompilationData::TR_Instruction2SharedSlotMap& array1 = osrCompilationData.instruction2SharedSlotMap;
if (array1.size() != 0)
{
out << ", Instr2SharedSlotMetaData: " << array1.size() << "[\n";
out << ", Instr2SharedSlotMetaData: " << static_cast<const int32_t>(array1.size()) << "[\n";
bool first = true;
for (auto itr = array1.begin(), end = array1.end(); itr != end; ++itr)
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/compile/ResolvedMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void TR_ResolvedMethod::makeParameterList(TR::ResolvedMethodSymbol *methodSym)
parmSymbol->setOrdinal(ordinal++);

char *s = getParameterTypeSignature(parmIndex);
uint32_t len = strlen(s);
uint32_t len = static_cast<uint32_t>(strlen(s));
parmSymbol->setTypeSignature(s, len);

la.add(parmSymbol);
Expand Down
4 changes: 2 additions & 2 deletions compiler/control/OMROptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3494,15 +3494,15 @@ OMR::Options::processOption(
{
i->isOptionToFind = false;
if (!i->length)
i->length = strlen(i->name);
i->length = static_cast<int32_t>(strlen(i->name));
}

// Find the entry for this option string using a binary search

// Create an object for the option to find in the table and set attributes
TR::OptionTable optionToFind = TR::OptionTable();
optionToFind.name = startOption;
optionToFind.length = strlen(optionToFind.name);
optionToFind.length = static_cast<int32_t>(strlen(optionToFind.name));

// Since STL binary search requires total ordering, there need to be a way to differentiate
// between the option to find and an option in the table. The isOptionToFind field is used
Expand Down
4 changes: 2 additions & 2 deletions compiler/control/OMROptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,8 +1524,8 @@ class OMR_EXTENSIBLE Options
int64_t getDebugCounterWarmupSeconds(){ return _debugCounterWarmupSeconds; }
const char *debugCounterInsertedFormat(TR_Memory *mem, const char *name, const char *format)
{
int nameLen = strlen(name);
int formatLen = strlen(format);
auto nameLen = strlen(name);
auto formatLen = strlen(format);
char *result = (char*)mem->allocateMemory(nameLen + formatLen + 2, heapAlloc);
const char *splitPoint = strchr(name, '~');
if (splitPoint)
Expand Down
12 changes: 6 additions & 6 deletions compiler/cs2/arrayof.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ CS2_ARTEMP inline void CS2_BASEARDECL::GrowTo (size_t newSize) {

if (segmentMapIndex >= fMaxSegments) {
if (fSegmentMap == NULL) {
uint32_t updatedMaxSegments = segmentMapIndex + (fMaxSegments >> 1) + 1;
uint32_t updatedMaxSegments = static_cast<uint32_t>(segmentMapIndex + (fMaxSegments >> 1) + 1);
fSegmentMap = (DerivedElement **) Allocator::allocate ( updatedMaxSegments * sizeof(DerivedElement *));
fMaxSegments = updatedMaxSegments;
} else {
Expand All @@ -341,7 +341,7 @@ CS2_ARTEMP inline void CS2_BASEARDECL::GrowTo (size_t newSize) {
fMaxSegments * sizeof(DerivedElement *)
);
fSegmentMap = static_cast<DerivedElement **>(newSegmentMapAllocation);
fMaxSegments = maxSegments;
fMaxSegments = static_cast<uint32_t>(maxSegments);
}

if (fSegmentMap == NULL) {
Expand All @@ -353,7 +353,7 @@ CS2_ARTEMP inline void CS2_BASEARDECL::GrowTo (size_t newSize) {
newSegmentIndex < segmentMapIndex + 1;
++newSegmentIndex) {
fSegmentMap[newSegmentIndex] = (DerivedElement *) Allocator::allocate ( SegmentSize());
fNumberOfSegments = newSegmentIndex + 1;
fNumberOfSegments = static_cast<uint32_t>(newSegmentIndex + 1);
}

CS2Assert (segmentMapIndex + 1 == fNumberOfSegments,
Expand Down Expand Up @@ -382,7 +382,7 @@ CS2_ARTEMP inline void CS2_BASEARDECL::ShrinkTo (size_t newSize) {
Allocator::deallocate (fSegmentMap[segmentIndex], SegmentSize());
}

fNumberOfSegments = firstDeadSegment;
fNumberOfSegments = static_cast<uint32_t>(firstDeadSegment);

// When new new size is zero we don't need the segment map
if (fNumberOfSegments == 0) {
Expand Down Expand Up @@ -472,7 +472,7 @@ template <class AElementType, class Allocator, size_t segmentBits = 8, class Ini
typename CS2_BASEARDECL::DerivedElement *currentElement = CS2_BASEARDECL::DerivedElementAt(elementIndex);
new (currentElement) typename CS2_BASEARDECL::DerivedElement(fInitializer);
}
fNumInitialized = newSize;
fNumInitialized = static_cast<uint32_t>(newSize);
}

void MakeEmpty() { return ShrinkTo(0); }
Expand All @@ -483,7 +483,7 @@ template <class AElementType, class Allocator, size_t segmentBits = 8, class Ini
for (c.SetTo(newSize); c.Valid(); c.SetToNext())
c.DerivedElement()->~DerivedElement();

fNumInitialized = newSize;
fNumInitialized = static_cast<uint32_t>(newSize);
CS2_BASEARDECL::ShrinkTo(newSize);
}
}
Expand Down
37 changes: 19 additions & 18 deletions compiler/cs2/sparsrbit.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class ASparseBitVector : private Allocator {
Segment() : fSegment(NULL), fSize(0), fHighBits(0), fNumValues(0) { }
void allocate(size_t size, Allocator &a) {
fSegment = (uint16_t *) a.allocate(size * sizeof(uint16_t));
fSize = size;
fSize = static_cast<uint16_t>(size);
fNumValues = 0;
}
template <class S2>
Expand All @@ -257,7 +257,7 @@ class ASparseBitVector : private Allocator {
void append(S2 &s, uint16_t fromIndex, uint16_t toIndex) {
size_t n = toIndex - fromIndex;
memcpy(&fSegment[fNumValues], &s.Indices()[fromIndex], n * sizeof(uint16_t));
fNumValues += n;
fNumValues += static_cast<uint32_t>(n);
}

// append elements of s to this Segment
Expand All @@ -272,8 +272,8 @@ class ASparseBitVector : private Allocator {

void adopt(size_t numValues, size_t size, uint16_t *bits) {
fSegment = bits;
fSize = size;
fNumValues = numValues;
fSize = static_cast<uint16_t>(size);
fNumValues = static_cast<uint32_t>(numValues);
}

void adopt(uint16_t highbits, size_t numValues, size_t size, uint16_t *bits) {
Expand All @@ -296,7 +296,7 @@ class ASparseBitVector : private Allocator {
fSegment = (uint16_t *) a.reallocate(size*sizeof(uint16_t),
fSegment,
fSize * sizeof(uint16_t));
fSize = size;
fSize = static_cast<uint16_t>(size);
}

void deallocate(Allocator &a) { a.deallocate(fSegment, fSize*sizeof(uint16_t)); }
Expand Down Expand Up @@ -581,7 +581,7 @@ inline typename ASparseBitVector<Allocator>::SparseBitRef& ASparseBitVector<All
base[i].Indices()[0]=fIndex;

fVector.fBase = base;
fVector.fNumberOfSegments=n+1;
fVector.fNumberOfSegments=static_cast<SparseBitIndex>(n+1);

return *this;
}
Expand Down Expand Up @@ -700,7 +700,7 @@ inline void ASparseBitVector<Allocator>::Compact() {

template <class Allocator>
inline typename ASparseBitVector<Allocator>::SparseBitRef ASparseBitVector<Allocator>::operator[] (size_t index) {
return SparseBitRef (*this, index);
return SparseBitRef (*this, static_cast<SparseBitIndex>(index));
}

template <class Allocator>
Expand All @@ -712,8 +712,8 @@ template <class Allocator>
inline bool
ASparseBitVector<Allocator>::ValueAt(size_t elementIndex) const
{
Segment *s =FindSegment(elementIndex);
if (s) return GetSegment(*s, elementIndex);
Segment *s =FindSegment(static_cast<SparseBitIndex>(elementIndex));
if (s) return GetSegment(*s, static_cast<SparseBitIndex>(elementIndex));
return false;
}

Expand Down Expand Up @@ -932,7 +932,8 @@ template <class Allocator>
inline SparseBitIndex ASparseBitVector<Allocator>::PopulationCount (SparseBitIndex numBits) const{
CS2Assert(numBits==0xEFFFFFFFul,("Population count subset not implemented"));

size_t i, n = fNumberOfSegments, ret=0;
size_t i, n = fNumberOfSegments;
SparseBitIndex ret=0;
for (i=0; i<n; i++) {
Segment *s = &fBase[i];
ret += s->PopulationCount();
Expand Down Expand Up @@ -1059,27 +1060,27 @@ inline SparseBitIndex ASparseBitVector<Allocator>::FindIndex(const typename ASpa
CS2Assert(thisSegment.Indices(), ("Expecting non-null srbv segment"));
if (high==0) high=thisSegment.fNumValues-1;

if (search <= thisSegment.Indices()[low]) return low;
if (search == thisSegment.Indices()[high]) return high;
if (search > thisSegment.Indices()[high]) return high+1;
if (search <= thisSegment.Indices()[low]) return static_cast<SparseBitIndex>(low);
if (search == thisSegment.Indices()[high]) return static_cast<SparseBitIndex>(high);
if (search > thisSegment.Indices()[high]) return static_cast<SparseBitIndex>(high+1);

while (high-low > 16) {
size_t mid = (high+low)/2;
if (search < thisSegment.Indices()[mid]) high = mid;
else if (search > thisSegment.Indices()[mid]) low = mid;
else return mid;
else return static_cast<SparseBitIndex>(mid);
}

while (low<high && thisSegment.Indices()[low] < search) low+=1;
return low;
return static_cast<SparseBitIndex>(low);
}

// FindIndex gets the segment location of SparseBitIndex.
// If SparseBitIndex does not appear in the segment, finds the
// smallest bit in the segment that is larger or equal than search
template <class Allocator>
inline SparseBitIndex ASparseBitVector<Allocator>::AdvanceIndex(const typename ASparseBitVector<Allocator>::Segment &thisSegment, uint16_t s, SparseBitIndex l, SparseBitIndex h) const {
size_t search(s), low(l), high(h);
SparseBitIndex search(static_cast<SparseBitIndex>(s)), low(l), high(h);
if (high==0) high=thisSegment.fNumValues-1;

if (search >= thisSegment.Indices()[high]) {
Expand All @@ -1092,7 +1093,7 @@ inline SparseBitIndex ASparseBitVector<Allocator>::AdvanceIndex(const typename A
high = long(search - value) + low;

const unsigned long residue = 128; /* do linear search under this range */
size_t mid = (high+low)/2;
SparseBitIndex mid = (high+low)/2;

while (high-low > residue) {
value = thisSegment.Indices()[mid];
Expand Down Expand Up @@ -1230,7 +1231,7 @@ inline typename ASparseBitVector<Allocator>::Segment *ASparseBitVector<Allocator
base[i].fNumValues = 0;

fBase = base;
fNumberOfSegments = n+1;
fNumberOfSegments = static_cast<SparseBitIndex>(n+1);

return &base[i];
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/env/OMRClassEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ char *
OMR::ClassEnv::classNameChars(TR::Compilation *comp, TR::SymbolReference *symRef, int32_t & len)
{
char *name = "<no class name>";
len = strlen(name);
len = static_cast<int32_t>(strlen(name));
return name;
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/env/RegionProfiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RegionProfiler
"kbytesAllocated.details/%s",
_identifier
),
(_region.bytesAllocated() - _initialRegionSize) / 1024
static_cast<int32_t>((_region.bytesAllocated() - _initialRegionSize) / 1024)
);
TR::DebugCounter::incStaticDebugCounter(
&_compilation,
Expand All @@ -85,7 +85,7 @@ class RegionProfiler
"segmentAllocation.details/%s",
_identifier
),
(_region._segmentProvider.bytesAllocated() - _initialSegmentProviderSize) / 1024
static_cast<int32_t>((_region._segmentProvider.bytesAllocated() - _initialSegmentProviderSize) / 1024)
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/env/TRMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,8 @@ class TRMemoryAllocator {

if (scavenge) {
for (uint32_t i=b+1; i < maxbits; i++) {
uint32_t chunksize=0; uint32_t elements=0;
uint32_t elements=0;
if (freelist[i-minbits]) {
chunksize = bucketsize(i);
elements = (1 << (i-b)); // (2^i / 2^b)

// remove this segment from its freelist
Expand Down
2 changes: 1 addition & 1 deletion compiler/il/OMRNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2910,7 +2910,7 @@ OMR::Node::containsDoNotPropagateNode(vcount_t vc)
return true;
}

for (size_t i = 0; i < self()->getNumChildren(); i++)
for (auto i = 0; i < self()->getNumChildren(); i++)
{
if (self()->getChild(i)->containsDoNotPropagateNode(vc))
{
Expand Down
8 changes: 4 additions & 4 deletions compiler/ilgen/OMRIlBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ OMR::IlBuilder::VectorStoreAt(TR::IlValue *address, TR::IlValue *value)
TR::IlValue *
OMR::IlBuilder::CreateLocalArray(int32_t numElements, TR::IlType *elementType)
{
uint32_t size = numElements * elementType->getSize();
uint32_t size = static_cast<uint32_t>(numElements * elementType->getSize());
TR::SymbolReference *localArraySymRef = symRefTab()->createLocalPrimArray(size,
methodSymbol(),
8 /*FIXME: JVM-specific - byte*/);
Expand All @@ -726,7 +726,7 @@ TR::IlValue *
OMR::IlBuilder::CreateLocalStruct(TR::IlType *structType)
{
//similar to CreateLocalArray except writing a method in StructType to get the struct size
uint32_t size = structType->getSize();
uint32_t size = static_cast<uint32_t>(structType->getSize());
TR::SymbolReference *localStructSymRef = symRefTab()->createLocalPrimArray(size,
methodSymbol(),
8 /*FIXME: JVM-specific - byte*/);
Expand Down Expand Up @@ -838,7 +838,7 @@ OMR::IlBuilder::IndexAt(TR::IlType *dt, TR::IlValue *base, TR::IlValue *index)
TR::ILOpCodes op = TR::DataType::getDataTypeConversion(indexType, targetType);
indexNode = TR::Node::create(op, 1, indexNode);
}
elemSizeNode = TR::Node::iconst(elemType->getSize());
elemSizeNode = TR::Node::iconst(static_cast<int32_t>(elemType->getSize()));
addOp = TR::aiadd;
mulOp = TR::imul;
}
Expand Down Expand Up @@ -871,7 +871,7 @@ OMR::IlBuilder::StructFieldInstanceAddress(const char* structName, const char* f
}
else
{
offsetValue = ConstInt32(offset);
offsetValue = ConstInt32(static_cast<int32_t>(offset));
}
auto addr = Add(obj, offsetValue);
return ConvertTo(ptype, addr);
Expand Down
4 changes: 2 additions & 2 deletions compiler/ilgen/OMRTypeDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ OMR::StructType::getFieldSymRef(const char *fieldName)

char *fullName = (char *) comp->trMemory()->allocateHeapMemory((strlen(info->_name) + 1 + strlen(_name) + 1) * sizeof(char));
sprintf(fullName, "%s.%s", _name, info->_name);
TR::Symbol *symbol = TR::Symbol::createNamedShadow(comp->trHeapMemory(), type, info->_type->getSize(), fullName);
TR::Symbol *symbol = TR::Symbol::createNamedShadow(comp->trHeapMemory(), type, static_cast<uint32_t>(info->_type->getSize()), fullName);

// TBD: should we create a dynamic "constant" pool for accesses made by the method being compiled?
symRef = new (comp->trHeapMemory()) TR::SymbolReference(comp->getSymRefTab(), symbol, comp->getMethodSymbol()->getResolvedMethodIndex(), -1);
Expand Down Expand Up @@ -393,7 +393,7 @@ OMR::UnionType::getFieldSymRef(const char *fieldName)

char *fullName = (char *) comp->trMemory()->allocateHeapMemory((strlen(info->_name) + 1 + strlen(_name) + 1) * sizeof(char));
sprintf(fullName, "%s.%s", _name, info->_name);
TR::Symbol *symbol = TR::Symbol::createNamedShadow(comp->trHeapMemory(), type, info->_type->getSize(), fullName);
TR::Symbol *symbol = TR::Symbol::createNamedShadow(comp->trHeapMemory(), type, static_cast<uint32_t>(info->_type->getSize()), fullName);
symRef = new (comp->trHeapMemory()) TR::SymbolReference(symRefTab, symbol, comp->getMethodSymbol()->getResolvedMethodIndex(), -1);
symRef->setOffset(0);
symRef->setReallySharesSymbol();
Expand Down
2 changes: 1 addition & 1 deletion compiler/ilgen/OMRVirtualMachineRegisterInStruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class VirtualMachineRegisterInStruct : public TR::VirtualMachineRegister
TR::IlType *baseType = _integerTypeForAdjustments->baseType();
_integerTypeForAdjustments = b->typeDictionary()->getWord();
_isAdjustable = true;
_adjustByStep = baseType->getSize();
_adjustByStep = static_cast<uint32_t>(baseType->getSize());
}
else
{
Expand Down
Loading

0 comments on commit 5cefde1

Please sign in to comment.