Prechádzať zdrojové kódy

Fixed packing issue, made Packed infer Ordered

Brian Fiete 5 rokov pred
rodič
commit
cf7914f71a

+ 5 - 1
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -2146,6 +2146,8 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 	bool isCRepr = false;
 	bool isOrdered = false;
 	ProcessTypeInstCustomAttributes(isPacked, isUnion, isCRepr, isOrdered);
+	if (isPacked) // Packed infers ordered
+		isOrdered = true;
 	typeInstance->mIsUnion = isUnion;
 	if ((typeInstance->IsEnum()) && (typeInstance->IsStruct()))
 		typeInstance->mIsUnion = true;
@@ -2783,7 +2785,9 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 
 			bool needsExplicitAlignment = !isCRepr || resolvedFieldType->NeedsExplicitAlignment();
 
-			int nextDataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
+			int nextDataPos = dataPos;
+			if (!isPacked)
+				nextDataPos = (dataPos + (alignSize - 1)) & ~(alignSize - 1);
 			int padding = nextDataPos - dataPos;
 			if ((alignSize > 1) && (needsExplicitAlignment) && (padding > 0))
 			{				

+ 11 - 0
IDEHelper/Tests/src/Structs.bf

@@ -111,6 +111,13 @@ namespace Tests
 			int8 mD;
 		}
 
+		[Packed]
+		struct StructJ
+		{
+			int8 mA;
+			int32 mB;
+		}
+
 		[Test]
 		static void TestBasics()
 		{
@@ -153,6 +160,10 @@ namespace Tests
 			Test.Assert(sizeof(StructI) == 16);
 			Test.Assert(alignof(StructI) == 4);
 			Test.Assert(strideof(StructI) == 16);
+
+			Test.Assert(sizeof(StructJ) == 5);
+			Test.Assert(alignof(StructJ) == 1);
+			Test.Assert(strideof(StructJ) == 5);
 		}
 
 		public int Test<T>(T val)