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

Question about %jmp_buf size in the setjmp/longjmp example code #32

Open
JOE1994 opened this issue Jan 21, 2020 · 3 comments
Open

Question about %jmp_buf size in the setjmp/longjmp example code #32

JOE1994 opened this issue Jan 21, 2020 · 3 comments

Comments

@JOE1994
Copy link

JOE1994 commented Jan 21, 2020

Hello ,
first of all, thank you for sharing and maintaining this gitbook! 😄 😸

I noticed that in the setjmp/longjmp example code, jmp_buf is set and used as a single i32 variable.

%jmp_buf = type { i32 }
declare i32 @setjmp(%jmp_buf* %env)
declare void @longjmp(%jmp_buf* %env, i32 %val)
define i32 @main(i32 %argc, i8** %argv) nounwind {
	; "try" keyword expands to a call to @setjmp
	%env = alloca %jmp_buf
	%status = call i32 @setjmp(%jmp_buf* %env)
	%1 = icmp eq i32 %status, 0
	br i1 %1, label %.body, label %.catch_block

The LLVM docs on setjmp mentions that the single parameter to the setjmp intrinsic (i32 @llvm.eh.sjlj.setjmp(i8* %setjmp_buf)) is a pointer to a five word buffer in which the calling context is saved.
Following the documentation, shouldn't the size of jmp_buf be set to an array [5 x i32] ?
(assuming a 32-bit system)

Thank you for reading!

@archfrog
Copy link
Collaborator

I think you're right :)

It has been some years since I wrote that example and obviously it never ran. Or, if it ran, it must have been sheer luck :-) I don't know what went through my head, perhaps I just put in i32 with the intent of fixing it later and then forgot about it.

If you want to, you can submit a pull request with the fixed code.

@JOE1994
Copy link
Author

JOE1994 commented Jan 21, 2020

I'll try to submit a PR soon !

@archfrog
Copy link
Collaborator

Thank you!

archfrog added a commit to archfrog/mapping-high-level-constructs-to-llvm-ir that referenced this issue Oct 28, 2021
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

2 participants