Skip to content

Commit 83cee26

Browse files
committed
lint ImproperCTypes: change what elements are being checked [...]
- do not check ADT definitions themselves, it turns out `repr(C)` is not a strong enough signal to determine if something is designed for FFIs - however, start checking static variables with `#[no_mangle]` or `#[export_name=_]`, even if that's not a perfect signal due to the lack of specified ABI - some changes to the LLVM codegen so it can be seen as FFI-safe
1 parent 9dfb1d0 commit 83cee26

File tree

9 files changed

+385
-239
lines changed

9 files changed

+385
-239
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,11 @@ fn report_inline_asm(
462462
cgcx.diag_emitter.inline_asm_error(span, msg, level, source);
463463
}
464464

465-
unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void) {
465+
unsafe extern "C" fn diagnostic_handler(info: Option<&DiagnosticInfo>, user: *mut c_void) {
466466
if user.is_null() {
467467
return;
468468
}
469+
let info = info.unwrap();
469470
let (cgcx, dcx) =
470471
unsafe { *(user as *const (&CodegenContext<LlvmCodegenBackend>, DiagCtxtHandle<'_>)) };
471472

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use libc::{c_char, c_uint};
66
use super::MetadataKindId;
77
use super::ffi::{AttributeKind, BasicBlock, Metadata, Module, Type, Value};
88
use crate::llvm::Bool;
9+
use crate::wrap_returns_in_options;
910

11+
wrap_returns_in_options! {
1012
#[link(name = "llvm-wrapper", kind = "static")]
1113
unsafe extern "C" {
1214
// Enzyme
@@ -15,7 +17,7 @@ unsafe extern "C" {
1517
pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
1618
pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
1719
pub(crate) fn LLVMRustEraseInstFromParent(V: &Value);
18-
pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
20+
|wrap pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
1921
pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
2022
pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool;
2123
pub(crate) fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64;
@@ -39,10 +41,11 @@ unsafe extern "C" {
3941
pub(crate) fn LLVMDumpModule(M: &Module);
4042
pub(crate) fn LLVMDumpValue(V: &Value);
4143
pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
42-
pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
44+
|wrap pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
4345
pub(crate) fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
4446
pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
4547
}
48+
}
4649

4750
#[repr(C)]
4851
#[derive(Copy, Clone, PartialEq)]

0 commit comments

Comments
 (0)