0

I have some code that was previously compiled and working in C++Builder 6. I want to recompile it in 10.4.2 and build 32-bit and 64-bit Windows targets.

The existing code compiles using the classic compiler, but when I try to compile with the clang compiler, I am getting the dreaded ICE:

Internal compiler error: 0 @ 00000000

By using #ifdefs to remove sections of code, I have tracked it down to the way the functions are declared. Nothing I have tried works, which makes me think I must have missed something very fundamental.

The original code that still works with the classic compiler:

extern "C" {
BOOL WINAPI __declspec(dllexport) GetLogonSIDFromToken (HANDLE hToken, PSID *ppsid);
BOOL WINAPI __declspec(dllexport) GetCurrentProcessLogonSID (PSID *ppsid);
BOOL WINAPI __declspec(dllexport) GetLogonSIDFromAccountName(char *lpszUserName, PSID *ppsid);
VOID WINAPI __declspec(dllexport) FreeLogonSID (PSID *ppsid);
PSECURITY_DESCRIPTOR WINAPI __declspec(dllexport) AddAceToNewSecurityDescriptor(PSECURITY_DESCRIPTOR psd, PSID psid, DWORD dwType, DWORD dwFlags, DWORD dwMask);
BOOL WINAPI __declspec(dllexport) SetUserObjectNullDacl(HANDLE hObject);
BOOL WINAPI __declspec(dllexport) AddAceToUserObject(HANDLE hObject, PSID psid, DWORD dwType, DWORD dwFlags, DWORD dwMask);
BOOL WINAPI __declspec(dllexport) AddAceToWindowStation(HWINSTA hwinsta, PSID psid);
BOOL WINAPI __declspec(dllexport) AddAceToDesktop(HDESK hdesk, PSID psid);
}

Now I have tried lots of things, and looked into the Windows SDK headers, but if I put this into my code:

extern "C" {
// this is lifted directly from winbase.h
WINADVAPI
BOOL
WINAPI
LogonUserExW (
    _In_            LPCWSTR lpszUsername,
    _In_opt_        LPCWSTR lpszDomain,
    _In_opt_        LPCWSTR lpszPassword,
    _In_            DWORD dwLogonType,
    _In_            DWORD dwLogonProvider,
    _Outptr_opt_ PHANDLE phToken,
    _Outptr_opt_ PSID  *ppLogonSid,
    _Outptr_opt_result_bytebuffer_all_(*pdwProfileLength) PVOID *ppProfileBuffer,
    _Out_opt_       LPDWORD pdwProfileLength,
    _Out_opt_       PQUOTA_LIMITS pQuotaLimits
    );

/*
BOOL
WINAPI
GetLogonSIDFromToken(
    _In_ HANDLE hToken,
    _Outptr_opt_ PSID *ppsid
    );
*/
/*
BOOL
APIENTRY
GetLogonSIDFromToken(
    _In_ HANDLE hToken,
    _Outptr_opt_ PSID *ppsid
    );
*/}

It compiles fine (but obviously doesn't have declarations for my functions), but if I uncomment either the second or third declaration, I get the ICE error.

Can anyone provide any pointers (no pun intended) for me, please?

4
  • Could it be that you have some project paths still pointing at classic include directories or library directories or similar?
    – Ted Lyngmo
    Dec 1, 2021 at 16:49
  • Thanks for the thought Ted, I don't think that's the case, the only headers I am using that are not shipped with the product is this one. I can't see how the inclusion of another header or path would mean the compiler is happy to accept the first declaration (a Windows API call) but no variation (that I have tried) of my own declared function. Dec 2, 2021 at 9:44
  • Ok, it was a long shot :)
    – Ted Lyngmo
    Dec 2, 2021 at 10:19
  • 1
    Found the issue which is not at all what I expected … I will post an answer. Dec 2, 2021 at 13:43

1 Answer 1

1

It's not what it looks like.

The code compiles fine with no function declarations in the header, but the problem is not in the header itself. There are two functions in the file that use __try __finally (Microsoft extensions) which are officially supported by clang, but in one of them there was a label at the beginning of the __finally block. Removing the label allowed the code to compile.

__finally
{
blockexit:
  ...

Removing the blockexit: label allows the code to compile.

I have no idea why the code compiles fine if there are no function declarations in the header ...

Thanks to all who looked at this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.