Skip to content

Commit 1e52d90

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 d15dbb5 commit 1e52d90

File tree

9 files changed

+381
-235
lines changed

9 files changed

+381
-235
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

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

469-
unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void) {
469+
unsafe extern "C" fn diagnostic_handler(info: Option<&DiagnosticInfo>, user: *mut c_void) {
470470
if user.is_null() {
471471
return;
472472
}
473+
let info = info.unwrap();
473474
let (cgcx, dcx) =
474475
unsafe { *(user as *const (&CodegenContext<LlvmCodegenBackend>, DiagCtxtHandle<'_>)) };
475476

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

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

10+
wrap_returns_in_options! {
911
#[link(name = "llvm-wrapper", kind = "static")]
1012
unsafe extern "C" {
1113
// Enzyme
@@ -14,7 +16,7 @@ unsafe extern "C" {
1416
pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
1517
pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
1618
pub(crate) fn LLVMRustEraseInstFromParent(V: &Value);
17-
pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
19+
|wrap pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
1820
pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
1921
pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool;
2022
pub(crate) fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64;
@@ -46,10 +48,11 @@ unsafe extern "C" {
4648
pub(crate) fn LLVMDumpModule(M: &Module);
4749
pub(crate) fn LLVMDumpValue(V: &Value);
4850
pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
49-
pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
51+
|wrap pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
5052
pub(crate) fn LLVMGetParams(Fnc: &Value, params: *mut &Value);
5153
pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
5254
}
55+
}
5356

5457
#[repr(C)]
5558
#[derive(Copy, Clone, PartialEq)]

0 commit comments

Comments
 (0)