Skip to content

Commit d225bd2

Browse files
committed
rustc_codegen_llvm: avoid converting between DILocation and Value.
1 parent 23388cc commit d225bd2

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
195195
let dbg_loc = self.cx().create_debug_loc(scope, span);
196196

197197
unsafe {
198-
llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc);
198+
let dbg_loc_as_llval = llvm::LLVMRustMetadataAsValue(self.cx().llcx, dbg_loc);
199+
llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc_as_llval);
199200
}
200201
}
201202
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {

src/librustc_codegen_llvm/debuginfo/source_loc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER};
22
use super::utils::debug_context;
33

44
use crate::common::CodegenCx;
5-
use crate::llvm::debuginfo::DIScope;
6-
use crate::llvm::{self, Value};
5+
use crate::llvm;
6+
use crate::llvm::debuginfo::{DILocation, DIScope};
77
use rustc_codegen_ssa::traits::*;
88

99
use rustc_data_structures::sync::Lrc;
@@ -45,7 +45,7 @@ impl CodegenCx<'ll, '_> {
4545
}
4646
}
4747

48-
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
48+
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll DILocation {
4949
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
5050

5151
unsafe {

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
use super::debuginfo::{
55
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
6-
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DINameSpace, DISPFlags, DIScope,
7-
DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind,
6+
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
7+
DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable,
8+
DebugEmissionKind,
89
};
910

1011
use libc::{c_char, c_int, c_uint, size_t};
@@ -624,6 +625,7 @@ pub mod debuginfo {
624625
pub struct DIBuilder<'a>(InvariantOpaque<'a>);
625626

626627
pub type DIDescriptor = Metadata;
628+
pub type DILocation = Metadata;
627629
pub type DIScope = DIDescriptor;
628630
pub type DIFile = DIScope;
629631
pub type DILexicalBlock = DIScope;
@@ -1795,7 +1797,7 @@ extern "C" {
17951797
VarInfo: &'a DIVariable,
17961798
AddrOps: *const i64,
17971799
AddrOpsCount: c_uint,
1798-
DL: &'a Value,
1800+
DL: &'a DILocation,
17991801
InsertAtEnd: &'a BasicBlock,
18001802
) -> &'a Value;
18011803

@@ -1886,8 +1888,8 @@ extern "C" {
18861888
Line: c_uint,
18871889
Column: c_uint,
18881890
Scope: &'a DIScope,
1889-
InlinedAt: Option<&'a Metadata>,
1890-
) -> &'a Value;
1891+
InlinedAt: Option<&'a DILocation>,
1892+
) -> &'a DILocation;
18911893
pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
18921894
pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
18931895

src/rustllvm/RustWrapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,12 @@ LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder,
914914

915915
extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
916916
LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
917-
int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL,
917+
int64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
918918
LLVMBasicBlockRef InsertAtEnd) {
919919
return wrap(Builder->insertDeclare(
920920
unwrap(V), unwrap<DILocalVariable>(VarInfo),
921921
Builder->createExpression(llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)),
922-
DebugLoc(cast<MDNode>(unwrap<MetadataAsValue>(DL)->getMetadata())),
922+
DebugLoc(cast<MDNode>(DL)),
923923
unwrap(InsertAtEnd)));
924924
}
925925

@@ -982,7 +982,7 @@ LLVMRustDICompositeTypeReplaceArrays(LLVMRustDIBuilderRef Builder,
982982
DINodeArray(unwrap<MDTuple>(Params)));
983983
}
984984

985-
extern "C" LLVMValueRef
985+
extern "C" LLVMMetadataRef
986986
LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line,
987987
unsigned Column, LLVMMetadataRef Scope,
988988
LLVMMetadataRef InlinedAt) {
@@ -991,7 +991,7 @@ LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line,
991991
DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIPtr<MDNode>(Scope),
992992
unwrapDIPtr<MDNode>(InlinedAt));
993993

994-
return wrap(MetadataAsValue::get(Context, debug_loc.getAsMDNode()));
994+
return wrap(debug_loc.getAsMDNode());
995995
}
996996

997997
extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() {

0 commit comments

Comments
 (0)