Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kvpanch
Copy link
Contributor

@kvpanch kvpanch commented Oct 27, 2025

Description

Support LLVM 21.x

Related Issue

None

How This Has Been Tested

cargo test was used to test changes. All test are passing.

Checklist

@xermicus
Copy link
Contributor

@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.

@TheDan64
Copy link
Owner

I can take a look in a few days. Just got back from a long trip

@TheDan64 TheDan64 self-requested a review October 31, 2025 04:22
@TheDan64 TheDan64 added this to the 0.7.0 milestone Oct 31, 2025
Copy link
Owner

@TheDan64 TheDan64 left a 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
Copy link
Owner

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?

Copy link
Contributor Author

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

Copy link
Owner

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:

unsafe { Attribute::new(LLVMCreateEnumAttribute(self.0, kind_id, val)) }

Copy link
Owner

@TheDan64 TheDan64 Oct 31, 2025

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

Copy link
Contributor Author

@kvpanch kvpanch Nov 1, 2025

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:

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)

Copy link
Owner

@TheDan64 TheDan64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@TheDan64 TheDan64 merged commit 0079487 into TheDan64:master Nov 1, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants