Critical: Use of 'unsafe' keyword bypasses Rust's safety guarantees. Requires careful auditing, clear justification (FFI, specific optimizations), and minimal scope.
unsafe extern "C" {
1//! Bindings to the LLVM-C API (`LLVM*`), and to our own `extern "C"` wrapper2//! functions around the unstable LLVM C++ API (`LLVMRust*`).3//!4//! ## Passing pointer/length strings as `*const c_uchar` (PTR_LEN_STR)5//!6//! Normally it's a good idea for Rust-side bindings to match the corresponding7//! C-side function declarations as closely as possible. But when passing `&str`8//! or `&[u8]` data as a pointer/length pair, it's more convenient to declare9//! the Rust-side pointer as `*const c_uchar` instead of `*const c_char`.10//! Both pointer types have the same ABI, and using `*const c_uchar` avoids11//! the need for an extra cast from `*const u8` on the Rust side.1213#![allow(non_camel_case_types)]1415use std::fmt::{self, Debug};16use std::marker::PhantomData;17use std::num::NonZero;18use std::ptr;1920use bitflags::bitflags;21use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t};2223use super::RustString;24use super::debuginfo::{25 DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DILocation,26 DISPFlags, DIScope, DISubprogram, DITemplateTypeParameter, DIType, DebugEmissionKind,27 DebugNameTableKind,28};29use crate::llvm::MetadataKindId;30use crate::{TryFromU32, llvm};3132/// In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`,33/// which has a different ABI from Rust or C++ `bool`.34///35/// This wrapper does not implement `PartialEq`.36/// To test the underlying boolean value, use [`Self::is_true`].37#[derive(Clone, Copy)]38#[repr(transparent)]39pub(crate) struct Bool {40 value: c_int,41}4243pub(crate) const TRUE: Bool = Bool::TRUE;44pub(crate) const FALSE: Bool = Bool::FALSE;4546impl Bool {47 pub(crate) const TRUE: Self = Self { value: 1 };48 pub(crate) const FALSE: Self = Self { value: 0 };4950 pub(crate) const fn from_bool(rust_bool: bool) -> Self {51 if rust_bool { Self::TRUE } else { Self::FALSE }52 }5354 /// Converts this LLVM-C boolean to a Rust `bool`55 pub(crate) fn is_true(self) -> bool {56 // Since we're interacting with a C API, follow the C convention of57 // treating any nonzero value as true.58 self.value != Self::FALSE.value59 }60}6162impl Debug for Bool {63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {64 match self.value {65 0 => f.write_str("FALSE"),66 1 => f.write_str("TRUE"),67 // As with `Self::is_true`, treat any nonzero value as true.68 v => write!(f, "TRUE ({v})"),69 }70 }71}7273/// Convenience trait to convert `bool` to `llvm::Bool` with an explicit method call.74///75/// Being able to write `b.to_llvm_bool()` is less noisy than `llvm::Bool::from(b)`,76/// while being more explicit and less mistake-prone than something like `b.into()`.77pub(crate) trait ToLlvmBool: Copy {78 fn to_llvm_bool(self) -> llvm::Bool;79}8081impl ToLlvmBool for bool {82 #[inline(always)]83 fn to_llvm_bool(self) -> llvm::Bool {84 llvm::Bool::from_bool(self)85 }86}8788/// Wrapper for a raw enum value returned from LLVM's C APIs.89///90/// For C enums returned by LLVM, it's risky to use a Rust enum as the return91/// type, because it would be UB if a later version of LLVM adds a new enum92/// value and returns it. Instead, return this raw wrapper, then convert to the93/// Rust-side enum explicitly.94#[repr(transparent)]95pub(crate) struct RawEnum<T> {96 value: u32,97 /// We don't own or consume a `T`, but we can produce one.98 _rust_side_type: PhantomData<fn() -> T>,99}100101impl<T: TryFrom<u32>> RawEnum<T> {102 #[track_caller]103 pub(crate) fn to_rust(self) -> T104 where105 T::Error: Debug,106 {107 // If this fails, the Rust-side enum is out of sync with LLVM's enum.108 T::try_from(self.value).expect("enum value returned by LLVM should be known")109 }110}111112#[derive(Copy, Clone, PartialEq)]113#[repr(C)]114#[allow(dead_code)] // Variants constructed by C++.115pub(crate) enum LLVMRustResult {116 Success,117 Failure,118}119120/// Must match the layout of `LLVMRustModuleFlagMergeBehavior`.121///122/// When merging modules (e.g. during LTO), their metadata flags are combined. Conflicts are123/// resolved according to the merge behaviors specified here. Flags differing only in merge124/// behavior are still considered to be in conflict.125///126/// In order for Rust-C LTO to work, we must specify behaviors compatible with Clang. Notably,127/// 'Error' and 'Warning' cannot be mixed for a given flag.128///129/// There is a stable LLVM-C version of this enum (`LLVMModuleFlagBehavior`),130/// but as of LLVM 19 it does not support all of the enum values in the unstable131/// C++ API.132#[derive(Copy, Clone, PartialEq)]133#[repr(C)]134pub(crate) enum ModuleFlagMergeBehavior {135 Error = 1,136 Warning = 2,137 Require = 3,138 Override = 4,139 Append = 5,140 AppendUnique = 6,141 Max = 7,142 Min = 8,143}144145// Consts for the LLVM CallConv type, pre-cast to usize.146147/// Must match the layout of `LLVMTailCallKind`.148#[derive(Copy, Clone, PartialEq, Debug)]149#[repr(C)]150#[allow(dead_code)]151pub(crate) enum TailCallKind {152 None = 0,153 Tail = 1,154 MustTail = 2,155 NoTail = 3,156}157158/// LLVM CallingConv::ID. Should we wrap this?159///160/// See <https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/CallingConv.h>161#[derive(Copy, Clone, PartialEq, Debug, TryFromU32)]162#[repr(C)]163pub(crate) enum CallConv {164 CCallConv = 0,165 FastCallConv = 8,166 ColdCallConv = 9,167 PreserveMost = 14,168 PreserveAll = 15,169 Tail = 18,170 PreserveNone = 21,171 X86StdcallCallConv = 64,172 X86FastcallCallConv = 65,173 ArmAapcsCallConv = 67,174 Msp430Intr = 69,175 X86_ThisCall = 70,176 PtxKernel = 71,177 X86_64_SysV = 78,178 X86_64_Win64 = 79,179 X86_VectorCall = 80,180 X86_Intr = 83,181 AvrNonBlockingInterrupt = 84,182 AvrInterrupt = 85,183 AmdgpuKernel = 91,184}185186/// Must match the layout of `LLVMLinkage`.187#[derive(Copy, Clone, PartialEq, TryFromU32)]188#[repr(C)]189pub(crate) enum Linkage {190 ExternalLinkage = 0,191 AvailableExternallyLinkage = 1,192 LinkOnceAnyLinkage = 2,193 LinkOnceODRLinkage = 3,194 #[deprecated = "marked obsolete by LLVM"]195 LinkOnceODRAutoHideLinkage = 4,196 WeakAnyLinkage = 5,197 WeakODRLinkage = 6,198 AppendingLinkage = 7,199 InternalLinkage = 8,200 PrivateLinkage = 9,201 #[deprecated = "marked obsolete by LLVM"]202 DLLImportLinkage = 10,203 #[deprecated = "marked obsolete by LLVM"]204 DLLExportLinkage = 11,205 ExternalWeakLinkage = 12,206 #[deprecated = "marked obsolete by LLVM"]207 GhostLinkage = 13,208 CommonLinkage = 14,209 LinkerPrivateLinkage = 15,210 LinkerPrivateWeakLinkage = 16,211}212213/// Must match the layout of `LLVMVisibility`.214#[repr(C)]215#[derive(Copy, Clone, PartialEq, TryFromU32)]216pub(crate) enum Visibility {217 Default = 0,218 Hidden = 1,219 Protected = 2,220}221222/// LLVMUnnamedAddr223#[repr(C)]224pub(crate) enum UnnamedAddr {225 No,226 #[expect(dead_code)]227 Local,228 Global,229}230231/// LLVMDLLStorageClass232#[derive(Copy, Clone)]233#[repr(C)]234pub(crate) enum DLLStorageClass {235 #[allow(dead_code)]236 Default = 0,237 DllImport = 1, // Function to be imported from DLL.238 #[allow(dead_code)]239 DllExport = 2, // Function to be accessible from DLL.240}241242/// Must match the layout of `LLVMRustAttributeKind`.243/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,244/// though it is not ABI compatible (since it's a C++ enum)245#[repr(C)]246#[derive(Copy, Clone, Debug)]247#[expect(dead_code, reason = "Some variants are unused, but are kept to match the C++")]248pub(crate) enum AttributeKind {249 AlwaysInline = 0,250 ByVal = 1,251 Cold = 2,252 InlineHint = 3,253 MinSize = 4,254 Naked = 5,255 NoAlias = 6,256 CapturesAddress = 7,257 NoInline = 8,258 NonNull = 9,259 NoRedZone = 10,260 NoReturn = 11,261 NoUnwind = 12,262 OptimizeForSize = 13,263 ReadOnly = 14,264 SExt = 15,265 StructRet = 16,266 UWTable = 17,267 ZExt = 18,268 InReg = 19,269 SanitizeThread = 20,270 SanitizeAddress = 21,271 SanitizeMemory = 22,272 NonLazyBind = 23,273 OptimizeNone = 24,274 ReadNone = 26,275 SanitizeHWAddress = 28,276 WillReturn = 29,277 StackProtectReq = 30,278 StackProtectStrong = 31,279 StackProtect = 32,280 NoUndef = 33,281 SanitizeMemTag = 34,282 NoCfCheck = 35,283 ShadowCallStack = 36,284 AllocSize = 37,285 AllocatedPointer = 38,286 AllocAlign = 39,287 SanitizeSafeStack = 40,288 FnRetThunkExtern = 41,289 Writable = 42,290 DeadOnUnwind = 43,291 DeadOnReturn = 44,292 CapturesReadOnly = 45,293 CapturesNone = 46,294 SanitizeRealtimeNonblocking = 47,295 SanitizeRealtimeBlocking = 48,296 Convergent = 49,297}298299/// LLVMIntPredicate300#[derive(Copy, Clone)]301#[repr(C)]302pub(crate) enum IntPredicate {303 IntEQ = 32,304 IntNE = 33,305 IntUGT = 34,306 IntUGE = 35,307 IntULT = 36,308 IntULE = 37,309 IntSGT = 38,310 IntSGE = 39,311 IntSLT = 40,312 IntSLE = 41,313}314315/// LLVMRealPredicate316#[derive(Copy, Clone)]317#[repr(C)]318pub(crate) enum RealPredicate {319 RealPredicateFalse = 0,320 RealOEQ = 1,321 RealOGT = 2,322 RealOGE = 3,323 RealOLT = 4,324 RealOLE = 5,325 RealONE = 6,326 RealORD = 7,327 RealUNO = 8,328 RealUEQ = 9,329 RealUGT = 10,330 RealUGE = 11,331 RealULT = 12,332 RealULE = 13,333 RealUNE = 14,334 RealPredicateTrue = 15,335}336337/// Must match the layout of `LLVMTypeKind`.338///339/// Use [`RawEnum<TypeKind>`] for values of `LLVMTypeKind` returned from LLVM,340/// to avoid risk of UB if LLVM adds new enum values.341///342/// All of LLVM's variants should be declared here, even if no Rust-side code refers343/// to them, because unknown variants will cause [`RawEnum::to_rust`] to panic.344#[derive(Copy, Clone, PartialEq, Debug, TryFromU32)]345#[repr(C)]346pub(crate) enum TypeKind {347 Void = 0,348 Half = 1,349 Float = 2,350 Double = 3,351 X86_FP80 = 4,352 FP128 = 5,353 PPC_FP128 = 6,354 Label = 7,355 Integer = 8,356 Function = 9,357 Struct = 10,358 Array = 11,359 Pointer = 12,360 Vector = 13,361 Metadata = 14,362 Token = 16,363 ScalableVector = 17,364 BFloat = 18,365 X86_AMX = 19,366}367368/// LLVMAtomicRmwBinOp369#[derive(Copy, Clone)]370#[repr(C)]371pub(crate) enum AtomicRmwBinOp {372 AtomicXchg = 0,373 AtomicAdd = 1,374 AtomicSub = 2,375 AtomicAnd = 3,376 AtomicNand = 4,377 AtomicOr = 5,378 AtomicXor = 6,379 AtomicMax = 7,380 AtomicMin = 8,381 AtomicUMax = 9,382 AtomicUMin = 10,383}384385/// LLVMAtomicOrdering386#[derive(Copy, Clone)]387#[repr(C)]388pub(crate) enum AtomicOrdering {389 #[allow(dead_code)]390 NotAtomic = 0,391 #[allow(dead_code)]392 Unordered = 1,393 Monotonic = 2,394 // Consume = 3, // Not specified yet.395 Acquire = 4,396 Release = 5,397 AcquireRelease = 6,398 SequentiallyConsistent = 7,399}400401/// LLVMRustFileType402#[derive(Copy, Clone)]403#[repr(C)]404pub(crate) enum FileType {405 AssemblyFile,406 ObjectFile,407}408409/// Must match the layout of `LLVMInlineAsmDialect`.410#[derive(Copy, Clone, PartialEq)]411#[repr(C)]412pub(crate) enum AsmDialect {413 Att,414 Intel,415}416417/// LLVMRustCodeGenOptLevel418#[derive(Copy, Clone, PartialEq)]419#[repr(C)]420pub(crate) enum CodeGenOptLevel {421 None,422 Less,423 Default,424 Aggressive,425}426427/// LLVMRustPassBuilderOptLevel428#[repr(C)]429pub(crate) enum PassBuilderOptLevel {430 O0,431 O1,432 O2,433 O3,434 Os,435 Oz,436}437438/// LLVMRustOptStage439#[derive(PartialEq)]440#[repr(C)]441pub(crate) enum OptStage {442 PreLinkNoLTO,443 PreLinkThinLTO,444 PreLinkFatLTO,445 ThinLTO,446 FatLTO,447}448449/// LLVMRustSanitizerOptions450#[repr(C)]451pub(crate) struct SanitizerOptions {452 pub sanitize_address: bool,453 pub sanitize_address_recover: bool,454 pub sanitize_cfi: bool,455 pub sanitize_dataflow: bool,456 pub sanitize_dataflow_abilist: *const *const c_char,457 pub sanitize_dataflow_abilist_len: size_t,458 pub sanitize_kcfi: bool,459 pub sanitize_memory: bool,460 pub sanitize_memory_recover: bool,461 pub sanitize_memory_track_origins: c_int,462 pub sanitize_realtime: bool,463 pub sanitize_thread: bool,464 pub sanitize_hwaddress: bool,465 pub sanitize_hwaddress_recover: bool,466 pub sanitize_kernel_address: bool,467 pub sanitize_kernel_address_recover: bool,468 pub sanitize_kernel_hwaddress: bool,469 pub sanitize_kernel_hwaddress_recover: bool,470}471472/// LLVMRustRelocModel473#[derive(Copy, Clone, PartialEq)]474#[repr(C)]475pub(crate) enum RelocModel {476 Static,477 PIC,478 DynamicNoPic,479 ROPI,480 RWPI,481 ROPI_RWPI,482}483484/// LLVMRustFloatABI485#[derive(Copy, Clone, PartialEq)]486#[repr(C)]487pub(crate) enum FloatAbi {488 Default,489 Soft,490 Hard,491}492493/// LLVMRustCodeModel494#[derive(Copy, Clone)]495#[repr(C)]496pub(crate) enum CodeModel {497 Tiny,498 Small,499 Kernel,500 Medium,501 Large,502 None,503}504505/// LLVMRustDiagnosticKind506#[derive(Copy, Clone)]507#[repr(C)]508#[allow(dead_code)] // Variants constructed by C++.509pub(crate) enum DiagnosticKind {510 Other,511 InlineAsm,512 StackSize,513 DebugMetadataVersion,514 SampleProfile,515 OptimizationRemark,516 OptimizationRemarkMissed,517 OptimizationRemarkAnalysis,518 OptimizationRemarkAnalysisFPCommute,519 OptimizationRemarkAnalysisAliasing,520 OptimizationRemarkOther,521 OptimizationFailure,522 PGOProfile,523 Linker,524 Unsupported,525 SrcMgr,526}527528/// LLVMRustDiagnosticLevel529#[derive(Copy, Clone)]530#[repr(C)]531#[allow(dead_code)] // Variants constructed by C++.532pub(crate) enum DiagnosticLevel {533 Error,534 Warning,535 Note,536 Remark,537}538539unsafe extern "C" {540 // LLVMRustThinLTOData541 pub(crate) type ThinLTOData;542}543544/// LLVMRustThinLTOModule545#[repr(C)]546pub(crate) struct ThinLTOModule {547 pub identifier: *const c_char,548 pub data: *const u8,549 pub len: usize,550}551552/// LLVMThreadLocalMode553#[derive(Copy, Clone)]554#[repr(C)]555pub(crate) enum ThreadLocalMode {556 #[expect(dead_code)]557 NotThreadLocal,558 GeneralDynamic,559 LocalDynamic,560 InitialExec,561 LocalExec,562}563564/// LLVMRustChecksumKind565#[derive(Copy, Clone)]566#[repr(C)]567pub(crate) enum ChecksumKind {568 None,569 MD5,570 SHA1,571 SHA256,572}573574/// LLVMRustMemoryEffects575#[derive(Copy, Clone)]576#[repr(C)]577pub(crate) enum MemoryEffects {578 None,579 ReadOnly,580 InaccessibleMemOnly,581 ReadOnlyNotPure,582}583584/// LLVMOpcode585#[derive(Copy, Clone, PartialEq, Eq)]586#[repr(C)]587#[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")]588pub(crate) enum Opcode {589 Ret = 1,590 Br = 2,591 Switch = 3,592 IndirectBr = 4,593 Invoke = 5,594 Unreachable = 7,595 CallBr = 67,596 FNeg = 66,597 Add = 8,598 FAdd = 9,599 Sub = 10,600 FSub = 11,601 Mul = 12,602 FMul = 13,603 UDiv = 14,604 SDiv = 15,605 FDiv = 16,606 URem = 17,607 SRem = 18,608 FRem = 19,609 Shl = 20,610 LShr = 21,611 AShr = 22,612 And = 23,613 Or = 24,614 Xor = 25,615 Alloca = 26,616 Load = 27,617 Store = 28,618 GetElementPtr = 29,619 Trunc = 30,620 ZExt = 31,621 SExt = 32,622 FPToUI = 33,623 FPToSI = 34,624 UIToFP = 35,625 SIToFP = 36,626 FPTrunc = 37,627 FPExt = 38,628 PtrToInt = 39,629 IntToPtr = 40,630 BitCast = 41,631 AddrSpaceCast = 60,632 ICmp = 42,633 FCmp = 43,634 PHI = 44,635 Call = 45,636 Select = 46,637 UserOp1 = 47,638 UserOp2 = 48,639 VAArg = 49,640 ExtractElement = 50,641 InsertElement = 51,642 ShuffleVector = 52,643 ExtractValue = 53,644 InsertValue = 54,645 Freeze = 68,646 Fence = 55,647 AtomicCmpXchg = 56,648 AtomicRMW = 57,649 Resume = 58,650 LandingPad = 59,651 CleanupRet = 61,652 CatchRet = 62,653 CatchPad = 63,654 CleanupPad = 64,655 CatchSwitch = 65,656}657658/// Must match the layout of `LLVMRustCompressionKind`.659#[derive(Copy, Clone)]660#[repr(C)]661pub(crate) enum CompressionKind {662 None = 0,663 Zlib = 1,664 Zstd = 2,665}666667unsafe extern "C" {668 type Opaque;669}670#[repr(C)]671struct InvariantOpaque<'a> {672 _marker: PhantomData<&'a mut &'a ()>,673 _opaque: Opaque,674}675676// Opaque pointer types677unsafe extern "C" {678 pub(crate) type Module;679 pub(crate) type Context;680 pub(crate) type Type;681 pub(crate) type Value;682 pub(crate) type ConstantInt;683 pub(crate) type Attribute;684 pub(crate) type Metadata;685 pub(crate) type BasicBlock;686 pub(crate) type Comdat;687 /// `&'ll DbgRecord` represents `LLVMDbgRecordRef`.688 pub(crate) type DbgRecord;689}690#[repr(C)]691pub(crate) struct Builder<'a>(InvariantOpaque<'a>);692#[repr(C)]693pub(crate) struct PassManager<'a>(InvariantOpaque<'a>);694unsafe extern "C" {695 pub type TargetMachine;696}697unsafe extern "C" {698 pub(crate) type Twine;699 pub(crate) type DiagnosticInfo;700 pub(crate) type SMDiagnostic;701}702/// Opaque pointee of `LLVMOperandBundleRef`.703#[repr(C)]704pub(crate) struct OperandBundle<'a>(InvariantOpaque<'a>);705#[repr(C)]706pub(crate) struct Linker<'a>(InvariantOpaque<'a>);707708unsafe extern "C" {709 pub(crate) type DiagnosticHandler;710}711712pub(crate) type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);713714pub(crate) mod debuginfo {715 use bitflags::bitflags;716717 use super::{InvariantOpaque, Metadata};718719 /// Opaque target type for references to an LLVM debuginfo builder.720 ///721 /// `&'_ DIBuilder<'ll>` corresponds to `LLVMDIBuilderRef`, which is the722 /// LLVM-C wrapper for `DIBuilder *`.723 ///724 /// Debuginfo builders are created and destroyed during codegen, so the725 /// builder reference typically has a shorter lifetime than the LLVM726 /// session (`'ll`) that it participates in.727 #[repr(C)]728 pub(crate) struct DIBuilder<'ll>(InvariantOpaque<'ll>);729730 pub(crate) type DIDescriptor = Metadata;731 pub(crate) type DILocation = Metadata;732 pub(crate) type DIScope = DIDescriptor;733 pub(crate) type DIFile = DIScope;734 pub(crate) type DILexicalBlock = DIScope;735 pub(crate) type DISubprogram = DIScope;736 pub(crate) type DIType = DIDescriptor;737 pub(crate) type DIBasicType = DIType;738 pub(crate) type DIDerivedType = DIType;739 pub(crate) type DICompositeType = DIDerivedType;740 pub(crate) type DIVariable = DIDescriptor;741 pub(crate) type DIArray = DIDescriptor;742 pub(crate) type DIEnumerator = DIDescriptor;743 pub(crate) type DITemplateTypeParameter = DIDescriptor;744745 bitflags! {746 /// Must match the layout of `LLVMDIFlags` in the LLVM-C API.747 ///748 /// Each value declared here must also be covered by the static749 /// assertions in `RustWrapper.cpp` used by `fromRust(LLVMDIFlags)`.750 #[repr(transparent)]751 #[derive(Clone, Copy, Default)]752 pub(crate) struct DIFlags: u32 {753 const FlagZero = 0;754 const FlagPrivate = 1;755 const FlagProtected = 2;756 const FlagPublic = 3;757 const FlagFwdDecl = (1 << 2);758 const FlagAppleBlock = (1 << 3);759 const FlagReservedBit4 = (1 << 4);760 const FlagVirtual = (1 << 5);761 const FlagArtificial = (1 << 6);762 const FlagExplicit = (1 << 7);763 const FlagPrototyped = (1 << 8);764 const FlagObjcClassComplete = (1 << 9);765 const FlagObjectPointer = (1 << 10);766 const FlagVector = (1 << 11);767 const FlagStaticMember = (1 << 12);768 const FlagLValueReference = (1 << 13);769 const FlagRValueReference = (1 << 14);770 const FlagReserved = (1 << 15);771 const FlagSingleInheritance = (1 << 16);772 const FlagMultipleInheritance = (2 << 16);773 const FlagVirtualInheritance = (3 << 16);774 const FlagIntroducedVirtual = (1 << 18);775 const FlagBitField = (1 << 19);776 const FlagNoReturn = (1 << 20);777 // The bit at (1 << 21) is unused, but was `LLVMDIFlagMainSubprogram`.778 const FlagTypePassByValue = (1 << 22);779 const FlagTypePassByReference = (1 << 23);780 const FlagEnumClass = (1 << 24);781 const FlagThunk = (1 << 25);782 const FlagNonTrivial = (1 << 26);783 const FlagBigEndian = (1 << 27);784 const FlagLittleEndian = (1 << 28);785 }786 }787788 // These values **must** match with LLVMRustDISPFlags!!789 bitflags! {790 #[repr(transparent)]791 #[derive(Clone, Copy, Default)]792 pub(crate) struct DISPFlags: u32 {793 const SPFlagZero = 0;794 const SPFlagVirtual = 1;795 const SPFlagPureVirtual = 2;796 const SPFlagLocalToUnit = (1 << 2);797 const SPFlagDefinition = (1 << 3);798 const SPFlagOptimized = (1 << 4);799 const SPFlagMainSubprogram = (1 << 5);800 }801 }802803 /// LLVMRustDebugEmissionKind804 #[derive(Copy, Clone)]805 #[repr(C)]806 pub(crate) enum DebugEmissionKind {807 NoDebug,808 FullDebug,809 LineTablesOnly,810 DebugDirectivesOnly,811 }812813 /// LLVMRustDebugNameTableKind814 #[derive(Clone, Copy)]815 #[repr(C)]816 pub(crate) enum DebugNameTableKind {817 Default,818 #[expect(dead_code)]819 Gnu,820 None,821 }822}823824// These values **must** match with LLVMRustAllocKindFlags825bitflags! {826 #[repr(transparent)]827 #[derive(Default)]828 pub(crate) struct AllocKindFlags : u64 {829 const Unknown = 0;830 const Alloc = 1;831 const Realloc = 1 << 1;832 const Free = 1 << 2;833 const Uninitialized = 1 << 3;834 const Zeroed = 1 << 4;835 const Aligned = 1 << 5;836 }837}838839// These values **must** match with LLVMGEPNoWrapFlags840bitflags! {841 #[repr(transparent)]842 #[derive(Default)]843 pub struct GEPNoWrapFlags : c_uint {844 const InBounds = 1 << 0;845 const NUSW = 1 << 1;846 const NUW = 1 << 2;847 }848}849850unsafe extern "C" {851 pub(crate) type Buffer;852}853854pub(crate) type SelfProfileBeforePassCallback =855 unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);856pub(crate) type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);857858pub(crate) type GetSymbolsCallback =859 unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void;860pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;861862unsafe extern "C" {863 // Create and destroy contexts.864 pub(crate) fn LLVMContextCreate() -> &'static mut Context;865 pub(crate) fn LLVMContextDispose(C: &'static mut Context);866 pub(crate) fn LLVMContextSetDiscardValueNames(C: &Context, Discard: Bool);867 pub(crate) fn LLVMGetMDKindIDInContext(868 C: &Context,869 Name: *const c_char,870 SLen: c_uint,871 ) -> MetadataKindId;872873 pub(crate) fn LLVMDisposeTargetMachine(T: ptr::NonNull<TargetMachine>);874875 // Create modules.876 pub(crate) fn LLVMModuleCreateWithNameInContext(877 ModuleID: *const c_char,878 C: &Context,879 ) -> &Module;880 pub(crate) safe fn LLVMCloneModule(M: &Module) -> &Module;881882 /// Data layout. See Module::getDataLayout.883 pub(crate) fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char;884 pub(crate) fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);885886 /// Append inline assembly to a module. See `Module::appendModuleInlineAsm`.887 pub(crate) fn LLVMAppendModuleInlineAsm(888 M: &Module,889 Asm: *const c_uchar, // See "PTR_LEN_STR".890 Len: size_t,891 );892893 /// Create the specified uniqued inline asm string. See `InlineAsm::get()`.894 pub(crate) fn LLVMGetInlineAsm<'ll>(895 Ty: &'ll Type,896 AsmString: *const c_uchar, // See "PTR_LEN_STR".897 AsmStringSize: size_t,898 Constraints: *const c_uchar, // See "PTR_LEN_STR".899 ConstraintsSize: size_t,900 HasSideEffects: llvm::Bool,901 IsAlignStack: llvm::Bool,902 Dialect: AsmDialect,903 CanThrow: llvm::Bool,904 ) -> &'ll Value;905906 pub(crate) safe fn LLVMGetTypeKind(Ty: &Type) -> RawEnum<TypeKind>;907908 // Operations on integer types909 pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type;910 pub(crate) fn LLVMInt8TypeInContext(C: &Context) -> &Type;911 pub(crate) fn LLVMInt16TypeInContext(C: &Context) -> &Type;912 pub(crate) fn LLVMInt32TypeInContext(C: &Context) -> &Type;913 pub(crate) fn LLVMInt64TypeInContext(C: &Context) -> &Type;914 pub(crate) safe fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;915916 pub(crate) fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;917918 // Operations on real types919 pub(crate) fn LLVMHalfTypeInContext(C: &Context) -> &Type;920 pub(crate) fn LLVMFloatTypeInContext(C: &Context) -> &Type;921 pub(crate) fn LLVMDoubleTypeInContext(C: &Context) -> &Type;922 pub(crate) fn LLVMFP128TypeInContext(C: &Context) -> &Type;923924 // Operations on non-IEEE real types925 pub(crate) fn LLVMBFloatTypeInContext(C: &Context) -> &Type;926927 // Operations on function types928 pub(crate) fn LLVMFunctionType<'a>(929 ReturnType: &'a Type,930 ParamTypes: *const &'a Type,931 ParamCount: c_uint,932 IsVarArg: Bool,933 ) -> &'a Type;934 pub(crate) fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;935 pub(crate) fn LLVMGetParamTypes<'a>(FunctionTy: &'a Type, Dest: *mut &'a Type);936 pub(crate) fn LLVMGetReturnType(FunctionTy: &Type) -> &Type;937 pub(crate) fn LLVMIsFunctionVarArg(FunctionTy: &Type) -> Bool;938939 // Operations on struct types940 pub(crate) fn LLVMStructTypeInContext<'a>(941 C: &'a Context,942 ElementTypes: *const &'a Type,943 ElementCount: c_uint,944 Packed: Bool,945 ) -> &'a Type;946947 // Operations on array, pointer, and vector types (sequence types)948 pub(crate) safe fn LLVMPointerTypeInContext(C: &Context, AddressSpace: c_uint) -> &Type;949 pub(crate) fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;950 pub(crate) fn LLVMScalableVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;951952 pub(crate) fn LLVMGetElementType(Ty: &Type) -> &Type;953 pub(crate) fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;954955 // Operations on other types956 pub(crate) fn LLVMVoidTypeInContext(C: &Context) -> &Type;957958 // Operations on all values959 pub(crate) fn LLVMTypeOf(Val: &Value) -> &Type;960 pub(crate) fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char;961 pub(crate) fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t);962 pub(crate) fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value);963 pub(crate) safe fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: MetadataKindId, Node: &'a Value);964 pub(crate) fn LLVMGlobalSetMetadata<'a>(965 Val: &'a Value,966 KindID: MetadataKindId,967 Metadata: &'a Metadata,968 );969 pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;970971 // Operations on constants of any type972 pub(crate) fn LLVMConstNull(Ty: &Type) -> &Value;973 pub(crate) fn LLVMGetUndef(Ty: &Type) -> &Value;974 pub(crate) fn LLVMGetPoison(Ty: &Type) -> &Value;975976 // Operations on metadata977 pub(crate) fn LLVMMDStringInContext2(978 C: &Context,979 Str: *const c_char,980 SLen: size_t,981 ) -> &Metadata;982 pub(crate) fn LLVMMDNodeInContext2<'a>(983 C: &'a Context,984 Vals: *const &'a Metadata,985 Count: size_t,986 ) -> &'a Metadata;987 pub(crate) fn LLVMAddNamedMetadataOperand<'a>(988 M: &'a Module,989 Name: *const c_char,990 Val: &'a Value,991 );992993 // Operations on scalar constants994 pub(crate) fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;995 pub(crate) fn LLVMConstIntOfArbitraryPrecision(996 IntTy: &Type,997 Wn: c_uint,998 Ws: *const u64,999 ) -> &Value;1000 pub(crate) fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;10011002 // Operations on composite constants1003 pub(crate) fn LLVMConstArray2<'a>(1004 ElementTy: &'a Type,1005 ConstantVals: *const &'a Value,1006 Length: u64,1007 ) -> &'a Value;1008 pub(crate) fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type;1009 pub(crate) fn LLVMConstStringInContext2(1010 C: &Context,1011 Str: *const c_char,1012 Length: size_t,1013 DontNullTerminate: Bool,1014 ) -> &Value;1015 pub(crate) fn LLVMConstStructInContext<'a>(1016 C: &'a Context,1017 ConstantVals: *const &'a Value,1018 Count: c_uint,1019 Packed: Bool,1020 ) -> &'a Value;1021 pub(crate) fn LLVMConstNamedStruct<'a>(1022 StructTy: &'a Type,1023 ConstantVals: *const &'a Value,1024 Count: c_uint,1025 ) -> &'a Value;1026 pub(crate) fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;10271028 // Constant expressions1029 pub(crate) fn LLVMConstInBoundsGEP2<'a>(1030 ty: &'a Type,1031 ConstantVal: &'a Value,1032 ConstantIndices: *const &'a Value,1033 NumIndices: c_uint,1034 ) -> &'a Value;1035 pub(crate) fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;1036 pub(crate) fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;1037 pub(crate) fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;1038 pub(crate) fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;1039 pub(crate) fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>;1040 pub(crate) fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode;1041 pub(crate) fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>;10421043 // Operations on global variables, functions, and aliases (globals)1044 pub(crate) fn LLVMIsDeclaration(Global: &Value) -> Bool;1045 pub(crate) fn LLVMGetLinkage(Global: &Value) -> RawEnum<Linkage>;1046 pub(crate) fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage);1047 pub(crate) fn LLVMSetSection(Global: &Value, Section: *const c_char);1048 pub(crate) fn LLVMGetVisibility(Global: &Value) -> RawEnum<Visibility>;1049 pub(crate) fn LLVMSetVisibility(Global: &Value, Viz: Visibility);1050 pub(crate) fn LLVMGetAlignment(Global: &Value) -> c_uint;1051 pub(crate) fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);1052 pub(crate) fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);1053 pub(crate) fn LLVMGlobalGetValueType(Global: &Value) -> &Type;10541055 // Operations on global variables1056 pub(crate) safe fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;1057 pub(crate) fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;1058 pub(crate) fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;1059 pub(crate) fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;1060 pub(crate) fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;1061 pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value);1062 pub(crate) safe fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;1063 pub(crate) fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value);1064 pub(crate) safe fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool;1065 pub(crate) fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);1066 pub(crate) safe fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;1067 pub(crate) safe fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);1068 pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);1069 pub(crate) safe fn LLVMSetTailCallKind(CallInst: &Value, kind: TailCallKind);1070 pub(crate) safe fn LLVMSetExternallyInitialized(GlobalVar: &Value, IsExtInit: Bool);10711072 // Operations on attributes1073 pub(crate) fn LLVMCreateStringAttribute(1074 C: &Context,1075 Name: *const c_char,1076 NameLen: c_uint,1077 Value: *const c_char,1078 ValueLen: c_uint,1079 ) -> &Attribute;10801081 // Operations on functions1082 pub(crate) fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);1083 pub(crate) fn LLVMAddFunction<'a>(1084 Mod: &'a Module,1085 Name: *const c_char,1086 FunctionTy: &'a Type,1087 ) -> &'a Value;1088 pub(crate) fn LLVMDeleteFunction(Fn: &Value);10891090 // Operations about llvm intrinsics1091 pub(crate) fn LLVMLookupIntrinsicID(Name: *const c_char, NameLen: size_t) -> c_uint;1092 pub(crate) fn LLVMIntrinsicIsOverloaded(ID: NonZero<c_uint>) -> Bool;1093 pub(crate) fn LLVMGetIntrinsicDeclaration<'a>(1094 Mod: &'a Module,1095 ID: NonZero<c_uint>,1096 ParamTypes: *const &'a Type,1097 ParamCount: size_t,1098 ) -> &'a Value;1099 pub(crate) fn LLVMRustUpgradeIntrinsicFunction<'a>(1100 Fn: &'a Value,1101 NewFn: &mut Option<&'a Value>,1102 ) -> bool;1103 pub(crate) fn LLVMRustIsTargetIntrinsic(ID: NonZero<c_uint>) -> bool;11041105 // Operations on parameters1106 pub(crate) fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;1107 pub(crate) safe fn LLVMCountParams(Fn: &Value) -> c_uint;1108 pub(crate) fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;11091110 // Operations on basic blocks1111 pub(crate) fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;1112 pub(crate) fn LLVMAppendBasicBlockInContext<'a>(1113 C: &'a Context,1114 Fn: &'a Value,1115 Name: *const c_char,1116 ) -> &'a BasicBlock;11171118 // Operations on instructions1119 pub(crate) fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;1120 pub(crate) fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;1121 pub(crate) fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>;11221123 // Operations on call sites1124 pub(crate) fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);11251126 // Operations on load/store instructions (only)1127 pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);1128 pub(crate) fn LLVMSetOrdering(MemoryAccessInst: &Value, Ordering: AtomicOrdering);11291130 // Operations on phi nodes1131 pub(crate) fn LLVMAddIncoming<'a>(1132 PhiNode: &'a Value,1133 IncomingValues: *const &'a Value,1134 IncomingBlocks: *const &'a BasicBlock,1135 Count: c_uint,1136 );11371138 // Instruction builders1139 pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;1140 pub(crate) fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);1141 pub(crate) fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock;1142 pub(crate) fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);11431144 // Metadata1145 pub(crate) fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: *const Metadata);1146 pub(crate) fn LLVMGetCurrentDebugLocation2<'a>(Builder: &Builder<'a>) -> Option<&'a Metadata>;11471148 // Terminators1149 pub(crate) safe fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;1150 pub(crate) fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value;1151 pub(crate) fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;1152 pub(crate) fn LLVMBuildCondBr<'a>(1153 B: &Builder<'a>,1154 If: &'a Value,1155 Then: &'a BasicBlock,1156 Else: &'a BasicBlock,1157 ) -> &'a Value;1158 pub(crate) fn LLVMBuildSwitch<'a>(1159 B: &Builder<'a>,1160 V: &'a Value,1161 Else: &'a BasicBlock,1162 NumCases: c_uint,1163 ) -> &'a Value;1164 pub(crate) fn LLVMBuildLandingPad<'a>(1165 B: &Builder<'a>,1166 Ty: &'a Type,1167 PersFn: Option<&'a Value>,1168 NumClauses: c_uint,1169 Name: *const c_char,1170 ) -> &'a Value;1171 pub(crate) fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;1172 pub(crate) fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;11731174 pub(crate) fn LLVMBuildCleanupPad<'a>(1175 B: &Builder<'a>,1176 ParentPad: Option<&'a Value>,1177 Args: *const &'a Value,1178 NumArgs: c_uint,1179 Name: *const c_char,1180 ) -> Option<&'a Value>;1181 pub(crate) fn LLVMBuildCleanupRet<'a>(1182 B: &Builder<'a>,1183 CleanupPad: &'a Value,1184 BB: Option<&'a BasicBlock>,1185 ) -> Option<&'a Value>;1186 pub(crate) fn LLVMBuildCatchPad<'a>(1187 B: &Builder<'a>,1188 ParentPad: &'a Value,1189 Args: *const &'a Value,1190 NumArgs: c_uint,1191 Name: *const c_char,1192 ) -> Option<&'a Value>;1193 pub(crate) fn LLVMBuildCatchRet<'a>(1194 B: &Builder<'a>,1195 CatchPad: &'a Value,1196 BB: &'a BasicBlock,1197 ) -> Option<&'a Value>;1198 pub(crate) fn LLVMBuildCatchSwitch<'a>(1199 Builder: &Builder<'a>,1200 ParentPad: Option<&'a Value>,1201 UnwindBB: Option<&'a BasicBlock>,1202 NumHandlers: c_uint,1203 Name: *const c_char,1204 ) -> Option<&'a Value>;1205 pub(crate) fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock);1206 pub(crate) fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);12071208 // Add a case to the switch instruction1209 pub(crate) fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);12101211 // Add a clause to the landing pad instruction1212 pub(crate) fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value);12131214 // Set the cleanup on a landing pad instruction1215 pub(crate) fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);12161217 // Arithmetic1218 pub(crate) fn LLVMBuildAdd<'a>(1219 B: &Builder<'a>,1220 LHS: &'a Value,1221 RHS: &'a Value,1222 Name: *const c_char,1223 ) -> &'a Value;1224 pub(crate) fn LLVMBuildFAdd<'a>(1225 B: &Builder<'a>,1226 LHS: &'a Value,1227 RHS: &'a Value,1228 Name: *const c_char,1229 ) -> &'a Value;1230 pub(crate) fn LLVMBuildSub<'a>(1231 B: &Builder<'a>,1232 LHS: &'a Value,1233 RHS: &'a Value,1234 Name: *const c_char,1235 ) -> &'a Value;1236 pub(crate) fn LLVMBuildFSub<'a>(1237 B: &Builder<'a>,1238 LHS: &'a Value,1239 RHS: &'a Value,1240 Name: *const c_char,1241 ) -> &'a Value;1242 pub(crate) fn LLVMBuildMul<'a>(1243 B: &Builder<'a>,1244 LHS: &'a Value,1245 RHS: &'a Value,1246 Name: *const c_char,1247 ) -> &'a Value;1248 pub(crate) fn LLVMBuildFMul<'a>(1249 B: &Builder<'a>,1250 LHS: &'a Value,1251 RHS: &'a Value,1252 Name: *const c_char,1253 ) -> &'a Value;1254 pub(crate) fn LLVMBuildUDiv<'a>(1255 B: &Builder<'a>,1256 LHS: &'a Value,1257 RHS: &'a Value,1258 Name: *const c_char,1259 ) -> &'a Value;1260 pub(crate) fn LLVMBuildExactUDiv<'a>(1261 B: &Builder<'a>,1262 LHS: &'a Value,1263 RHS: &'a Value,1264 Name: *const c_char,1265 ) -> &'a Value;1266 pub(crate) fn LLVMBuildSDiv<'a>(1267 B: &Builder<'a>,1268 LHS: &'a Value,1269 RHS: &'a Value,1270 Name: *const c_char,1271 ) -> &'a Value;1272 pub(crate) fn LLVMBuildExactSDiv<'a>(1273 B: &Builder<'a>,1274 LHS: &'a Value,1275 RHS: &'a Value,1276 Name: *const c_char,1277 ) -> &'a Value;1278 pub(crate) fn LLVMBuildFDiv<'a>(1279 B: &Builder<'a>,1280 LHS: &'a Value,1281 RHS: &'a Value,1282 Name: *const c_char,1283 ) -> &'a Value;1284 pub(crate) fn LLVMBuildURem<'a>(1285 B: &Builder<'a>,1286 LHS: &'a Value,1287 RHS: &'a Value,1288 Name: *const c_char,1289 ) -> &'a Value;1290 pub(crate) fn LLVMBuildSRem<'a>(1291 B: &Builder<'a>,1292 LHS: &'a Value,1293 RHS: &'a Value,1294 Name: *const c_char,1295 ) -> &'a Value;1296 pub(crate) fn LLVMBuildFRem<'a>(1297 B: &Builder<'a>,1298 LHS: &'a Value,1299 RHS: &'a Value,1300 Name: *const c_char,1301 ) -> &'a Value;1302 pub(crate) fn LLVMBuildShl<'a>(1303 B: &Builder<'a>,1304 LHS: &'a Value,1305 RHS: &'a Value,1306 Name: *const c_char,1307 ) -> &'a Value;1308 pub(crate) fn LLVMBuildLShr<'a>(1309 B: &Builder<'a>,1310 LHS: &'a Value,1311 RHS: &'a Value,1312 Name: *const c_char,1313 ) -> &'a Value;1314 pub(crate) fn LLVMBuildAShr<'a>(1315 B: &Builder<'a>,1316 LHS: &'a Value,1317 RHS: &'a Value,1318 Name: *const c_char,1319 ) -> &'a Value;1320 pub(crate) fn LLVMBuildNSWAdd<'a>(1321 B: &Builder<'a>,1322 LHS: &'a Value,1323 RHS: &'a Value,1324 Name: *const c_char,1325 ) -> &'a Value;1326 pub(crate) fn LLVMBuildNUWAdd<'a>(1327 B: &Builder<'a>,1328 LHS: &'a Value,1329 RHS: &'a Value,1330 Name: *const c_char,1331 ) -> &'a Value;1332 pub(crate) fn LLVMBuildNSWSub<'a>(1333 B: &Builder<'a>,1334 LHS: &'a Value,1335 RHS: &'a Value,1336 Name: *const c_char,1337 ) -> &'a Value;1338 pub(crate) fn LLVMBuildNUWSub<'a>(1339 B: &Builder<'a>,1340 LHS: &'a Value,1341 RHS: &'a Value,1342 Name: *const c_char,1343 ) -> &'a Value;1344 pub(crate) fn LLVMBuildNSWMul<'a>(1345 B: &Builder<'a>,1346 LHS: &'a Value,1347 RHS: &'a Value,1348 Name: *const c_char,1349 ) -> &'a Value;1350 pub(crate) fn LLVMBuildNUWMul<'a>(1351 B: &Builder<'a>,1352 LHS: &'a Value,1353 RHS: &'a Value,1354 Name: *const c_char,1355 ) -> &'a Value;1356 pub(crate) fn LLVMBuildAnd<'a>(1357 B: &Builder<'a>,1358 LHS: &'a Value,1359 RHS: &'a Value,1360 Name: *const c_char,1361 ) -> &'a Value;1362 pub(crate) fn LLVMBuildOr<'a>(1363 B: &Builder<'a>,1364 LHS: &'a Value,1365 RHS: &'a Value,1366 Name: *const c_char,1367 ) -> &'a Value;1368 pub(crate) fn LLVMBuildXor<'a>(1369 B: &Builder<'a>,1370 LHS: &'a Value,1371 RHS: &'a Value,1372 Name: *const c_char,1373 ) -> &'a Value;1374 pub(crate) fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char)1375 -> &'a Value;1376 pub(crate) fn LLVMBuildFNeg<'a>(1377 B: &Builder<'a>,1378 V: &'a Value,1379 Name: *const c_char,1380 ) -> &'a Value;1381 pub(crate) fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char)1382 -> &'a Value;13831384 // Extra flags on arithmetic1385 pub(crate) fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool);1386 pub(crate) fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool);1387 pub(crate) fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool);13881389 // Memory1390 pub(crate) fn LLVMBuildAlloca<'a>(1391 B: &Builder<'a>,1392 Ty: &'a Type,1393 Name: *const c_char,1394 ) -> &'a Value;1395 pub(crate) fn LLVMBuildLoad2<'a>(1396 B: &Builder<'a>,1397 Ty: &'a Type,1398 PointerVal: &'a Value,1399 Name: *const c_char,1400 ) -> &'a Value;14011402 pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;14031404 pub(crate) fn LLVMBuildGEPWithNoWrapFlags<'a>(1405 B: &Builder<'a>,1406 Ty: &'a Type,1407 Pointer: &'a Value,1408 Indices: *const &'a Value,1409 NumIndices: c_uint,1410 Name: *const c_char,1411 Flags: GEPNoWrapFlags,1412 ) -> &'a Value;14131414 // Casts1415 pub(crate) fn LLVMBuildTrunc<'a>(1416 B: &Builder<'a>,1417 Val: &'a Value,1418 DestTy: &'a Type,1419 Name: *const c_char,1420 ) -> &'a Value;1421 pub(crate) fn LLVMBuildZExt<'a>(1422 B: &Builder<'a>,1423 Val: &'a Value,1424 DestTy: &'a Type,1425 Name: *const c_char,1426 ) -> &'a Value;1427 pub(crate) fn LLVMBuildSExt<'a>(1428 B: &Builder<'a>,1429 Val: &'a Value,1430 DestTy: &'a Type,1431 Name: *const c_char,1432 ) -> &'a Value;1433 pub(crate) fn LLVMBuildFPToUI<'a>(1434 B: &Builder<'a>,1435 Val: &'a Value,1436 DestTy: &'a Type,1437 Name: *const c_char,1438 ) -> &'a Value;1439 pub(crate) fn LLVMBuildFPToSI<'a>(1440 B: &Builder<'a>,1441 Val: &'a Value,1442 DestTy: &'a Type,1443 Name: *const c_char,1444 ) -> &'a Value;1445 pub(crate) fn LLVMBuildUIToFP<'a>(1446 B: &Builder<'a>,1447 Val: &'a Value,1448 DestTy: &'a Type,1449 Name: *const c_char,1450 ) -> &'a Value;1451 pub(crate) fn LLVMBuildSIToFP<'a>(1452 B: &Builder<'a>,1453 Val: &'a Value,1454 DestTy: &'a Type,1455 Name: *const c_char,1456 ) -> &'a Value;1457 pub(crate) fn LLVMBuildFPTrunc<'a>(1458 B: &Builder<'a>,1459 Val: &'a Value,1460 DestTy: &'a Type,1461 Name: *const c_char,1462 ) -> &'a Value;1463 pub(crate) fn LLVMBuildFPExt<'a>(1464 B: &Builder<'a>,1465 Val: &'a Value,1466 DestTy: &'a Type,1467 Name: *const c_char,1468 ) -> &'a Value;1469 pub(crate) fn LLVMBuildPtrToInt<'a>(1470 B: &Builder<'a>,1471 Val: &'a Value,1472 DestTy: &'a Type,1473 Name: *const c_char,1474 ) -> &'a Value;1475 pub(crate) fn LLVMBuildIntToPtr<'a>(1476 B: &Builder<'a>,1477 Val: &'a Value,1478 DestTy: &'a Type,1479 Name: *const c_char,1480 ) -> &'a Value;1481 pub(crate) fn LLVMBuildBitCast<'a>(1482 B: &Builder<'a>,1483 Val: &'a Value,1484 DestTy: &'a Type,1485 Name: *const c_char,1486 ) -> &'a Value;1487 pub(crate) fn LLVMBuildPointerCast<'a>(1488 B: &Builder<'a>,1489 Val: &'a Value,1490 DestTy: &'a Type,1491 Name: *const c_char,1492 ) -> &'a Value;1493 pub(crate) fn LLVMBuildIntCast2<'a>(1494 B: &Builder<'a>,1495 Val: &'a Value,1496 DestTy: &'a Type,1497 IsSigned: Bool,1498 Name: *const c_char,1499 ) -> &'a Value;15001501 // Comparisons1502 pub(crate) fn LLVMBuildICmp<'a>(1503 B: &Builder<'a>,1504 Op: c_uint,1505 LHS: &'a Value,1506 RHS: &'a Value,1507 Name: *const c_char,1508 ) -> &'a Value;1509 pub(crate) fn LLVMBuildFCmp<'a>(1510 B: &Builder<'a>,1511 Op: c_uint,1512 LHS: &'a Value,1513 RHS: &'a Value,1514 Name: *const c_char,1515 ) -> &'a Value;15161517 // Miscellaneous instructions1518 pub(crate) fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char)1519 -> &'a Value;1520 pub(crate) fn LLVMBuildSelect<'a>(1521 B: &Builder<'a>,1522 If: &'a Value,1523 Then: &'a Value,1524 Else: &'a Value,1525 Name: *const c_char,1526 ) -> &'a Value;1527 pub(crate) fn LLVMBuildVAArg<'a>(1528 B: &Builder<'a>,1529 list: &'a Value,1530 Ty: &'a Type,1531 Name: *const c_char,1532 ) -> &'a Value;1533 pub(crate) fn LLVMBuildExtractElement<'a>(1534 B: &Builder<'a>,1535 VecVal: &'a Value,1536 Index: &'a Value,1537 Name: *const c_char,1538 ) -> &'a Value;1539 pub(crate) fn LLVMBuildInsertElement<'a>(1540 B: &Builder<'a>,1541 VecVal: &'a Value,1542 EltVal: &'a Value,1543 Index: &'a Value,1544 Name: *const c_char,1545 ) -> &'a Value;1546 pub(crate) fn LLVMBuildShuffleVector<'a>(1547 B: &Builder<'a>,1548 V1: &'a Value,1549 V2: &'a Value,1550 Mask: &'a Value,1551 Name: *const c_char,1552 ) -> &'a Value;1553 pub(crate) fn LLVMBuildExtractValue<'a>(1554 B: &Builder<'a>,1555 AggVal: &'a Value,1556 Index: c_uint,1557 Name: *const c_char,1558 ) -> &'a Value;1559 pub(crate) fn LLVMBuildInsertValue<'a>(1560 B: &Builder<'a>,1561 AggVal: &'a Value,1562 EltVal: &'a Value,1563 Index: c_uint,1564 Name: *const c_char,1565 ) -> &'a Value;15661567 // Atomic Operations1568 pub(crate) fn LLVMBuildAtomicCmpXchg<'a>(1569 B: &Builder<'a>,1570 LHS: &'a Value,1571 CMP: &'a Value,1572 RHS: &'a Value,1573 Order: AtomicOrdering,1574 FailureOrder: AtomicOrdering,1575 SingleThreaded: Bool,1576 ) -> &'a Value;15771578 pub(crate) fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);15791580 pub(crate) fn LLVMBuildAtomicRMW<'a>(1581 B: &Builder<'a>,1582 Op: AtomicRmwBinOp,1583 LHS: &'a Value,1584 RHS: &'a Value,1585 Order: AtomicOrdering,1586 SingleThreaded: Bool,1587 ) -> &'a Value;15881589 pub(crate) fn LLVMBuildFence<'a>(1590 B: &Builder<'a>,1591 Order: AtomicOrdering,1592 SingleThreaded: Bool,1593 Name: *const c_char,1594 ) -> &'a Value;15951596 /// Writes a module to the specified path. Returns 0 on success.1597 pub(crate) fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;15981599 /// Creates a legacy pass manager -- only used for final codegen.1600 pub(crate) fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;16011602 pub(crate) fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);16031604 pub(crate) fn LLVMGetHostCPUFeatures() -> *mut c_char;16051606 pub(crate) fn LLVMDisposeMessage(message: *mut c_char);16071608 pub(crate) fn LLVMIsMultithreaded() -> Bool;16091610 pub(crate) fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;16111612 pub(crate) fn LLVMStructSetBody<'a>(1613 StructTy: &'a Type,1614 ElementTypes: *const &'a Type,1615 ElementCount: c_uint,1616 Packed: Bool,1617 );16181619 pub(crate) fn LLVMCountStructElementTypes(StructTy: &Type) -> c_uint;1620 pub(crate) fn LLVMGetStructElementTypes<'a>(StructTy: &'a Type, Dest: *mut &'a Type);16211622 pub(crate) safe fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;16231624 pub(crate) safe fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);16251626 pub(crate) fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;16271628 pub(crate) fn LLVMGetOrInsertComdat(M: &Module, Name: *const c_char) -> &Comdat;1629 pub(crate) fn LLVMSetComdat(V: &Value, C: &Comdat);16301631 pub(crate) fn LLVMCreateOperandBundle(1632 Tag: *const c_char,1633 TagLen: size_t,1634 Args: *const &'_ Value,1635 NumArgs: c_uint,1636 ) -> *mut OperandBundle<'_>;1637 pub(crate) fn LLVMDisposeOperandBundle(Bundle: ptr::NonNull<OperandBundle<'_>>);16381639 pub(crate) fn LLVMBuildCallWithOperandBundles<'a>(1640 B: &Builder<'a>,1641 Ty: &'a Type,1642 Fn: &'a Value,1643 Args: *const &'a Value,1644 NumArgs: c_uint,1645 Bundles: *const &OperandBundle<'a>,1646 NumBundles: c_uint,1647 Name: *const c_char,1648 ) -> &'a Value;1649 pub(crate) fn LLVMBuildInvokeWithOperandBundles<'a>(1650 B: &Builder<'a>,1651 Ty: &'a Type,1652 Fn: &'a Value,1653 Args: *const &'a Value,1654 NumArgs: c_uint,1655 Then: &'a BasicBlock,1656 Catch: &'a BasicBlock,1657 Bundles: *const &OperandBundle<'a>,1658 NumBundles: c_uint,1659 Name: *const c_char,1660 ) -> &'a Value;1661 pub(crate) fn LLVMBuildCallBr<'a>(1662 B: &Builder<'a>,1663 Ty: &'a Type,1664 Fn: &'a Value,1665 DefaultDest: &'a BasicBlock,1666 IndirectDests: *const &'a BasicBlock,1667 NumIndirectDests: c_uint,1668 Args: *const &'a Value,1669 NumArgs: c_uint,1670 Bundles: *const &OperandBundle<'a>,1671 NumBundles: c_uint,1672 Name: *const c_char,1673 ) -> &'a Value;1674}16751676#[cfg(feature = "llvm_offload")]1677pub(crate) use self::Offload::*;16781679#[cfg(feature = "llvm_offload")]1680mod Offload {1681 use super::*;1682 unsafe extern "C" {1683 /// Processes the module and writes it in an offload compatible way into a "host.out" file.1684 pub(crate) fn LLVMRustBundleImages<'a>(1685 M: &'a Module,1686 TM: &'a TargetMachine,1687 host_out: *const c_char,1688 ) -> bool;1689 pub(crate) unsafe fn LLVMRustOffloadEmbedBufferInModule<'a>(1690 _M: &'a Module,1691 _host_out: *const c_char,1692 ) -> bool;1693 pub(crate) fn LLVMRustOffloadMapper<'a>(1694 OldFn: &'a Value,1695 NewFn: &'a Value,1696 RebuiltArgs: *const &Value,1697 );1698 }1699}17001701#[cfg(not(feature = "llvm_offload"))]1702pub(crate) use self::Offload_fallback::*;17031704#[cfg(not(feature = "llvm_offload"))]1705mod Offload_fallback {1706 use super::*;1707 /// Processes the module and writes it in an offload compatible way into a "host.out" file.1708 /// Marked as unsafe to match the real offload wrapper which is unsafe due to FFI.1709 #[allow(unused_unsafe)]1710 pub(crate) unsafe fn LLVMRustBundleImages<'a>(1711 _M: &'a Module,1712 _TM: &'a TargetMachine,1713 _host_out: *const c_char,1714 ) -> bool {1715 unimplemented!("This rustc version was not built with LLVM Offload support!");1716 }1717 pub(crate) unsafe fn LLVMRustOffloadEmbedBufferInModule<'a>(1718 _M: &'a Module,1719 _host_out: *const c_char,1720 ) -> bool {1721 unimplemented!("This rustc version was not built with LLVM Offload support!");1722 }1723 #[allow(unused_unsafe)]1724 pub(crate) unsafe fn LLVMRustOffloadMapper<'a>(1725 _OldFn: &'a Value,1726 _NewFn: &'a Value,1727 _RebuiltArgs: *const &Value,1728 ) {1729 unimplemented!("This rustc version was not built with LLVM Offload support!");1730 }1731}17321733// FFI bindings for `DIBuilder` functions in the LLVM-C API.1734// Try to keep these in the same order as in `llvm/include/llvm-c/DebugInfo.h`.1735//1736// FIXME(#134001): Audit all `Option` parameters, especially in lists, to check1737// that they really are nullable on the C/C++ side. LLVM doesn't appear to1738// actually document which ones are nullable.1739unsafe extern "C" {1740 pub(crate) fn LLVMCreateDIBuilder<'ll>(M: &'ll Module) -> *mut DIBuilder<'ll>;1741 pub(crate) fn LLVMDisposeDIBuilder<'ll>(Builder: ptr::NonNull<DIBuilder<'ll>>);17421743 pub(crate) fn LLVMDIBuilderFinalize<'ll>(Builder: &DIBuilder<'ll>);17441745 pub(crate) fn LLVMDIBuilderCreateNameSpace<'ll>(1746 Builder: &DIBuilder<'ll>,1747 ParentScope: Option<&'ll Metadata>,1748 Name: *const c_uchar, // See "PTR_LEN_STR".1749 NameLen: size_t,1750 ExportSymbols: llvm::Bool,1751 ) -> &'ll Metadata;17521753 pub(crate) fn LLVMDIBuilderCreateLexicalBlock<'ll>(1754 Builder: &DIBuilder<'ll>,1755 Scope: &'ll Metadata,1756 File: &'ll Metadata,1757 Line: c_uint,1758 Column: c_uint,1759 ) -> &'ll Metadata;17601761 pub(crate) fn LLVMDIBuilderCreateLexicalBlockFile<'ll>(1762 Builder: &DIBuilder<'ll>,1763 Scope: &'ll Metadata,1764 File: &'ll Metadata,1765 Discriminator: c_uint, // (optional "DWARF path discriminator"; default is 0)1766 ) -> &'ll Metadata;17671768 pub(crate) fn LLVMDIBuilderCreateDebugLocation<'ll>(1769 Ctx: &'ll Context,1770 Line: c_uint,1771 Column: c_uint,1772 Scope: &'ll Metadata,1773 InlinedAt: Option<&'ll Metadata>,1774 ) -> &'ll Metadata;17751776 pub(crate) fn LLVMDIBuilderCreateSubroutineType<'ll>(1777 Builder: &DIBuilder<'ll>,1778 File: Option<&'ll Metadata>, // (ignored and has no effect)1779 ParameterTypes: *const Option<&'ll Metadata>,1780 NumParameterTypes: c_uint,1781 Flags: DIFlags, // (default is `DIFlags::DIFlagZero`)1782 ) -> &'ll Metadata;17831784 pub(crate) fn LLVMDIBuilderCreateUnionType<'ll>(1785 Builder: &DIBuilder<'ll>,1786 Scope: Option<&'ll Metadata>,1787 Name: *const c_uchar, // See "PTR_LEN_STR".1788 NameLen: size_t,1789 File: &'ll Metadata,1790 LineNumber: c_uint,1791 SizeInBits: u64,1792 AlignInBits: u32,1793 Flags: DIFlags,1794 Elements: *const Option<&'ll Metadata>,1795 NumElements: c_uint,1796 RunTimeLang: c_uint, // (optional Objective-C runtime version; default is 0)1797 UniqueId: *const c_uchar, // See "PTR_LEN_STR".1798 UniqueIdLen: size_t,1799 ) -> &'ll Metadata;18001801 pub(crate) fn LLVMDIBuilderCreateArrayType<'ll>(1802 Builder: &DIBuilder<'ll>,1803 Size: u64,1804 Align: u32,1805 Ty: &'ll Metadata,1806 Subscripts: *const &'ll Metadata,1807 NumSubscripts: c_uint,1808 ) -> &'ll Metadata;18091810 pub(crate) fn LLVMDIBuilderCreateBasicType<'ll>(1811 Builder: &DIBuilder<'ll>,1812 Name: *const c_uchar, // See "PTR_LEN_STR".1813 NameLen: size_t,1814 SizeInBits: u64,1815 Encoding: c_uint, // (`LLVMDWARFTypeEncoding`)1816 Flags: DIFlags, // (default is `DIFlags::DIFlagZero`)1817 ) -> &'ll Metadata;18181819 pub(crate) fn LLVMDIBuilderCreatePointerType<'ll>(1820 Builder: &DIBuilder<'ll>,1821 PointeeTy: &'ll Metadata,1822 SizeInBits: u64,1823 AlignInBits: u32,1824 AddressSpace: c_uint, // (optional DWARF address space; default is 0)1825 Name: *const c_uchar, // See "PTR_LEN_STR".1826 NameLen: size_t,1827 ) -> &'ll Metadata;18281829 pub(crate) fn LLVMDIBuilderCreateStructType<'ll>(1830 Builder: &DIBuilder<'ll>,1831 Scope: Option<&'ll Metadata>,1832 Name: *const c_uchar, // See "PTR_LEN_STR".1833 NameLen: size_t,1834 File: &'ll Metadata,1835 LineNumber: c_uint,1836 SizeInBits: u64,1837 AlignInBits: u32,1838 Flags: DIFlags,1839 DerivedFrom: Option<&'ll Metadata>,1840 Elements: *const Option<&'ll Metadata>,1841 NumElements: c_uint,1842 RunTimeLang: c_uint, // (optional Objective-C runtime version; default is 0)1843 VTableHolder: Option<&'ll Metadata>,1844 UniqueId: *const c_uchar, // See "PTR_LEN_STR".1845 UniqueIdLen: size_t,1846 ) -> &'ll Metadata;18471848 pub(crate) fn LLVMDIBuilderCreateMemberType<'ll>(1849 Builder: &DIBuilder<'ll>,1850 Scope: &'ll Metadata,1851 Name: *const c_uchar, // See "PTR_LEN_STR".1852 NameLen: size_t,1853 File: &'ll Metadata,1854 LineNo: c_uint,1855 SizeInBits: u64,1856 AlignInBits: u32,1857 OffsetInBits: u64,1858 Flags: DIFlags,1859 Ty: &'ll Metadata,1860 ) -> &'ll Metadata;18611862 pub(crate) fn LLVMDIBuilderCreateStaticMemberType<'ll>(1863 Builder: &DIBuilder<'ll>,1864 Scope: &'ll Metadata,1865 Name: *const c_uchar, // See "PTR_LEN_STR".1866 NameLen: size_t,1867 File: &'ll Metadata,1868 LineNumber: c_uint,1869 Type: &'ll Metadata,1870 Flags: DIFlags,1871 ConstantVal: Option<&'ll Value>,1872 AlignInBits: u32,1873 ) -> &'ll Metadata;18741875 /// Creates a "qualified type" in the C/C++ sense, by adding modifiers1876 /// like `const` or `volatile`.1877 pub(crate) fn LLVMDIBuilderCreateQualifiedType<'ll>(1878 Builder: &DIBuilder<'ll>,1879 Tag: c_uint, // (DWARF tag, e.g. `DW_TAG_const_type`)1880 Type: &'ll Metadata,1881 ) -> &'ll Metadata;18821883 pub(crate) fn LLVMDIBuilderCreateTypedef<'ll>(1884 Builder: &DIBuilder<'ll>,1885 Type: &'ll Metadata,1886 Name: *const c_uchar, // See "PTR_LEN_STR".1887 NameLen: size_t,1888 File: &'ll Metadata,1889 LineNo: c_uint,1890 Scope: Option<&'ll Metadata>,1891 AlignInBits: u32, // (optional; default is 0)1892 ) -> &'ll Metadata;18931894 pub(crate) fn LLVMDIBuilderGetOrCreateSubrange<'ll>(1895 Builder: &DIBuilder<'ll>,1896 LowerBound: i64,1897 Count: i64,1898 ) -> &'ll Metadata;18991900 pub(crate) fn LLVMDIBuilderGetOrCreateArray<'ll>(1901 Builder: &DIBuilder<'ll>,1902 Data: *const Option<&'ll Metadata>,1903 NumElements: size_t,1904 ) -> &'ll Metadata;19051906 pub(crate) fn LLVMDIBuilderCreateExpression<'ll>(1907 Builder: &DIBuilder<'ll>,1908 Addr: *const u64,1909 Length: size_t,1910 ) -> &'ll Metadata;19111912 pub(crate) fn LLVMDIBuilderCreateGlobalVariableExpression<'ll>(1913 Builder: &DIBuilder<'ll>,1914 Scope: Option<&'ll Metadata>,1915 Name: *const c_uchar, // See "PTR_LEN_STR".1916 NameLen: size_t,1917 Linkage: *const c_uchar, // See "PTR_LEN_STR".1918 LinkLen: size_t,1919 File: &'ll Metadata,1920 LineNo: c_uint,1921 Ty: &'ll Metadata,1922 LocalToUnit: llvm::Bool,1923 Expr: &'ll Metadata,1924 Decl: Option<&'ll Metadata>,1925 AlignInBits: u32,1926 ) -> &'ll Metadata;19271928 pub(crate) fn LLVMDIBuilderInsertDeclareRecordAtEnd<'ll>(1929 Builder: &DIBuilder<'ll>,1930 Storage: &'ll Value,1931 VarInfo: &'ll Metadata,1932 Expr: &'ll Metadata,1933 DebugLoc: &'ll Metadata,1934 Block: &'ll BasicBlock,1935 ) -> &'ll DbgRecord;19361937 pub(crate) fn LLVMDIBuilderInsertDbgValueRecordAtEnd<'ll>(1938 Builder: &DIBuilder<'ll>,1939 Val: &'ll Value,1940 VarInfo: &'ll Metadata,1941 Expr: &'ll Metadata,1942 DebugLoc: &'ll Metadata,1943 Block: &'ll BasicBlock,1944 ) -> &'ll DbgRecord;19451946 pub(crate) fn LLVMDIBuilderCreateAutoVariable<'ll>(1947 Builder: &DIBuilder<'ll>,1948 Scope: &'ll Metadata,1949 Name: *const c_uchar, // See "PTR_LEN_STR".1950 NameLen: size_t,1951 File: &'ll Metadata,1952 LineNo: c_uint,1953 Ty: &'ll Metadata,1954 AlwaysPreserve: llvm::Bool, // "If true, this descriptor will survive optimizations."1955 Flags: DIFlags,1956 AlignInBits: u32,1957 ) -> &'ll Metadata;19581959 pub(crate) fn LLVMDIBuilderCreateParameterVariable<'ll>(1960 Builder: &DIBuilder<'ll>,1961 Scope: &'ll Metadata,1962 Name: *const c_uchar, // See "PTR_LEN_STR".1963 NameLen: size_t,1964 ArgNo: c_uint,1965 File: &'ll Metadata,1966 LineNo: c_uint,1967 Ty: &'ll Metadata,1968 AlwaysPreserve: llvm::Bool, // "If true, this descriptor will survive optimizations."1969 Flags: DIFlags,1970 ) -> &'ll Metadata;1971}19721973#[link(name = "llvm-wrapper", kind = "static")]1974unsafe extern "C" {1975 pub(crate) fn LLVMRustInstallErrorHandlers();1976 pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();19771978 // Operations on all values1979 pub(crate) fn LLVMRustGlobalAddMetadata<'a>(1980 Val: &'a Value,1981 KindID: MetadataKindId,1982 Metadata: &'a Metadata,1983 );1984 pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;1985 pub(crate) fn LLVMRustStripPointerCasts<'a>(Val: &'a Value) -> &'a Value;19861987 // Operations on scalar constants1988 pub(crate) fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;1989 pub(crate) fn LLVMRustConstInt128Get(1990 ConstantVal: &ConstantInt,1991 SExt: bool,1992 high: &mut u64,1993 low: &mut u64,1994 ) -> bool;19951996 // Operations on global variables, functions, and aliases (globals)1997 pub(crate) fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);19981999 // Operations on global variables2000 pub(crate) fn LLVMRustGetOrInsertGlobal<'a>(
Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.