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

Error assigning an integer values to pointer in the LLVM code emitter #280

Open
zamabuvaraeu opened this issue Jan 5, 2021 · 2 comments

Comments

@zamabuvaraeu
Copy link
Contributor

There is a source code:

Function EntryPoint Alias "EntryPoint"()As Integer
	
	Dim pValue As Integer Ptr = CPtr(Integer Ptr, 0)
	
	Return 0
	
End Function

When compiling with the "-gen lvm " option and then compiling via "clang.exe -c -S EntryPoint.ll -o EntryPoint.asm" returns an error:

EntryPoint.ll:29:13: error: integer constant must have integer type
        store i64* 0, i64** %PVALUE.1
                   ^
1 error generated.

In the generated code, we find:

%FBSTRING = type { i8*, i64, i64 }
declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i32, i1) nounwind


%fb_RTTI$ = type { i8*, i8*, %fb_RTTI$* }
@__fb_ZTS6Object = global %fb_RTTI$ zeroinitializer
@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 0, void ()* @fb_ctor__EntryPoint }]

define i64 @EntryPoint(  ) nounwind
{

	; localvar fb$result
	%fb$result.0 = alloca i64

	; localvar PVALUE
	%PVALUE.1 = alloca i64*

	; addrof fb$result

	; memclear fb$result
	%vr1 = bitcast i64* %fb$result.0 to i8*
	call void @llvm.memset.p0i8.i32( i8* %vr1, i8 0, i32 8, i32 1, i1 false )

	; label .Lt_0004
	br label %.Lt_0004
.Lt_0004:

	; store PVALUE := 20
	store i64* 0, i64** %PVALUE.1

	; store fb$result := 0
	store i64 0, i64* %fb$result.0

	; goto .Lt_0005
	br label %.Lt_0005
.Lt_0006:

	; label .Lt_0005
	br label %.Lt_0005
.Lt_0005:

	; loadres fb$result
	%vr3 = load i64, i64* %fb$result.0
	ret i64 %vr3
}

And it should be like this:

store i64* inttoptr (i64 0 to i64*), i64** %1, align 8

Clang also throws an error on strings:

@__fb_ZTS6Object = global %fb_RTTI$ zeroinitializer
@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 0, void ()* @fb_ctor__EntryPoint }]

If you remove them, the compilation will be successful.

@zamabuvaraeu
Copy link
Contributor Author

zamabuvaraeu commented Oct 22, 2021

EntryPoint.ll:8:100: error: use of undefined value '@fb_ctor__EntryPoint'
@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 0, void ()* @"<U+0001>fb_ctor__EntryPoint" }]
                                                                                                   ^
1 error generated.

@zamabuvaraeu
Copy link
Contributor Author

I think constructors and destructors need to be declared before use.

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

1 participant