Skip to content

PGO fails with "cannot guarantee tail call due to mismatched varargs" #131155

Open
@akaStiX

Description

@akaStiX

When compiling Unreal Engine based project with PGO and LTO we get this error:

cannot guarantee tail call due to mismatched varargs
  musttail call void @"?TimerUpdate@UDataRegistry@@MEAAXXZ"(ptr noundef %0, ...) #51, !dbg !44172
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Exception Code: 0xC000001D
 #0 0x00007ff79d18f7f6 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x210f7f6)
 #1 0x00007ffe29b3bab4 (C:\Windows\System32\ucrtbase.dll+0x7bab4)
 #2 0x00007ffe29b3ca81 (C:\Windows\System32\ucrtbase.dll+0x7ca81)
 #3 0x00007ff79d191c95 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x2111c95)
 #4 0x00007ff79d0ff7a4 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x207f7a4)
 #5 0x00007ff79d2bbf6c xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x223bf6c)
 #6 0x00007ff79d26324a xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x21e324a)
 #7 0x00007ff79d29b199 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x221b199)
 #8 0x00007ff79d25c828 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x21dc828)
 #9 0x00007ff79d25fb72 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x21dfb72)
#10 0x00007ff79d1dfb6a xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x215fb6a)
#11 0x00007ff79d1df1f3 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x215f1f3)
#12 0x00007ff79d1dec66 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x215ec66)
#13 0x00007ff79d358a0e xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x22d8a0e)
#14 0x00007ff79d358e91 xmlLinkGetData (d:\build\AutoSDK\Sync\HostWin64\Win64\LLVM\18.1.8\bin\lld-link.exe+0x22d8e91)
#15 0x00007ffe29ae6b4c (C:\Windows\System32\ucrtbase.dll+0x26b4c)
#16 0x00007ffe2b284de0 (C:\Windows\System32\KERNEL32.DLL+0x14de0)
#17 0x00007ffe2c2dec4b (C:\Windows\SYSTEM32\ntdll.dll+0x7ec4b)

Here's the code:

class UDataRegistry : public UObject
{
	virtual void TimerUpdate();
}

class UDataRegistrySource : public UObject
{
	virtual void TimerUpdate();
}

// please note that the class UObject doesn't have TimerUpdate method

void UDataRegistry::TimerUpdate()
{
	float CurrentTime = GetCurrentTime();

	for (int32 i = 0; i < RuntimeSources.Num(); i++)
	{
		UDataRegistrySource* Source = RuntimeSources[i];
		if (Source)
		{
			Source->TimerUpdate(CurrentTime, TimerUpdateFrequency);
		}
	}
}

For some reason LLVM toolchain assumes that it's safe to add musttail optimization to a Source->TimerUpdate, albeit this call clearly doesn't qualify for it.

Seems to be introduced by this change 0b2473936d3660ad and without it, llvm would silently produce bogus code

Metadata

Metadata

Assignees

No one assigned

    Labels

    PGOProfile Guided Optimizations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions