Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global variable initializer type does not match global variable type #2108

Closed
MrSmith33 opened this issue May 11, 2017 · 12 comments
Closed

Global variable initializer type does not match global variable type #2108

MrSmith33 opened this issue May 11, 2017 · 12 comments

Comments

@MrSmith33
Copy link
Contributor

MrSmith33 commented May 11, 2017

Global variable initializer type does not match global variable type!
%voxelman.graphics.font.textmesher.TextMesherParams* @_D8voxelman8graphics4font10textmesher16TextMesherParams6__initZ
LLVM ERROR: Broken module found, compilation aborted!
ldc2 failed with exit code 1.

Fails on 1.2.0 and 1.3.0-beta1 on Windows
Upd: And 1.1.1

P.S. Can we have debug release?

@ennis
Copy link

ennis commented Jun 16, 2017

The following code seems to trigger the same error:

import std.stdio;

struct Vec
{
    float v; 
}

struct Quat
{
	union
	{
		Vec v;   // replacing this line with 'float v;' makes the error disappear
		struct
		{
			float x;
		}
	}

	@nogc static Quat identity() pure nothrow @property
	{
		Quat q;
		q.x = 1;  // commenting this line makes the error disappear
		return q;
	}
}

struct S 
{
	Quat q = Quat.identity;
}

static Quat q = Quat.identity;

void main()
{
}

Compiler output:

Global variable initializer type does not match global variable type!
%app.S* @_D3app1S6__initZ
LLVM ERROR: Broken module found, compilation aborted!

Output of ldc2 -version:

LDC - the LLVM D compiler (1.3.0-beta1):
based on DMD v2.073.2 and LLVM 3.9.1
built with LDC - the LLVM D compiler (1.3.0-beta1)
Default target: x86_64-pc-windows-msvc
Host CPU: haswell

@ennis
Copy link

ennis commented Jun 16, 2017

Reduced with dustmite:

struct Vec
{
}

struct Quat
{
	union
	{
		Vec v;
		struct
		{
			float x;
		}
	}

	static identity() 
	{
		Quat q;
		q.x = 1;
		return q;
	}
}

struct S 
{
	Quat q = Quat.identity;
}

Also fails on 1.3.0-beta2

@kinke
Copy link
Member

kinke commented Jun 16, 2017

Thank you very much @ennis.

@kinke
Copy link
Member

kinke commented Jun 16, 2017

struct Vec { float v; }

struct Quat
{
	union
	{
		Vec v;
		struct { float x; }
	}

	@nogc static Quat identity() pure nothrow @property
	{
		Quat q;
		q.x = 1; // q.v.v = 1;
		return q;
	}
}

struct S 
{
	Quat q = Quat.identity;
}

Crashes with initializer type mismatch. The commented-out code also crashes, but this time when generating the ModuleInfo... a jewel of a testcase. Almost certainly due to the union of course and the difficulty of expressing it in LLVM IR.

Edit: Sorry, the 2nd crash is due to a dirty source tree on my side, initializing the primary union member compiles fine with beta2.

@kinke
Copy link
Member

kinke commented Jun 16, 2017

The potentially multiple LL types for a single D union (and all aggregates containing it such as struct S), depending on which members are initialized, are also the reason for nasty issue #1829. We should probably look into how clang handles this.

kinke added a commit to kinke/ldc that referenced this issue Jun 17, 2017
Thereby allowing T.init with explicit initializers for dominated members in
nested unions, fixing issue ldc-developers#2108.
kinke added a commit to kinke/ldc that referenced this issue Jun 17, 2017
Thereby allowing T.init with explicit initializers for dominated members in
nested unions, fixing issue ldc-developers#2108.
kinke added a commit that referenced this issue Jul 15, 2017
Fix issue #2108 (triggered by T.init initializing dominated members in nested unions)
@kinke
Copy link
Member

kinke commented Jul 15, 2017

ennis' testcase fixed by #2171.

@MrSmith33: Please check again with Windows CI build 3897 here. It should be downloadable in about half an hour.

@MrSmith33
Copy link
Contributor Author

@kinke:
On first try I got LLVM ERROR: Could not acquire a cryptographic context: Unknown error (0x7F)
On second I and consecutive I get Error: out of memory
LDC uses only 1.8 Gigs of memory

@kinke
Copy link
Member

kinke commented Jul 16, 2017

Are you using the 64-bit build? And which Windows version?

@MrSmith33
Copy link
Contributor Author

MrSmith33 commented Jul 17, 2017

I downloaded LDC-master-3911-multilib.7z on Windows 10 64bit

@MrSmith33
Copy link
Contributor Author

I tried splitting project into two parts. One part still fails with .dub\obj\client.obj: not enough memory

@MrSmith33
Copy link
Contributor Author

It seems to compile now, but fails to link with some system libs, (possibly a dub bug)

I have "libs-windows": ["user32", "gdi32", "ws2_32", "winmm"], in dub.json

ws2_32.lib(WS2_32.dll) : error LNK2005: htons already defined in druntime-ldc.lib(winsock2.obj)
ws2_32.lib(WS2_32.dll) : error LNK2005: ntohs already defined in druntime-ldc.lib(winsock2.obj)
ws2_32.lib(WS2_32.dll) : error LNK2005: ntohl already defined in druntime-ldc.lib(winsock2.obj)
ws2_32.lib(WS2_32.dll) : error LNK2005: htonl already defined in druntime-ldc.lib(winsock2.obj)
   Creating library .dub\build\application-debug-windows-x86_64-ldc_2073-0BF793B79011CBF99FDC78FD7F053D86\editor.lib and object .dub\build\application-debug-windows-x86_64-ldc_2073-0BF793B79011CBF99FDC78FD7F053D86\editor.exp
cimgui.lib(imgui.obj) : error LNK2019: unresolved external symbol _vacopy referenced in function "public: void __cdecl ImGuiTextBuffer::appendv(char const *,char *)" (?appendv@ImGuiTextBuffer@@QEAAXPEBDPEAD@Z)
enet.lib(win32.o) : error LNK2019: unresolved external symbol __imp_timeBeginPeriod referenced in function enet_initialize
enet.lib(win32.o) : error LNK2019: unresolved external symbol __imp_timeEndPeriod referenced in function enet_deinitialize
enet.lib(win32.o) : error LNK2019: unresolved external symbol __imp_timeGetTime referenced in function enet_host_random_seed
.dub\build\application-debug-windows-x86_64-ldc_2073-0BF793B79011CBF99FDC78FD7F053D86\editor.exe : fatal error LNK1120: 4 unresolved externals
Error: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe failed with status: 1120
ldc2 failed with exit code 1120.

@kinke
Copy link
Member

kinke commented Jul 18, 2017

Alright, the original issue seems to be fixed as expected then, thanks for confirming -> closing.

@kinke kinke closed this as completed Jul 18, 2017
thewilsonator pushed a commit to thewilsonator/ldc that referenced this issue Jul 28, 2017
Thereby allowing T.init with explicit initializers for dominated members in
nested unions, fixing issue ldc-developers#2108.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants