Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl<'a> Drop for DiagnosticHandlers<'a> {
fn report_inline_asm(
cgcx: &CodegenContext,
msg: String,
level: llvm::DiagnosticLevel,
severity: llvm::DiagnosticSeverity,
cookie: u64,
source: Option<(String, Vec<InnerSpan>)>,
) -> InlineAsmError {
Expand All @@ -422,10 +422,10 @@ fn report_inline_asm(
let hi = BytePos::from_u32((cookie >> 32) as u32);
(lo, hi)
};
let level = match level {
llvm::DiagnosticLevel::Error => Level::Error,
llvm::DiagnosticLevel::Warning => Level::Warning(None),
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
let level = match severity {
llvm::DiagnosticSeverity::Error => Level::Error,
llvm::DiagnosticSeverity::Warning => Level::Warning(None),
llvm::DiagnosticSeverity::Note | llvm::DiagnosticSeverity::Remark => Level::Note,
};
let msg = msg.trim_prefix("error: ").to_string();
InlineAsmError { lo, hi, msg, level, source }
Expand Down Expand Up @@ -456,7 +456,7 @@ fn diagnostic_handler_callback_inner(
shared_emitter.inline_asm_error(report_inline_asm(
cgcx,
inline.message,
inline.level,
inline.severity,
inline.cookie,
inline.source,
));
Expand All @@ -479,21 +479,25 @@ fn diagnostic_handler_callback_inner(
message: &opt.message,
});
}
llvm::diagnostic::PGO(diagnostic_ref) | llvm::diagnostic::Linker(diagnostic_ref) => {
let message = llvm::build_string(|s| unsafe {
llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s)
})
.expect("non-UTF8 diagnostic");
dcx.emit_warn(FromLlvmDiag { message });
}
llvm::diagnostic::Unsupported(diagnostic_ref) => {

// FIXME(#164677): Don't ignore stack size warnings.
llvm::diagnostic::StackSize => {}

llvm::diagnostic::Other(diagnostic_ref) => {
let message = llvm::build_string(|s| unsafe {
llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s)
})
.expect("non-UTF8 diagnostic");
dcx.emit_err(FromLlvmDiag { message });
match diagnostic_ref.severity() {
llvm::DiagnosticSeverity::Error => {
dcx.emit_err(FromLlvmDiag { message });
}
llvm::DiagnosticSeverity::Warning => {
dcx.emit_warn(FromLlvmDiag { message });
}
_ => {}
};
}
llvm::diagnostic::UnknownDiagnostic(..) => {}
}
}

Expand Down
36 changes: 16 additions & 20 deletions compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl<'ll> OptimizationDiagnostic<'ll> {
}

pub(crate) struct SrcMgrDiagnostic {
pub level: super::DiagnosticLevel,
pub message: String,
pub source: Option<(String, Vec<InnerSpan>)>,
}
Expand All @@ -86,7 +85,6 @@ impl SrcMgrDiagnostic {
// diagnostics.
let mut have_source = false;
let mut buffer = String::new();
let mut level = super::DiagnosticLevel::Error;
let mut loc = 0;
let mut ranges = [0; 8];
let mut num_ranges = ranges.len() / 2;
Expand All @@ -96,7 +94,6 @@ impl SrcMgrDiagnostic {
diag,
message,
buffer,
&mut level,
&mut loc,
ranges.as_mut_ptr(),
&mut num_ranges,
Expand All @@ -108,7 +105,6 @@ impl SrcMgrDiagnostic {

SrcMgrDiagnostic {
message,
level,
source: have_source.then(|| {
let mut spans = vec![InnerSpan::new(loc as usize, loc as usize)];
for i in 0..num_ranges {
Expand All @@ -122,7 +118,7 @@ impl SrcMgrDiagnostic {

#[derive(Clone)]
pub(crate) struct InlineAsmDiagnostic {
pub level: super::DiagnosticLevel,
pub severity: super::DiagnosticSeverity,
pub cookie: u64,
pub message: String,
pub source: Option<(String, Vec<InnerSpan>)>,
Expand All @@ -132,14 +128,13 @@ impl InlineAsmDiagnostic {
unsafe fn unpackInlineAsm(di: &DiagnosticInfo) -> Self {
let mut cookie = 0;
let mut message = None;
let mut level = super::DiagnosticLevel::Error;

unsafe {
super::LLVMRustUnpackInlineAsmDiagnostic(di, &mut level, &mut cookie, &mut message);
super::LLVMRustUnpackInlineAsmDiagnostic(di, &mut cookie, &mut message);
}

InlineAsmDiagnostic {
level,
severity: di.severity(),
cookie,
message: super::twine_to_string(message.unwrap()),
source: None,
Expand All @@ -151,7 +146,7 @@ impl InlineAsmDiagnostic {
let smdiag =
unsafe { SrcMgrDiagnostic::unpack(super::LLVMRustGetSMDiagnostic(di, &mut cookie)) };
InlineAsmDiagnostic {
level: smdiag.level,
severity: di.severity(),
cookie,
message: smdiag.message,
source: smdiag.source,
Expand All @@ -162,13 +157,10 @@ impl InlineAsmDiagnostic {
pub(crate) enum Diagnostic<'ll> {
Optimization(OptimizationDiagnostic<'ll>),
InlineAsm(InlineAsmDiagnostic),
PGO(&'ll DiagnosticInfo),
Linker(&'ll DiagnosticInfo),
Unsupported(&'ll DiagnosticInfo),
StackSize,

/// LLVM has other types that we do not wrap here.
#[expect(dead_code)]
UnknownDiagnostic(&'ll DiagnosticInfo),
/// LLVM has other types that we do not distinguish here.
Other(&'ll DiagnosticInfo),
}

impl<'ll> Diagnostic<'ll> {
Expand Down Expand Up @@ -206,14 +198,18 @@ impl<'ll> Diagnostic<'ll> {
Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di))
}

Dk::PGOProfile => PGO(di),
Dk::Linker => Linker(di),
Dk::Unsupported => Unsupported(di),

Dk::SrcMgr => InlineAsm(InlineAsmDiagnostic::unpackSrcMgr(di)),

_ => UnknownDiagnostic(di),
Dk::StackSize => StackSize,

_ => Other(di),
}
}
}
}

impl DiagnosticInfo {
pub(crate) fn severity(&self) -> super::DiagnosticSeverity {
unsafe { super::LLVMGetDiagInfoSeverity(self) }
}
}
9 changes: 4 additions & 5 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,15 @@ pub(crate) enum DiagnosticKind {
SrcMgr,
}

/// LLVMRustDiagnosticLevel
/// LLVMDiagnosticSeverity
#[derive(Copy, Clone)]
#[repr(C)]
#[allow(dead_code)] // Variants constructed by C++.
pub(crate) enum DiagnosticLevel {
pub(crate) enum DiagnosticSeverity {
Error,
Warning,
Note,
Remark,
Note,
}

unsafe extern "C" {
Expand Down Expand Up @@ -2502,13 +2502,13 @@ unsafe extern "C" {

pub(crate) fn LLVMRustUnpackInlineAsmDiagnostic<'a>(
DI: &'a DiagnosticInfo,
level_out: &mut DiagnosticLevel,
cookie_out: &mut u64,
message_out: &mut Option<&'a Twine>,
);

pub(crate) fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
pub(crate) fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
pub(crate) fn LLVMGetDiagInfoSeverity(DI: &DiagnosticInfo) -> DiagnosticSeverity;

pub(crate) fn LLVMRustGetSMDiagnostic<'a>(
DI: &'a DiagnosticInfo,
Expand All @@ -2519,7 +2519,6 @@ unsafe extern "C" {
d: &SMDiagnostic,
message_out: &RustString,
buffer_out: &RustString,
level_out: &mut DiagnosticLevel,
loc_out: &mut c_uint,
ranges_out: *mut c_uint,
num_ranges: &mut usize,
Expand Down
43 changes: 4 additions & 39 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,32 +1217,15 @@ enum class LLVMRustDiagnosticLevel {
Remark,
};

extern "C" void LLVMRustUnpackInlineAsmDiagnostic(
LLVMDiagnosticInfoRef DI, LLVMRustDiagnosticLevel *LevelOut,
uint64_t *CookieOut, const Twine **MessageOut) {
extern "C" void LLVMRustUnpackInlineAsmDiagnostic(LLVMDiagnosticInfoRef DI,
uint64_t *CookieOut,
const Twine **MessageOut) {
// Undefined to call this not on an inline assembly diagnostic!
llvm::DiagnosticInfoInlineAsm *IA =
static_cast<llvm::DiagnosticInfoInlineAsm *>(unwrap(DI));

*CookieOut = IA->getLocCookie();
*MessageOut = &IA->getMsgStr();

switch (IA->getSeverity()) {
case DS_Error:
*LevelOut = LLVMRustDiagnosticLevel::Error;
break;
case DS_Warning:
*LevelOut = LLVMRustDiagnosticLevel::Warning;
break;
case DS_Note:
*LevelOut = LLVMRustDiagnosticLevel::Note;
break;
case DS_Remark:
*LevelOut = LLVMRustDiagnosticLevel::Remark;
break;
default:
report_fatal_error("Invalid LLVMRustDiagnosticLevel value!");
}
}

extern "C" void LLVMRustWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef DI,
Expand Down Expand Up @@ -1324,30 +1307,12 @@ extern "C" const SMDiagnostic *LLVMRustGetSMDiagnostic(LLVMDiagnosticInfoRef DI,

extern "C" bool
LLVMRustUnpackSMDiagnostic(const SMDiagnostic *DRef, RustStringRef MessageOut,
RustStringRef BufferOut,
LLVMRustDiagnosticLevel *LevelOut, unsigned *LocOut,
RustStringRef BufferOut, unsigned *LocOut,
unsigned *RangesOut, size_t *NumRanges) {
const SMDiagnostic &D = *DRef;
auto MessageOS = RawRustStringOstream(MessageOut);
MessageOS << D.getMessage();

switch (D.getKind()) {
case SourceMgr::DK_Error:
*LevelOut = LLVMRustDiagnosticLevel::Error;
break;
case SourceMgr::DK_Warning:
*LevelOut = LLVMRustDiagnosticLevel::Warning;
break;
case SourceMgr::DK_Note:
*LevelOut = LLVMRustDiagnosticLevel::Note;
break;
case SourceMgr::DK_Remark:
*LevelOut = LLVMRustDiagnosticLevel::Remark;
break;
default:
report_fatal_error("Invalid LLVMRustDiagnosticLevel value!");
}

if (D.getLoc() == SMLoc())
return false;

Expand Down
1 change: 1 addition & 0 deletions tests/ui/codegen/huge-stacks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ revisions: unoptimized optimized
//@[optimized]compile-flags: -O
//@[unoptimized]compile-flags: -C opt-level=0
//@ run-pass
//@ only-64bit

Expand Down
3 changes: 1 addition & 2 deletions tests/ui/lto/lto-duplicate-symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ extern crate lto_duplicate_symbols2;

fn main() {}

//~? WARN Linking globals named 'foo': symbol multiply defined
//~? ERROR failed to load bitcode of module "lto-duplicate-symbols2.lto_duplicate_symbols2
//~? ERROR Linking globals named 'foo': symbol multiply defined
6 changes: 2 additions & 4 deletions tests/ui/lto/lto-duplicate-symbols.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
warning: Linking globals named 'foo': symbol multiply defined!
error: Linking globals named 'foo': symbol multiply defined!

error: failed to load bitcode of module "lto-duplicate-symbols2.lto_duplicate_symbols2.HASH-cgu.0.rcgu.o":

error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error

20 changes: 20 additions & 0 deletions tests/ui/target-feature/too-many-reserved-regs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ build-fail
//@ add-minicore
//@ ignore-backends: gcc
//@ needs-llvm-components: riscv
//@ compile-flags: --target=riscv64gc-unknown-linux-gnu -Copt-level=3 -Cdebuginfo=line-tables-only -Zllvm-target-feature=+reserve-x1,+reserve-x3,+reserve-x4,+reserve-x5,+reserve-x6,+reserve-x7,+reserve-x8,+reserve-x9,+reserve-x11,+reserve-x12,+reserve-x13,+reserve-x14,+reserve-x15,+reserve-x16,+reserve-x17,+reserve-x18,+reserve-x19,+reserve-x20,+reserve-x21,+reserve-x22,+reserve-x23,+reserve-x24,+reserve-x25,+reserve-x26,+reserve-x27,+reserve-x28,+reserve-x29,+reserve-x30,+reserve-x31
//@ normalize-stderr: "error: .*/too-many-reserved-regs.rs" -> "error: too-many-reserved-regs.rs"

#![feature(no_core)]
#![no_core]
#![crate_type = "lib"]

extern crate minicore;
use minicore::*;

#[unsafe(no_mangle)]
pub unsafe fn store_val(dst: *mut u32) {
*dst = 42;
}

//~? ERROR ran out of registers during register allocation in function 'store_val'
4 changes: 4 additions & 0 deletions tests/ui/target-feature/too-many-reserved-regs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: too-many-reserved-regs.rs:17:5: ran out of registers during register allocation in function 'store_val'

error: aborting due to 1 previous error

Loading