Преглед на файлове

Fixed const string bitcast failure

Brian Fiete преди 9 месеца
родител
ревизия
3864a8896b
променени са 3 файла, в които са добавени 32 реда и са изтрити 2 реда
  1. 8 2
      IDEHelper/Compiler/BfConstResolver.cpp
  2. 23 0
      IDEHelper/Compiler/BfModule.cpp
  3. 1 0
      IDEHelper/Compiler/BfModule.h

+ 8 - 2
IDEHelper/Compiler/BfConstResolver.cpp

@@ -184,7 +184,13 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
 		if (isConst)
 		{
 			auto constant = mModule->mBfIRBuilder->GetConstant(mResult.mValue);
-			if ((constant->mConstType == BfConstType_GlobalVar) && ((flags & BfConstResolveFlag_AllowGlobalVariable) == 0))
+
+			if ((constant->mTypeCode != BfTypeCode_StringId) && (mModule->HasStringId(mResult.mValue, mModule->mBfIRBuilder)))
+			{
+				mModule->Fail("Invalid usage of string constant", expr);				
+				mResult = BfTypedValue();
+			}
+			else if ((constant->mConstType == BfConstType_GlobalVar) && ((flags & BfConstResolveFlag_AllowGlobalVariable) == 0))
 			{
 				int stringId = mModule->GetStringPoolIdx(mResult.mValue, mModule->mBfIRBuilder);
 				if (stringId != -1)
@@ -193,7 +199,7 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
 				}
 				else
 					isConst = false;
-			}
+			}			
 		}
 
 		if ((!isConst) && ((mBfEvalExprFlags & BfEvalExprFlags_AllowNonConst) == 0))

+ 23 - 0
IDEHelper/Compiler/BfModule.cpp

@@ -1766,6 +1766,29 @@ BfIRValue BfModule::CreateStringObjectValue(const StringImpl& str, int stringId,
 	return stringValLiteral;
 }
 
+bool BfModule::HasStringId(BfIRValue constantStr, BfIRConstHolder* constHolder)
+{
+	if (constHolder == NULL)
+		constHolder = mBfIRBuilder;
+
+	auto constant = constHolder->GetConstant(constantStr);
+	if (constant == NULL)
+		return false;
+
+	while (constant->mConstType == BfConstType_BitCast)
+	{
+		auto constBitCast = (BfConstantBitCast*)constant;
+		constant = constHolder->GetConstantById(constBitCast->mTarget);
+	}
+
+	if (constant->mTypeCode == BfTypeCode_StringId)
+	{
+		return true;
+	}
+
+	return false;
+}
+
 int BfModule::GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder)
 {
 	if (constHolder == NULL)

+ 1 - 0
IDEHelper/Compiler/BfModule.h

@@ -1652,6 +1652,7 @@ public:
 	void FixConstValueParams(BfTypeInstance* typeInst, SizedArrayImpl<BfIRValue>& valueParams, bool fillInPadding = false);
 	BfIRValue CreateStringObjectValue(const StringImpl& str, int stringId, bool define);
 	BfIRValue CreateStringCharPtr(const StringImpl& str, int stringId, bool define);
+	bool HasStringId(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
 	int GetStringPoolIdx(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
 	String* GetStringPoolString(BfIRValue constantStr, BfIRConstHolder* constHolder = NULL);
 	BfIRValue GetStringCharPtr(int stringId, bool force = false);