Procházet zdrojové kódy

Fixed const stride issues

Brian Fiete před 4 roky
rodič
revize
8c700e6deb

+ 6 - 0
IDEHelper/Backend/BeCOFFObject.cpp

@@ -1880,8 +1880,14 @@ void BeCOFFObject::WriteConst(BeCOFFSection& sect, BeConstant* constVal)
 		}
 		else if (constStruct->mType->mTypeCode == BeTypeCode_SizedArray)
 		{
+			BeSizedArrayType* arrayType = (BeSizedArrayType*)constStruct->mType;
 			for (auto& memberVal : constStruct->mMemberValues)
+			{
 				WriteConst(sect, memberVal);
+				int padding = arrayType->mElementType->GetStride() - arrayType->mElementType->mSize;
+				if (padding > 0)
+					sect.mData.WriteZeros(padding);
+			}
 		}
 		else
 			BF_FATAL("Invalid StructConst type");

+ 4 - 2
IDEHelper/Backend/BeIRCodeGen.cpp

@@ -899,8 +899,10 @@ void BeIRCodeGen::Read(BeValue*& beValue)
 		}
 		else if (constType == BfConstType_Undef)
 		{
-			CMD_PARAM(BeType*, type);
-			beValue = mBeModule->CreateUndefValue(type);
+			CMD_PARAM(BeType*, type);			
+			auto constUndef = mBeModule->mOwnedValues.Alloc<BeUndefConstant>();
+			constUndef->mType = type;
+			beValue = constUndef;
 			return;
 		}
 		else if (constType == BfConstType_TypeOf)

+ 1 - 1
IDEHelper/Backend/BeMCContext.cpp

@@ -2949,7 +2949,7 @@ void BeMCContext::CreateStore(BeMCInstKind instKind, const BeMCOperand& val, con
 					//AllocInst(instKind, destOperand, elementVal);
 					CreateStore(instKind, elementVal, destOperand);
 
-					offset += elemType->mSize;
+					offset += elemType->GetStride();
 				}
 				return;
 			}

+ 10 - 0
IDEHelper/Backend/BeModule.cpp

@@ -1348,6 +1348,16 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
 		return;
 	}
 
+	if (auto constant = BeValueDynCast<BeUndefConstant>(value))
+	{
+		if (showType)
+		{
+			BeModule::ToString(str, constant->mType);
+			str += " ";
+		}
+		str += "undef";
+	}
+
 	if (auto constant = BeValueDynCast<BeCastConstant>(value))
 	{ 		
 		ToString(str, constant->mType);

+ 13 - 0
IDEHelper/Backend/BeModule.h

@@ -403,12 +403,25 @@ public:
 	virtual void HashContent(BeHashContext& hashCtx) override
 	{
 		hashCtx.Mixin(TypeId);
+		hashCtx.Mixin(mType);
 		hashCtx.Mixin(mMemberValues.size());
 		for (auto member : mMemberValues)
 			member->HashReference(hashCtx);
 	}
 };
 
+class BeUndefConstant : public BeConstant
+{
+public:
+	BE_VALUE_TYPE(BeUndefConstant, BeConstant);
+	
+	virtual void HashContent(BeHashContext& hashCtx) override
+	{
+		hashCtx.Mixin(mType);
+		hashCtx.Mixin(TypeId);		
+	}
+};
+
 class BeStringConstant : public BeConstant
 {
 public: