Skip to content

Preliminary LLVM 19/20 support#557

Merged
TheDan64 merged 35 commits intoTheDan64:masterfrom
stevefan1999-personal:master
Aug 9, 2025
Merged

Preliminary LLVM 19/20 support#557
TheDan64 merged 35 commits intoTheDan64:masterfrom
stevefan1999-personal:master

Conversation

@stevefan1999-personal
Copy link
Contributor

@stevefan1999-personal stevefan1999-personal commented Dec 13, 2024

Description

Adds preliminary LLVM 19/20 support so that https://github.com/jamesmth/llvm-plugin-rs can build plugin with it. No new features have been added so far.

I've also added nextest and replaced some CI with caching, so now the CI pipeline for testing is faster now.

No new LLVM 19 features have been tested, hence "preliminary" in the sense that it is not a very complete port, but it should be at least backward compatible with existing LLVM API

Related Issue

#530

How This Has Been Tested

Not yet

Option<Breaking Changes>

Checklist

@stevefan1999-personal
Copy link
Contributor Author

stevefan1999-personal commented Dec 14, 2024

I used a simple JIT example from README and it works. Looking good already but still need unit tests

@stevefan1999-personal
Copy link
Contributor Author

@TheDan64 Should the feature base name be renamed as llvm19-1? Looks like LLVM skipped 19.0 entirely and released 19.1 as the first one

@TheDan64
Copy link
Owner

TheDan64 commented Dec 16, 2024

Nah, it's fine and consistent as is 🤔

@TheDan64 TheDan64 self-requested a review December 16, 2024 03:23
@TheDan64
Copy link
Owner

That is such a weird choice...

@TheDan64
Copy link
Owner

Yeah, I guess 19-1 makes more sense

@stevefan1999-personal
Copy link
Contributor Author

stevefan1999-personal commented Dec 16, 2024

@TheDan64 okay, I also tested LLVM 19 integration with https://github.com/jamesmth/llvm-plugin-rs, so the basic examples provided in their repo do compile pretty well, so I will rename the feature from llvm19-0 to llvm19-1 tonight after running the tests and adding LLVM 18 and 19 back to Actions pipeline...

Keep in mind the new features in LLVM 19 aren't added yet, and so a follow up contribution for completing that puzzle would be a huge welcome.

@TyrsDev
Copy link

TyrsDev commented Dec 16, 2024

Yeah, I guess 19-1 makes more sense

I believe LLVM skipped 18.0 as well, and inkwell uses 18-0 for the major feature number, so it would be more consistent to use 19-0 now as well.

@stevefan1999-personal stevefan1999-personal marked this pull request as ready for review December 16, 2024 14:46
@stevefan1999-personal
Copy link
Contributor Author

Yeah, I guess 19-1 makes more sense

I believe LLVM skipped 18.0 as well, and inkwell uses 18-0 for the major feature number, so it would be more consistent to use 19-0 now as well.

No the problem is LLVM directly skipped 19.0 and even llvm-sys have to use 191 as the prefix number, so it is the matter of consistency in the library or in the actual LLVM naming scheme

@iamrecursion
Copy link

I have been able to integrate stevefan1999-personal@0c1e5dd into my project that relies on Inkwell, but stevefan1999-personal@87b7049 creates a number of compilation errors about undefined feature version llvm19-0.

For the version with the successful integration everything seems to be working swimmingly so far, with no regressions found by the test suite.

@stevefan1999-personal
Copy link
Contributor Author

I have been able to integrate stevefan1999-personal@0c1e5dd into my project that relies on Inkwell, but stevefan1999-personal@87b7049 creates a number of compilation errors about undefined feature version llvm19-0.

For the version with the successful integration everything seems to be working swimmingly so far, with no regressions found by the test suite.

That is strange, let me revert the actions changes tonight

@RyanMarcus
Copy link

RyanMarcus commented Jan 20, 2025

I was also able to get 0c1e5dd52cf3e012cb238ecfbdb3b1731b987c03 to work (test suite for my project fully passes), but not the current head. Here's the errors I get on the current head, which seem related to the 19-0 / 19-1 issue.

   Compiling inkwell v0.5.0 (https://github.com/stevefan1999-personal/inkwell.git#b144c761)
error: undefined feature version: "llvm19-0"
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:130:19
    |
130 | #[llvm_versions(..19)]
    |                   ^^

error: undefined feature version: "llvm19-0"
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:135:17
    |
135 | #[llvm_versions(19..)]
    |                 ^^

error: undefined feature version: "llvm19-0"
    --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:1650:25
     |
1650 |         #[llvm_versions(19..)]
     |                         ^^

error: undefined feature version: "llvm19-0"
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/lib.rs:383:21
    |
383 |     #[llvm_versions(19..)]
    |                     ^^

error[E0432]: unresolved import `crate::AtomicRMWBinOp`
  --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/builder.rs:57:29
   |
57 | use crate::{AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate};
   |                             ^^^^^^^^^^^^^^
   |                             |
   |                             no `AtomicRMWBinOp` in the root
   |                             help: a similar name exists in the module: `LLVMAtomicRMWBinOp`

error[E0432]: unresolved import `crate::debug_info::DWARFSourceLanguage`
  --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/module.rs:45:59
   |
45 | ...nd, DWARFSourceLanguage, DebugInfoBuilder};
   |        ^^^^^^^^^^^^^^^^^^^ no `DWARFSourceLanguage` in `debug_info`

error[E0412]: cannot find type `DWARFSourceLanguage` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:190:19
    |
190 |         language: DWARFSourceLanguage,
    |                   ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `DWARFSourceLanguage` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:303:19
    |
303 |         language: DWARFSourceLanguage,
    |                   ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMDIBuilderInsertDeclareBefore` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:952:13
    |
952 |             LLVMDIBuilderInsertDeclareBefore(
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMDIBuilderInsertDeclareAtEnd` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:983:13
    |
983 |             LLVMDIBuilderInsertDeclareAtEnd(
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMDIBuilderInsertDbgValueBefore` in this scope
    --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:1029:13
     |
1029 |             LLVMDIBuilderInsertDbgValueBefore(
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

Some errors have detailed explanations: E0412, E0425, E0432.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `inkwell` (lib) due to 11 previous errors

Simply changing the macro occurrences of "19" to "19.1" seems to solve this issue. Here's the patch (unified diff):

diff --git a/src/debug_info.rs b/src/debug_info.rs
index e393fe9..3411e52 100644
--- a/src/debug_info.rs
+++ b/src/debug_info.rs
@@ -127,12 +127,12 @@ use llvm_sys::debuginfo::{
     LLVMDITypeGetAlignInBits, LLVMDITypeGetOffsetInBits, LLVMDITypeGetSizeInBits,
 };
 
-#[llvm_versions(..19)]
+#[llvm_versions(..19.1)]
 use llvm_sys::debuginfo::{
     LLVMDIBuilderInsertDbgValueBefore, LLVMDIBuilderInsertDeclareAtEnd, LLVMDIBuilderInsertDeclareBefore,
 };
 
-#[llvm_versions(19..)]
+#[llvm_versions(19.1..)]
 use llvm_sys::debuginfo::{
     LLVMDIBuilderInsertDbgValueRecordBefore as LLVMDIBuilderInsertDbgValueBefore,
     LLVMDIBuilderInsertDeclareRecordAtEnd as LLVMDIBuilderInsertDeclareAtEnd,
@@ -1647,51 +1647,51 @@ mod flags {
         #[llvm_variant(LLVMDWARFSourceLanguageMojo)]
         Mojo,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageHIP)]
         Hip,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageAssembly)]
         Assembly,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageC_sharp)]
         Csharp,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageGLSL)]
         Glsl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageGLSL_ES)]
         GlslEs,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageHLSL)]
         Hlsl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageOpenCL_CPP)]
         OpenClCpp,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageCPP_for_OpenCL)]
         CppForOpenCl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageSYCL)]
         Sycl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageRuby)]
         Ruby,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageMove)]
         Move,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageHylo)]
         Hylo,
     }
diff --git a/src/lib.rs b/src/lib.rs
index 582c178..cef20cc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -380,11 +380,11 @@ pub enum AtomicRMWBinOp {
     #[llvm_variant(LLVMAtomicRMWBinOpFMin)]
     FMin,
 
-    #[llvm_versions(19..)]
+    #[llvm_versions(19.1..)]
     #[llvm_variant(LLVMAtomicRMWBinOpUIncWrap)]
     UIncWrap,
 
-    #[llvm_versions(19..)]
+    #[llvm_versions(19.1..)]
     #[llvm_variant(LLVMAtomicRMWBinOpUDecWrap)]
     UDecWrap,
 }

@TheDan64
Copy link
Owner

Hi @stevefan1999-personal, are you able to address the above issues?

@stevefan1999-personal
Copy link
Contributor Author

Hi @stevefan1999-personal, are you able to address the above issues?

Ah I was busy with company stuff, let me handle that tonight

@stevefan1999-personal
Copy link
Contributor Author

I was also able to get 0c1e5dd52cf3e012cb238ecfbdb3b1731b987c03 to work (test suite for my project fully passes), but not the current head. Here's the errors I get on the current head, which seem related to the 19-0 / 19-1 issue.

   Compiling inkwell v0.5.0 (https://github.com/stevefan1999-personal/inkwell.git#b144c761)
error: undefined feature version: "llvm19-0"
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:130:19
    |
130 | #[llvm_versions(..19)]
    |                   ^^

error: undefined feature version: "llvm19-0"
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:135:17
    |
135 | #[llvm_versions(19..)]
    |                 ^^

error: undefined feature version: "llvm19-0"
    --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:1650:25
     |
1650 |         #[llvm_versions(19..)]
     |                         ^^

error: undefined feature version: "llvm19-0"
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/lib.rs:383:21
    |
383 |     #[llvm_versions(19..)]
    |                     ^^

error[E0432]: unresolved import `crate::AtomicRMWBinOp`
  --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/builder.rs:57:29
   |
57 | use crate::{AtomicOrdering, AtomicRMWBinOp, FloatPredicate, IntPredicate};
   |                             ^^^^^^^^^^^^^^
   |                             |
   |                             no `AtomicRMWBinOp` in the root
   |                             help: a similar name exists in the module: `LLVMAtomicRMWBinOp`

error[E0432]: unresolved import `crate::debug_info::DWARFSourceLanguage`
  --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/module.rs:45:59
   |
45 | ...nd, DWARFSourceLanguage, DebugInfoBuilder};
   |        ^^^^^^^^^^^^^^^^^^^ no `DWARFSourceLanguage` in `debug_info`

error[E0412]: cannot find type `DWARFSourceLanguage` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:190:19
    |
190 |         language: DWARFSourceLanguage,
    |                   ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `DWARFSourceLanguage` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:303:19
    |
303 |         language: DWARFSourceLanguage,
    |                   ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMDIBuilderInsertDeclareBefore` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:952:13
    |
952 |             LLVMDIBuilderInsertDeclareBefore(
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMDIBuilderInsertDeclareAtEnd` in this scope
   --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:983:13
    |
983 |             LLVMDIBuilderInsertDeclareAtEnd(
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMDIBuilderInsertDbgValueBefore` in this scope
    --> /home/ryan/.cargo/git/checkouts/inkwell-23378709d3c29eb9/b144c76/src/debug_info.rs:1029:13
     |
1029 |             LLVMDIBuilderInsertDbgValueBefore(
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

Some errors have detailed explanations: E0412, E0425, E0432.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `inkwell` (lib) due to 11 previous errors

Simply changing the macro occurrences of "19" to "19.1" seems to solve this issue. Here's the patch (unified diff):

diff --git a/src/debug_info.rs b/src/debug_info.rs
index e393fe9..3411e52 100644
--- a/src/debug_info.rs
+++ b/src/debug_info.rs
@@ -127,12 +127,12 @@ use llvm_sys::debuginfo::{
     LLVMDITypeGetAlignInBits, LLVMDITypeGetOffsetInBits, LLVMDITypeGetSizeInBits,
 };
 
-#[llvm_versions(..19)]
+#[llvm_versions(..19.1)]
 use llvm_sys::debuginfo::{
     LLVMDIBuilderInsertDbgValueBefore, LLVMDIBuilderInsertDeclareAtEnd, LLVMDIBuilderInsertDeclareBefore,
 };
 
-#[llvm_versions(19..)]
+#[llvm_versions(19.1..)]
 use llvm_sys::debuginfo::{
     LLVMDIBuilderInsertDbgValueRecordBefore as LLVMDIBuilderInsertDbgValueBefore,
     LLVMDIBuilderInsertDeclareRecordAtEnd as LLVMDIBuilderInsertDeclareAtEnd,
@@ -1647,51 +1647,51 @@ mod flags {
         #[llvm_variant(LLVMDWARFSourceLanguageMojo)]
         Mojo,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageHIP)]
         Hip,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageAssembly)]
         Assembly,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageC_sharp)]
         Csharp,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageGLSL)]
         Glsl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageGLSL_ES)]
         GlslEs,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageHLSL)]
         Hlsl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageOpenCL_CPP)]
         OpenClCpp,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageCPP_for_OpenCL)]
         CppForOpenCl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageSYCL)]
         Sycl,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageRuby)]
         Ruby,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageMove)]
         Move,
 
-        #[llvm_versions(19..)]
+        #[llvm_versions(19.1..)]
         #[llvm_variant(LLVMDWARFSourceLanguageHylo)]
         Hylo,
     }
diff --git a/src/lib.rs b/src/lib.rs
index 582c178..cef20cc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -380,11 +380,11 @@ pub enum AtomicRMWBinOp {
     #[llvm_variant(LLVMAtomicRMWBinOpFMin)]
     FMin,
 
-    #[llvm_versions(19..)]
+    #[llvm_versions(19.1..)]
     #[llvm_variant(LLVMAtomicRMWBinOpUIncWrap)]
     UIncWrap,
 
-    #[llvm_versions(19..)]
+    #[llvm_versions(19.1..)]
     #[llvm_variant(LLVMAtomicRMWBinOpUDecWrap)]
     UDecWrap,
 }

I guess the biggest problem is that we don't know why LLVM skipped the whole 19.0 release and go straight to 19.1, which the 19.. range should technically be covered. I think as a workaround, let me merge it to be using 19.1 then, but keep in mind this is pretty abnormal in a common sense

@stevefan1999-personal
Copy link
Contributor Author

stevefan1999-personal commented Feb 21, 2025

https://github.com/stevefan1999-personal/inkwell/actions/runs/13450580072/job/37584222806

Looks like 19.1 amd64 is missing from KyleMayes and one of the PR that attempts to fix it is still missing it as well...Can't really test 19.1 at the moment with CI for now

See KyleMayes/install-llvm-action#84

@TheDan64
Copy link
Owner

@stevefan1999-personal do you suggest waiting to merge until 19.1 is added?

@TheDan64 TheDan64 added this to the 0.6.0 milestone Feb 23, 2025
@stevefan1999-personal
Copy link
Contributor Author

@TheDan64 all tests passed on my actions, so if it is LGTY let's merge it ASAP so I can work on the llvm-plugin-rs

@TheDan64 TheDan64 requested a review from Copilot May 23, 2025 07:54
@TheDan64
Copy link
Owner

I wont be able to review this until next week

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces preliminary support for LLVM 19 and 20 by adding new feature flags across various type and module definitions, updating CI workflows, and configuring Cargo dependencies to accommodate the newer LLVM versions.

  • Extended feature lists in type definitions and trait implementations
  • Updated CI configuration and documentation to include LLVM 19/20 installations
  • Adjusted examples and context functions to reflect these new LLVM versions

Reviewed Changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/types/*.rs Added LLVM 19/20 feature flags in type modules
src/lib.rs Updated extern crate declarations for LLVM 19/20 support
src/debug_info.rs Introduced new blocks with todo!() for LLVM 19/20 debug info stubs
src/context.rs, src/builder.rs Updated function implementations and overloads for new LLVM versions
internal_macros/src/cfg.rs Updated feature list to include llvm19-1 and llvm20-1
examples/kaleidoscope/main.rs, Cargo.toml, .github/workflows/test.yml Adapted examples, documentation, and CI for LLVM 19/20 integration

#[cfg(any(feature = "llvm19-1", feature = "llvm20-1"))]
{
let _ = value_ref;
todo!()
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

The use of todo!() in the DebugInfoBuilder functions for LLVM 19/20 may lead to unexpected panics. Consider adding a clear error message or a fallback implementation along with documentation to indicate that these functions are currently unimplemented.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tell me how to use the new API for Debug Struct starting from LLVM 19 as a replacement to old API, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I did not see that Copilot won't reply to this thread, so I thought I have a prompt for that there...

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 follow, can't you leave the current api as is?

If there is a new api we should either support it here or in a future PR without removing existing functionality (assuming the methods haven't been removed)

Comment on lines +2898 to +2918
#[llvm_versions(..17)]
pub fn build_int_nuw_neg<T: IntMathValue<'ctx>>(&self, value: T, name: &str) -> Result<T, BuilderError> {
if self.positioned.get() != PositionState::Set {
return Err(BuilderError::UnsetPosition);
}
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNUWNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) };
unsafe { Ok(T::new(value)) }
}

// SubType: <I>(&self, value: &IntValue<I>, name) -> IntValue<I> {
#[llvm_versions(17..)]
pub fn build_int_nuw_neg<T: IntMathValue<'ctx>>(&self, value: T, name: &str) -> Result<T, BuilderError> {
if self.positioned.get() != PositionState::Set {
return Err(BuilderError::UnsetPosition);
}
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) };
unsafe {
LLVMSetNUW(value, true.into());
}
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

[nitpick] Two versions of build_int_nuw_neg are provided for different LLVM versions. Consider refactoring or clearly documenting the differences to improve code clarity and reduce potential confusion in maintenance.

Suggested change
#[llvm_versions(..17)]
pub fn build_int_nuw_neg<T: IntMathValue<'ctx>>(&self, value: T, name: &str) -> Result<T, BuilderError> {
if self.positioned.get() != PositionState::Set {
return Err(BuilderError::UnsetPosition);
}
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNUWNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) };
unsafe { Ok(T::new(value)) }
}
// SubType: <I>(&self, value: &IntValue<I>, name) -> IntValue<I> {
#[llvm_versions(17..)]
pub fn build_int_nuw_neg<T: IntMathValue<'ctx>>(&self, value: T, name: &str) -> Result<T, BuilderError> {
if self.positioned.get() != PositionState::Set {
return Err(BuilderError::UnsetPosition);
}
let c_string = to_c_str(name);
let value = unsafe { LLVMBuildNeg(self.builder, value.as_value_ref(), c_string.as_ptr()) };
unsafe {
LLVMSetNUW(value, true.into());
}
pub fn build_int_nuw_neg<T: IntMathValue<'ctx>>(&self, value: T, name: &str) -> Result<T, BuilderError> {
if self.positioned.get() != PositionState::Set {
return Err(BuilderError::UnsetPosition);
}
let c_string = to_c_str(name);
let value = unsafe {
#[cfg(llvm_versions = "..17")]
{
LLVMBuildNUWNeg(self.builder, value.as_value_ref(), c_string.as_ptr())
}
#[cfg(llvm_versions = "17..")]
{
let v = LLVMBuildNeg(self.builder, value.as_value_ref(), c_string.as_ptr());
LLVMSetNUW(v, true.into());
v
}
};

Copilot uses AI. Check for mistakes.
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.

This looks pretty good but there are a couple things that need to be addressed before merging


* Rust 1.56+ (Stable, Beta, or Nightly)
* One of LLVM 8-18
* One of LLVM 8-18 (WIP: 19 and 20 are barely supported without extensive tests)
Copy link
Owner

Choose a reason for hiding this comment

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

We should update this to 20

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I specifically mentioned 19 and 20 because both of them are indeed not tested especially with their new APIs, thus I should call this >=19 maybe?

Copy link
Owner

Choose a reason for hiding this comment

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

If the test suite passes for those versions we consider them supported, even if we don't have new tests specifically for them

#[cfg(any(feature = "llvm19-1", feature = "llvm20-1"))]
{
let _ = value_ref;
todo!()
Copy link
Owner

Choose a reason for hiding this comment

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

This looks like it still needs to be fixed? And a few later on as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea on how to use the new Debug Record API starting from LLVM 19, I think it is not just deprecated is it removed entirely? Or we can just version it out but it will be very confusing to end users

Copy link
Contributor Author

@stevefan1999-personal stevefan1999-personal May 30, 2025

Choose a reason for hiding this comment

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

Yeah I guess that new API deserve a whole new struct and tailor-made wrapper APIs around it to be honest.

Copy link
Owner

Choose a reason for hiding this comment

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

If the methods don't exist then we must version them out, otherwise keep them. Adding new APIs can be done in a separate PR

Benjins added a commit to Benjins/llvm-ir that referenced this pull request Jun 22, 2025
… the official apt packages for 19 and above

KyleMayes/install-llvm-action uses the semi-official binaries uploaded to the LLVM github releases. For LLVM 19, these are built with LTO, which cannot be linked against by the standard linkers (and broke CI for LLVM 19).

To work around this, we can use the github action to install older versions of LLVM, but use the official apt packages for newer versions. Ubuntu 24.04 (noble) has packages starting at LLVM 17, so this should be good for a while.

This is pretty much what Inkwell seems to be doing as well: TheDan64/inkwell#557
Benjins added a commit to Benjins/llvm-ir that referenced this pull request Jun 22, 2025
… the official apt packages for 19 and above

KyleMayes/install-llvm-action uses the semi-official binaries uploaded to the LLVM github releases. For LLVM 19, these are built with LTO, which cannot be linked against by the standard linkers (and broke CI for LLVM 19).

To work around this, we can use the github action to install older versions of LLVM, but use the official apt packages for newer versions. Ubuntu 24.04 (noble) has packages starting at LLVM 17, so this should be good for a while.

This is pretty much what Inkwell seems to be doing as well: TheDan64/inkwell#557
Benjins added a commit to Benjins/llvm-ir that referenced this pull request Jun 22, 2025
… the official apt packages for 19 and above

KyleMayes/install-llvm-action uses the semi-official binaries uploaded to the LLVM github releases. For LLVM 19, these are built with LTO, which cannot be linked against by the standard linkers (and broke CI for LLVM 19).

To work around this, we can use the github action to install older versions of LLVM, but use the official apt packages for newer versions. Ubuntu 24.04 (noble) has packages starting at LLVM 17, so this should be good for a while.

This is pretty much what Inkwell seems to be doing as well: TheDan64/inkwell#557
Benjins added a commit to Benjins/llvm-ir that referenced this pull request Jun 22, 2025
… the official apt packages for 19 and above

KyleMayes/install-llvm-action uses the semi-official binaries uploaded to the LLVM github releases. For LLVM 19, these are built with LTO, which cannot be linked against by the standard linkers (and broke CI for LLVM 19).

To work around this, we can use the github action to install older versions of LLVM, but use the official apt packages for newer versions. Ubuntu 24.04 (noble) has packages starting at LLVM 17, so this should be good for a while.

This is pretty much what Inkwell seems to be doing as well: TheDan64/inkwell#557
@TheDan64
Copy link
Owner

@stevefan1999-personal are you able to resolve the remaining issues and comments so we can merge this PR?

@stevefan1999-personal
Copy link
Contributor Author

@TheDan64 let me take a look this weekend

@stevefan1999-personal
Copy link
Contributor Author

@stevefan1999-personal
Copy link
Contributor Author

@TheDan64 do you think it is good to go

@TheDan64
Copy link
Owner

TheDan64 commented Aug 3, 2025

@stevefan1999-personal there are some clippy failures... if you do cargo clippy --fix you should be able to fix them and get the full suite to run

@TheDan64 TheDan64 merged commit 50c16a6 into TheDan64:master Aug 9, 2025
15 checks passed
@qartik
Copy link
Contributor

qartik commented Oct 6, 2025

@TheDan64 would you be willing to make a new release with this PR included?

@TheDan64
Copy link
Owner

TheDan64 commented Oct 6, 2025

Sure thing

@TheDan64
Copy link
Owner

TheDan64 commented Oct 7, 2025

0.7.0 milestone has been triaged now accurately represents what remains before release: https://github.com/TheDan64/inkwell/milestone/9

cdisselkoen pushed a commit to cdisselkoen/llvm-ir that referenced this pull request Jan 16, 2026
… the official apt packages for 19 and above (#76)

KyleMayes/install-llvm-action uses the semi-official binaries uploaded to the LLVM github releases. For LLVM 19, these are built with LTO, which cannot be linked against by the standard linkers (and broke CI for LLVM 19).

To work around this, we can use the github action to install older versions of LLVM, but use the official apt packages for newer versions. Ubuntu 24.04 (noble) has packages starting at LLVM 17, so this should be good for a while.

This is pretty much what Inkwell seems to be doing as well: TheDan64/inkwell#557
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.

8 participants