Browse Source

Mangle fixes

Brian Fiete 1 year ago
parent
commit
0bed50cf7c
2 changed files with 37 additions and 15 deletions
  1. 36 13
      IDEHelper/Compiler/BfMangler.cpp
  2. 1 2
      IDEHelper/Compiler/BfModule.cpp

+ 36 - 13
IDEHelper/Compiler/BfMangler.cpp

@@ -914,13 +914,16 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst)
 		prefixLen = true;
 	}
 
-	if (methodDef->mCheckedKind == BfCheckedKind_Checked)
-		name += "`CHK";
-	else if (methodDef->mCheckedKind == BfCheckedKind_Unchecked)
-		name += "`UCHK";
+	if (!mangleContext.mCPPMangle)
+	{
+		if (methodDef->mCheckedKind == BfCheckedKind_Checked)
+			name += "`CHK";
+		else if (methodDef->mCheckedKind == BfCheckedKind_Unchecked)
+			name += "`UCHK";
 
-	if (methodDef->mHasComptime)
-		name += "`COMPTIME";
+		if (methodDef->mHasComptime)
+			name += "`COMPTIME";
+	}
 
 	if (((methodInst->GetOwner()->mTypeDef->IsGlobalsContainer()) &&
 		 ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_Dtor) || (methodDef->mName == BF_METHODNAME_MARKMEMBERS_STATIC))) ||
@@ -1021,12 +1024,22 @@ String BfGNUMangler::Mangle(BfMethodInstance* methodInst)
 			HandleParamCustomAttributes(paramDecl->mAttributes, false, isConst);
 		}
 
-		auto paramKind = methodInst->GetParamKind(paramIdx);
-		if (paramKind == BfParamKind_Params)
-			name += "U6params";
-		else if (paramKind == BfParamKind_DelegateParam)
-			name += "U5param";
-		Mangle(mangleContext, name, paramType, NULL, isConst);
+		if (!mangleContext.mCPPMangle)
+		{
+			auto paramKind = methodInst->GetParamKind(paramIdx);
+			if (paramKind == BfParamKind_Params)
+				name += "U6params";
+			else if (paramKind == BfParamKind_DelegateParam)
+				name += "U5param";
+		}
+
+		if ((paramType->IsVoid()) && (methodInst->GetParamCount() == 1))
+		{
+			// Avoid collision between 'Method()' and 'Method(void)'
+			name += "U4void";
+		}
+		else
+			Mangle(mangleContext, name, paramType, NULL, isConst);
 	}
 	if ((methodInst->GetParamCount() == 0) && (!doExplicitThis))
 		name += 'v';
@@ -2232,8 +2245,10 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho
 		{
 			Mangle(mangleContext, name, typeInst->GetUnderlyingType(), true);
 		}
-		for (auto& param : methodInst->mParams)
+
+		for (int paramIdx = 0; paramIdx < methodInst->mParams.mSize; paramIdx++)
 		{
+			auto& param = methodInst->mParams[paramIdx];
 			bool isConst = false;
 			if ((param.mParamDefIdx >= 0) && (methodDeclaration != NULL) && (param.mParamDefIdx < methodDeclaration->mParams.mSize))
 			{
@@ -2241,6 +2256,14 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho
 				HandleParamCustomAttributes(paramDecl->mAttributes, false, isConst);
 			}
 
+			if (!mangleContext.mCPPMangle)
+			{
+				auto paramKind = methodInst->GetParamKind(paramIdx);
+				if (paramKind == BfParamKind_Params)
+					name += "Tparams@@";
+				else if (paramKind == BfParamKind_DelegateParam)
+					name += "Tparam@@";
+			}
 			Mangle(mangleContext, name, param.mResolvedType, true, isConst);
 		}
 		name += '@';

+ 1 - 2
IDEHelper/Compiler/BfModule.cpp

@@ -23374,9 +23374,8 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
 					mCurMethodInstance->mMangleWithIdx = true;
 				mangledName.Clear();
 				BfMangler::Mangle(mangledName, mCompiler->GetMangleKind(), mCurMethodInstance);
-				prevFunc = mBfIRBuilder->GetFunction(mangledName);
 
-				BfLogSysM("Function collision forced mangleWithIdx for %p: %d\n", methodInstance, prevFunc.mId);
+				BfLogSysM("Function collision forced mangleWithIdx for %p: %d GenericArgs: %d Unspecialized: %d\n", methodInstance, prevFunc.mId, methodInstance->GetNumGenericArguments(), methodInstance->mIsUnspecialized);
 			}
 			else
 			{