Skip to content
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ llvm-sys-160 = { package = "llvm-sys", version = "160.1.0", optional = true }
once_cell = "1.16"
parking_lot = "0.12"
static-alloc = { version = "0.2", optional = true }
trc = "1.2.2"
Comment thread
TheDan64 marked this conversation as resolved.
Outdated

[dev-dependencies]
regex = "1"
Expand Down
125 changes: 125 additions & 0 deletions src/builder.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use llvm_sys::core::LLVMGetPoison;

use llvm_sys::core::{
LLVMAlignOf, LLVMArrayType, LLVMConstNull, LLVMConstPointerNull, LLVMFunctionType, LLVMGetElementType,
LLVMGetTypeContext, LLVMGetTypeKind, LLVMGetUndef, LLVMPointerType, LLVMPrintTypeToString,
LLVMSizeOf, LLVMTypeIsSized, LLVMVectorType,
LLVMGetTypeContext, LLVMGetTypeKind, LLVMGetUndef, LLVMPointerType, LLVMPrintTypeToString, LLVMSizeOf,
LLVMTypeIsSized, LLVMVectorType,
};
use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};
use llvm_sys::LLVMTypeKind;
Expand Down
2 changes: 1 addition & 1 deletion src/types/struct_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<'ctx> StructType<'ctx> {
/// Defines the body of a `StructType`.
///
/// If the struct is an opaque type, it will no longer be after this call.
///
///
/// Resetting the `packed` state of a non-opaque struct type may not work.
///
/// # Example
Expand Down
10 changes: 5 additions & 5 deletions src/values/array_value.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use llvm_sys::core::{LLVMIsAConstantArray, LLVMIsAConstantDataArray, LLVMIsConstantString, LLVMGetAsString};
use llvm_sys::core::{LLVMGetAsString, LLVMIsAConstantArray, LLVMIsAConstantDataArray, LLVMIsConstantString};
use llvm_sys::prelude::LLVMValueRef;

use std::ffi::CStr;
Expand Down Expand Up @@ -102,16 +102,16 @@ impl<'ctx> ArrayValue<'ctx> {

/// Obtain the string from the ArrayValue
/// if the value points to a constant string.
///
///
/// # Example
///
///
/// ```no_run
/// use inkwell::context::Context;
/// use std::ffi::CStr;
///
///
/// let context = Context::create();
/// let string = context.const_string(b"hello!", true);
///
///
/// let result = CStr::from_bytes_with_nul(b"hello!\0").unwrap();
/// assert_eq!(string.get_string_constant(), Some(result));
/// ```
Expand Down
12 changes: 9 additions & 3 deletions src/values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub use crate::values::vec_value::VectorValue;
use llvm_sys::core::LLVMIsPoison;

use llvm_sys::core::{
LLVMDumpValue, LLVMGetFirstUse, LLVMGetSection, LLVMIsAInstruction, LLVMIsConstant, LLVMIsNull,
LLVMIsUndef, LLVMPrintTypeToString, LLVMPrintValueToString, LLVMReplaceAllUsesWith, LLVMSetSection, LLVMTypeOf,
LLVMDumpValue, LLVMGetFirstUse, LLVMGetSection, LLVMIsAInstruction, LLVMIsConstant, LLVMIsNull, LLVMIsUndef,
LLVMPrintTypeToString, LLVMPrintValueToString, LLVMReplaceAllUsesWith, LLVMSetSection, LLVMTypeOf,
};
use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};

Expand Down Expand Up @@ -205,7 +205,13 @@ impl<'ctx> Value<'ctx> {
/// Sets the section of the global value
fn set_section(self, section: Option<&str>) {
#[cfg(target_os = "macos")]
let section = section.map(|s| if s.contains(",") { format!("{}", s) } else { format!(",{}", s) });
let section = section.map(|s| {
if s.contains(",") {
format!("{}", s)
} else {
format!(",{}", s)
}
});

let c_string = section.as_deref().map(to_c_str);

Expand Down
4 changes: 2 additions & 2 deletions src/values/vec_value.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use llvm_sys::core::{
LLVMConstExtractElement, LLVMConstInsertElement, LLVMConstSelect, LLVMConstShuffleVector,
LLVMGetElementAsConstant, LLVMIsAConstantDataVector, LLVMIsAConstantVector,
LLVMConstExtractElement, LLVMConstInsertElement, LLVMConstSelect, LLVMConstShuffleVector, LLVMGetElementAsConstant,
LLVMIsAConstantDataVector, LLVMIsAConstantVector,
};
use llvm_sys::prelude::LLVMValueRef;

Expand Down
8 changes: 8 additions & 0 deletions tests/all/test_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ fn test_call_site() {
let fn_type = void_type.fn_type(&[], false);

let function = module.add_function("do_nothing", fn_type, None);

let block = context.append_basic_block(function, "entry");
builder.position_at_end(block);

let call_site = builder.build_call(function, &[], "to_infinity_and_beyond");

assert_eq!(call_site.count_arguments(), 0);
Expand Down Expand Up @@ -1344,6 +1348,10 @@ fn test_constant_expression() {
let fn_type = void_type.fn_type(&[], false);

let function = module.add_function("", fn_type, None);

let block = context.append_basic_block(function, "entry");
builder.position_at_end(block);

let expr = builder.build_ptr_to_int(function.as_global_value().as_pointer_value(), i32_type, "");

assert!(expr.is_const());
Expand Down