Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 7930a09

Browse files
committed
make getHeapNameAndIndex consistently use Bytes+Integer, instead of sometimes using Bytes+implicit type
1 parent 0789708 commit 7930a09

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

lib/Target/JSBackend/JSBackend.cpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ namespace {
564564
/// @return The index to the heap HeapName for the memory access.
565565
std::string getHeapNameAndIndex(const Value *Ptr, const char **HeapName);
566566

567-
// Like getHeapNameAndIndex(), but uses the given memory operation size instead of the one from Ptr.
568-
std::string getHeapNameAndIndex(const Value *Ptr, const char **HeapName, unsigned Bytes);
567+
// Like getHeapNameAndIndex(), but uses the given memory operation size and whether it is an Integer instead of the type of Ptr.
568+
std::string getHeapNameAndIndex(const Value *Ptr, const char **HeapName, unsigned Bytes, bool Integer);
569569

570570
/// Like getHeapNameAndIndex(), but for global variables only.
571-
std::string getHeapNameAndIndexToGlobal(const GlobalVariable *GV, const Type *T, const char **HeapName);
571+
std::string getHeapNameAndIndexToGlobal(const GlobalVariable *GV, unsigned Bytes, bool Integer, const char **HeapName);
572572

573573
/// Like getHeapNameAndIndex(), but for pointers represented in string expression form.
574574
static std::string getHeapNameAndIndexToPtr(const std::string& Ptr, unsigned Bytes, bool Integer, const char **HeapName);
@@ -982,12 +982,10 @@ static inline const char *getHeapShiftStr(int Bytes)
982982
}
983983
}
984984

985-
std::string JSWriter::getHeapNameAndIndexToGlobal(const GlobalVariable *GV, const Type *T, const char **HeapName)
985+
std::string JSWriter::getHeapNameAndIndexToGlobal(const GlobalVariable *GV, unsigned Bytes, bool Integer, const char **HeapName)
986986
{
987-
Type *t = cast<PointerType>(T)->getElementType();
988-
unsigned Bytes = DL->getTypeAllocSize(t);
989987
unsigned Addr = getGlobalAddress(GV->getName().str());
990-
*HeapName = getHeapName(Bytes, t->isIntegerTy() || t->isPointerTy());
988+
*HeapName = getHeapName(Bytes, Integer);
991989
if (!Relocatable) {
992990
return utostr(Addr >> getHeapShift(Bytes));
993991
} else {
@@ -1001,24 +999,21 @@ std::string JSWriter::getHeapNameAndIndexToPtr(const std::string& Ptr, unsigned
1001999
return Ptr + getHeapShiftStr(Bytes);
10021000
}
10031001

1004-
std::string JSWriter::getHeapNameAndIndex(const Value *Ptr, const char **HeapName, unsigned Bytes)
1002+
std::string JSWriter::getHeapNameAndIndex(const Value *Ptr, const char **HeapName, unsigned Bytes, bool Integer)
10051003
{
1006-
Type *t = cast<PointerType>(Ptr->getType())->getElementType();
1007-
10081004
const GlobalVariable *GV;
10091005
if ((GV = dyn_cast<GlobalVariable>(Ptr->stripPointerCasts())) && GV->hasInitializer()) {
10101006
// Note that we use the type of the pointer, as it might be a bitcast of the underlying global. We need the right type.
1011-
return getHeapNameAndIndexToGlobal(GV, Ptr->getType(), HeapName);
1007+
return getHeapNameAndIndexToGlobal(GV, Bytes, Integer, HeapName);
10121008
} else {
1013-
return getHeapNameAndIndexToPtr(getValueAsStr(Ptr), Bytes, t->isIntegerTy() || t->isPointerTy(), HeapName);
1009+
return getHeapNameAndIndexToPtr(getValueAsStr(Ptr), Bytes, Integer, HeapName);
10141010
}
10151011
}
10161012

10171013
std::string JSWriter::getHeapNameAndIndex(const Value *Ptr, const char **HeapName)
10181014
{
10191015
Type *t = cast<PointerType>(Ptr->getType())->getElementType();
1020-
unsigned Bytes = DL->getTypeAllocSize(t);
1021-
return getHeapNameAndIndex(Ptr, HeapName, Bytes);
1016+
return getHeapNameAndIndex(Ptr, HeapName, DL->getTypeAllocSize(t), t->isIntegerTy() || t->isPointerTy());
10221017
}
10231018

10241019
static const char *heapNameToAtomicTypeName(const char *HeapName)
@@ -1293,7 +1288,7 @@ std::string JSWriter::getHeapAccess(const std::string& Name, unsigned Bytes, boo
12931288

12941289
std::string JSWriter::getShiftedPtr(const Value *Ptr, unsigned Bytes) {
12951290
const char *HeapName = 0; // unused
1296-
return getHeapNameAndIndex(Ptr, &HeapName, Bytes);
1291+
return getHeapNameAndIndex(Ptr, &HeapName, Bytes, true /* Integer; doesn't matter */);
12971292
}
12981293

12991294
std::string JSWriter::getPtrUse(const Value* Ptr) {

0 commit comments

Comments
 (0)