-
Notifications
You must be signed in to change notification settings - Fork 261
Initial support to LLVM 21 #617
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
Conversation
|
@TheDan64 any chance to review and merge this with the goal to get it into the next crate release? We depend on a fix back-ported to LLVM 21. I'm happy to help out here too if needed. |
|
I can take a look in a few days. Just got back from a long trip |
TheDan64
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, but I had one comment I'd like to discuss
| /// let fn_value = module.add_function("my_fn", fn_type, None); | ||
| /// let string_attribute = context.create_string_attribute("my_key", "my_val"); | ||
| /// let enum_attribute = context.create_enum_attribute(1, 1); | ||
| /// // Enum attribute cannot have non-zero value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand - what's the point of the parameter if 0 is the only valid value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this comes from that assert in LLVM. AFAIK the idea is quite simple: single enum attribute cannot be parameterized and fully defines semantics of it; integer attribute can be parameterized and its semantics without parameter is not fully defined.
Not really sure how inkwell got away with it unless people built LLVM without asserts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's provided by the C api:
Line 351 in f88ccb2
| unsafe { Attribute::new(LLVMCreateEnumAttribute(self.0, kind_id, val)) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, if there are no other valid values we should remove it from the rust side entirely as a safety measure and add comments about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's provided by the C api:
Line 351 in f88ccb2
unsafe { Attribute::new(LLVMCreateEnumAttribute(self.0, kind_id, val)) }
As I can see, that API didn't change since 2016 and assert was added way later.
Anyway, if there are no other valid values we should remove it from the rust side entirely as a safety measure and add comments about it
I don't think we can easily remove it as there's no C API to build IntAttr, TypeAttr etc.
The worse part is there might be bad naming that was carried around: for example, there is LLVMGetLastEnumAttributeKind function that one might expect would return LastEnumAttr that is generated from tablegen file, but in reality it returns EndAttrKinds that includes EnumAttr, IntAttr, TypeAttr and ConstantRangeAttr.
That said, we may need to keep it and try to add some convenience C functions to either split LLVMCreateEnumAttribute into several functions such as LLVMCreateEnumAttribute, LLVMCreateIntAttribute etc or simply return nullptr if value cannot be used with attr kind or have LLVMGet[First|Last]EnumAttributeKind C Functions to be able to split inkwell's API into create_enum_attr(kind) and create_int_attr(kind, val)
TheDan64
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Description
Support LLVM 21.x
Related Issue
None
How This Has Been Tested
cargo testwas used to test changes. All test are passing.Checklist