Skip to content

Commit 9414870

Browse files
ghaithTheDan64
authored andcommitted
Add Support for LLVM 11. Fixes rust-lang#217
Added support for an llvm 11 feature Fixed the Debug builder API to support the new arguments
1 parent 3eab4db commit 9414870

File tree

8 files changed

+187
-5
lines changed

8 files changed

+187
-5
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ llvm7-0 = ["llvm-sys-70"]
2525
llvm8-0 = ["llvm-sys-80"]
2626
llvm9-0 = ["llvm-sys-90"]
2727
llvm10-0 = ["llvm-sys-100"]
28+
llvm11-0 = ["llvm-sys-110"]
2829
# Don't link aganist LLVM libraries. This is useful if another dependency is
2930
# installing LLVM. See llvm-sys for more details. We can't enable a single
3031
# `no-llvm-linking` feature across the board of llvm versions, as it'll cause
@@ -41,6 +42,7 @@ llvm7-0-no-llvm-linking = ["llvm7-0", "llvm-sys-70/no-llvm-linking"]
4142
llvm8-0-no-llvm-linking = ["llvm8-0", "llvm-sys-80/no-llvm-linking"]
4243
llvm9-0-no-llvm-linking = ["llvm9-0", "llvm-sys-90/no-llvm-linking"]
4344
llvm10-0-no-llvm-linking = ["llvm10-0", "llvm-sys-100/no-llvm-linking"]
45+
llvm11-0-no-llvm-linking = ["llvm11-0", "llvm-sys-110/no-llvm-linking"]
4446
# Don't force linking to libffi on non-windows platforms. Without this feature
4547
# inkwell always links to libffi on non-windows platforms.
4648
no-libffi-linking = []
@@ -96,6 +98,7 @@ llvm-sys-70 = { package = "llvm-sys", version = "70.4", optional = true }
9698
llvm-sys-80 = { package = "llvm-sys", version = "80.3", optional = true }
9799
llvm-sys-90 = { package = "llvm-sys", version = "90.2", optional = true }
98100
llvm-sys-100 = { package = "llvm-sys", version = "100.2", optional = true }
101+
llvm-sys-110 = { package = "llvm-sys", version = "110.0", optional = true }
99102
once_cell = "1.4.1"
100103
parking_lot = "0.11"
101104
regex = "1"

internal_macros/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use syn::spanned::Spanned;
1919
use syn::{Token, LitFloat, Ident, Item, Field, Variant, Attribute};
2020

2121
// This array should match the LLVM features in the top level Cargo manifest
22-
const FEATURE_VERSIONS: [&str; 11] =
23-
["llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0"];
22+
const FEATURE_VERSIONS: [&str; 12] =
23+
["llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0"];
2424

2525
/// Gets the index of the feature version that represents `latest`
2626
fn get_latest_feature_index(features: &[&str]) -> usize {

src/debug_info.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub trait AsDIScope<'ctx> {
162162
}
163163

164164
impl<'ctx> DebugInfoBuilder<'ctx> {
165+
#[llvm_versions(3.6..=10.0)]
165166
pub(crate) fn new(
166167
module: &Module,
167168
allow_unresolved: bool,
@@ -210,6 +211,59 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
210211
(builder, cu)
211212
}
212213

214+
#[llvm_versions(11.0)]
215+
pub(crate) fn new(
216+
module: &Module,
217+
allow_unresolved: bool,
218+
language: DWARFSourceLanguage,
219+
filename: &str,
220+
directory: &str,
221+
producer: &str,
222+
is_optimized: bool,
223+
flags: &str,
224+
runtime_ver: libc::c_uint,
225+
split_name: &str,
226+
kind: DWARFEmissionKind,
227+
dwo_id: libc::c_uint,
228+
split_debug_inlining: bool,
229+
debug_info_for_profiling: bool,
230+
sysroot: &str,
231+
sdk: &str,
232+
) -> (Self, DICompileUnit<'ctx>) {
233+
let builder = unsafe {
234+
if allow_unresolved {
235+
LLVMCreateDIBuilder(module.module.get())
236+
} else {
237+
LLVMCreateDIBuilderDisallowUnresolved(module.module.get())
238+
}
239+
};
240+
241+
let builder = DebugInfoBuilder {
242+
builder,
243+
_marker: PhantomData,
244+
};
245+
246+
let file = builder.create_file(filename, directory);
247+
248+
let cu = builder.create_compile_unit(
249+
language,
250+
file,
251+
producer,
252+
is_optimized,
253+
flags,
254+
runtime_ver,
255+
split_name,
256+
kind,
257+
dwo_id,
258+
split_debug_inlining,
259+
debug_info_for_profiling,
260+
sysroot,
261+
sdk
262+
);
263+
264+
(builder, cu)
265+
}
266+
213267
/// A DICompileUnit provides an anchor for all debugging information generated during this instance of compilation.
214268
///
215269
/// * `language` - Source programming language
@@ -223,6 +277,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
223277
/// * `dwo_id` - The DWOId if this is a split skeleton compile unit.
224278
/// * `split_debug_inlining` - Whether to emit inline debug info.
225279
/// * `debug_info_for_profiling` - Whether to emit extra debug info for profile collection.
280+
#[llvm_versions(3.6..=10.0)]
226281
fn create_compile_unit(
227282
&self,
228283
language: DWARFSourceLanguage,
@@ -264,6 +319,70 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
264319
}
265320
}
266321

322+
/// A DICompileUnit provides an anchor for all debugging information generated during this instance of compilation.
323+
///
324+
/// * `language` - Source programming language
325+
/// * `file` - File info
326+
/// * `producer` - Identify the producer of debugging information and code. Usually this is a compiler version string.
327+
/// * `is_optimized` - A boolean flag which indicates whether optimization is enabled or not.
328+
/// * `flags` - This string lists command line options. This string is directly embedded in debug info output which may be used by a tool analyzing generated debugging information.
329+
/// * `runtime_ver` - This indicates runtime version for languages like Objective-C.
330+
/// * `split_name` - The name of the file that we'll split debug info out into.
331+
/// * `kind` - The kind of debug information to generate.
332+
/// * `dwo_id` - The DWOId if this is a split skeleton compile unit.
333+
/// * `split_debug_inlining` - Whether to emit inline debug info.
334+
/// * `debug_info_for_profiling` - Whether to emit extra debug info for profile collection.
335+
/// * `sysroot` The clang system root (value of -isysroot).
336+
/// * `sdk` The SDK name. On Darwin, this is the last component of the sysroot.
337+
#[llvm_versions(11.0)]
338+
fn create_compile_unit(
339+
&self,
340+
language: DWARFSourceLanguage,
341+
file: DIFile<'ctx>,
342+
producer: &str,
343+
is_optimized: bool,
344+
flags: &str,
345+
runtime_ver: libc::c_uint,
346+
split_name: &str,
347+
kind: DWARFEmissionKind,
348+
dwo_id: libc::c_uint,
349+
split_debug_inlining: bool,
350+
debug_info_for_profiling: bool,
351+
sysroot: &str,
352+
sdk: &str,
353+
) -> DICompileUnit<'ctx> {
354+
355+
let metadata_ref = unsafe {
356+
LLVMDIBuilderCreateCompileUnit(
357+
self.builder,
358+
language.into(),
359+
file.metadata_ref,
360+
producer.as_ptr() as _,
361+
producer.len(),
362+
is_optimized as _,
363+
flags.as_ptr() as _,
364+
flags.len(),
365+
runtime_ver,
366+
split_name.as_ptr() as _,
367+
split_name.len(),
368+
kind.into(),
369+
dwo_id,
370+
split_debug_inlining as _,
371+
debug_info_for_profiling as _,
372+
sysroot.as_ptr() as _,
373+
sysroot.len(),
374+
sdk.as_ptr() as _,
375+
sdk.len(),
376+
)
377+
};
378+
379+
DICompileUnit {
380+
file,
381+
metadata_ref,
382+
_marker: PhantomData,
383+
}
384+
}
385+
267386
/// A DIFunction provides an anchor for all debugging information generated for the specified subprogram.
268387
///
269388
/// * `scope` - Function scope.

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ extern crate llvm_sys_80 as llvm_sys;
6363
extern crate llvm_sys_90 as llvm_sys;
6464
#[cfg(feature="llvm10-0")]
6565
extern crate llvm_sys_100 as llvm_sys;
66+
#[cfg(feature="llvm11-0")]
67+
extern crate llvm_sys_110 as llvm_sys;
6668

6769
use llvm_sys::{LLVMIntPredicate, LLVMRealPredicate, LLVMVisibility, LLVMThreadLocalMode, LLVMDLLStorageClass, LLVMAtomicOrdering, LLVMAtomicRMWBinOp};
6870

@@ -100,7 +102,7 @@ macro_rules! assert_unique_used_features {
100102
}
101103
}
102104

103-
assert_unique_used_features!{"llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0"}
105+
assert_unique_used_features!{"llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0"}
104106

105107
/// Defines the address space in which a global will be inserted.
106108
///

src/module.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ impl<'ctx> Module<'ctx> {
13541354
}
13551355

13561356
/// Creates a `DebugInfoBuilder` for this `Module`.
1357-
#[llvm_versions(7.0..=latest)]
1357+
#[llvm_versions(7.0..=10.0)]
13581358
pub fn create_debug_info_builder(&self,
13591359
allow_unresolved: bool,
13601360
language: DWARFSourceLanguage,
@@ -1374,6 +1374,32 @@ impl<'ctx> Module<'ctx> {
13741374
language, filename, directory, producer, is_optimized, flags, runtime_ver, split_name, kind, dwo_id, split_debug_inlining, debug_info_for_profiling
13751375
)
13761376
}
1377+
1378+
/// Creates a `DebugInfoBuilder` for this `Module`.
1379+
#[llvm_versions(11.0)]
1380+
pub fn create_debug_info_builder(&self,
1381+
allow_unresolved: bool,
1382+
language: DWARFSourceLanguage,
1383+
filename: &str,
1384+
directory: &str,
1385+
producer: &str,
1386+
is_optimized: bool,
1387+
flags: &str,
1388+
runtime_ver: libc::c_uint,
1389+
split_name: &str,
1390+
kind: DWARFEmissionKind,
1391+
dwo_id: libc::c_uint,
1392+
split_debug_inlining: bool,
1393+
debug_info_for_profiling: bool,
1394+
sysroot: &str,
1395+
sdk: &str,
1396+
) -> (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>) {
1397+
DebugInfoBuilder::new(self, allow_unresolved,
1398+
language, filename, directory, producer, is_optimized, flags,
1399+
runtime_ver, split_name, kind, dwo_id, split_debug_inlining,
1400+
debug_info_for_profiling, sysroot, sdk
1401+
)
1402+
}
13771403
}
13781404

13791405
impl Clone for Module<'_> {

src/types/enums.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,17 @@ impl<'ctx> AnyTypeEnum<'ctx> {
103103
LLVMTypeKind::LLVMX86_FP80TypeKind |
104104
LLVMTypeKind::LLVMFP128TypeKind |
105105
LLVMTypeKind::LLVMPPC_FP128TypeKind => AnyTypeEnum::FloatType(FloatType::new(type_)),
106+
#[cfg(feature = "llvm11-0")]
107+
LLVMTypeKind::LLVMBFloatTypeKind => AnyTypeEnum::FloatType(FloatType::new(type_)),
106108
LLVMTypeKind::LLVMLabelTypeKind => panic!("FIXME: Unsupported type: Label"),
107109
LLVMTypeKind::LLVMIntegerTypeKind => AnyTypeEnum::IntType(IntType::new(type_)),
108110
LLVMTypeKind::LLVMFunctionTypeKind => AnyTypeEnum::FunctionType(FunctionType::new(type_)),
109111
LLVMTypeKind::LLVMStructTypeKind => AnyTypeEnum::StructType(StructType::new(type_)),
110112
LLVMTypeKind::LLVMArrayTypeKind => AnyTypeEnum::ArrayType(ArrayType::new(type_)),
111113
LLVMTypeKind::LLVMPointerTypeKind => AnyTypeEnum::PointerType(PointerType::new(type_)),
112114
LLVMTypeKind::LLVMVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)),
115+
#[cfg(feature = "llvm11-0")]
116+
LLVMTypeKind::LLVMScalableVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)),
113117
LLVMTypeKind::LLVMMetadataTypeKind => panic!("FIXME: Unsupported type: Metadata"),
114118
LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("FIXME: Unsupported type: MMX"),
115119
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
@@ -277,11 +281,15 @@ impl<'ctx> BasicTypeEnum<'ctx> {
277281
LLVMTypeKind::LLVMX86_FP80TypeKind |
278282
LLVMTypeKind::LLVMFP128TypeKind |
279283
LLVMTypeKind::LLVMPPC_FP128TypeKind => BasicTypeEnum::FloatType(FloatType::new(type_)),
284+
#[cfg(feature= "llvm11-0")]
285+
LLVMTypeKind::LLVMBFloatTypeKind => BasicTypeEnum::FloatType(FloatType::new(type_)),
280286
LLVMTypeKind::LLVMIntegerTypeKind => BasicTypeEnum::IntType(IntType::new(type_)),
281287
LLVMTypeKind::LLVMStructTypeKind => BasicTypeEnum::StructType(StructType::new(type_)),
282288
LLVMTypeKind::LLVMPointerTypeKind => BasicTypeEnum::PointerType(PointerType::new(type_)),
283289
LLVMTypeKind::LLVMArrayTypeKind => BasicTypeEnum::ArrayType(ArrayType::new(type_)),
284290
LLVMTypeKind::LLVMVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)),
291+
#[cfg(feature= "llvm11-0")]
292+
LLVMTypeKind::LLVMScalableVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)),
285293
LLVMTypeKind::LLVMMetadataTypeKind => unreachable!("Unsupported basic type: Metadata"),
286294
LLVMTypeKind::LLVMX86_MMXTypeKind => unreachable!("Unsupported basic type: MMX"),
287295
LLVMTypeKind::LLVMLabelTypeKind => unreachable!("Unsupported basic type: Label"),

src/values/metadata_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 25;
3434
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 26;
3535
#[cfg(feature = "llvm9-0")]
3636
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 28;
37-
#[cfg(feature = "llvm10-0")]
37+
#[cfg(any(feature = "llvm10-0", feature = "llvm11-0"))]
3838
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 30;
3939

4040
#[derive(PartialEq, Eq, Clone, Copy, Hash)]

tests/all/test_debug_info.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ fn test_smoke() {
3232
0,
3333
false,
3434
false,
35+
#[cfg(feature = "llvm11-0")]
36+
"",
37+
#[cfg(feature = "llvm11-0")]
38+
"",
3539
);
3640

3741
let ditype = dibuilder
@@ -106,6 +110,10 @@ fn test_struct_with_placeholders() {
106110
0,
107111
false,
108112
false,
113+
#[cfg(feature = "llvm11-0")]
114+
"",
115+
#[cfg(feature = "llvm11-0")]
116+
"",
109117
);
110118

111119
// Some byte aligned integer types.
@@ -219,6 +227,10 @@ fn test_no_explicit_finalize() {
219227
0,
220228
false,
221229
false,
230+
#[cfg(feature = "llvm11-0")]
231+
"",
232+
#[cfg(feature = "llvm11-0")]
233+
"",
222234
);
223235

224236
drop(dibuilder);
@@ -246,6 +258,10 @@ fn test_replacing_placeholder_with_placeholder() {
246258
0,
247259
false,
248260
false,
261+
#[cfg(feature = "llvm11-0")]
262+
"",
263+
#[cfg(feature = "llvm11-0")]
264+
"",
249265
);
250266

251267
let i32ty = dibuilder
@@ -289,6 +305,10 @@ fn test_anonymous_basic_type() {
289305
0,
290306
false,
291307
false,
308+
#[cfg(feature = "llvm11-0")]
309+
"",
310+
#[cfg(feature = "llvm11-0")]
311+
"",
292312
);
293313

294314
assert_eq!(
@@ -323,6 +343,10 @@ fn test_global_expressions() {
323343
0,
324344
false,
325345
false,
346+
#[cfg(feature = "llvm11-0")]
347+
"",
348+
#[cfg(feature = "llvm11-0")]
349+
"",
326350
);
327351

328352
let di_type = dibuilder.create_basic_type("type_name", 0_u64, 0x00, DIFlags::ZERO);

0 commit comments

Comments
 (0)