Skip to content

Commit

Permalink
[LLVM] Introduce a stable representation of DIFlags
Browse files Browse the repository at this point in the history
In LLVM 4.0, this enum becomes an actual type-safe enum, which breaks
all of the interfaces. Introduce our own copy of the bitflags that we
can then safely convert to the LLVM one.
  • Loading branch information
shepmaster committed Dec 3, 2016
1 parent c80c31a commit dbdd60e
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/librustc_llvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/librustc_llvm/Cargo.toml
Expand Up @@ -12,6 +12,9 @@ crate-type = ["dylib"]
[features]
static-libstdcpp = []

[dependencies]
rustc_bitflags = { path = "../librustc_bitflags" }

[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.27"
54 changes: 29 additions & 25 deletions src/librustc_llvm/ffi.rs
Expand Up @@ -11,7 +11,7 @@
use debuginfo::{DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
DINameSpace};
DINameSpace, DIFlags};

use libc::{c_uint, c_int, size_t, c_char};
use libc::{c_longlong, c_ulonglong, c_void};
Expand Down Expand Up @@ -408,7 +408,6 @@ pub enum Visibility {
}

pub mod debuginfo {
pub use self::DIDescriptorFlags::*;
use super::MetadataRef;

#[allow(missing_copy_implementations)]
Expand All @@ -433,24 +432,29 @@ pub mod debuginfo {
pub type DIEnumerator = DIDescriptor;
pub type DITemplateTypeParameter = DIDescriptor;

#[derive(Copy, Clone)]
pub enum DIDescriptorFlags {
FlagPrivate = 1 << 0,
FlagProtected = 1 << 1,
FlagFwdDecl = 1 << 2,
FlagAppleBlock = 1 << 3,
FlagBlockByrefStruct = 1 << 4,
FlagVirtual = 1 << 5,
FlagArtificial = 1 << 6,
FlagExplicit = 1 << 7,
FlagPrototyped = 1 << 8,
FlagObjcClassComplete = 1 << 9,
FlagObjectPointer = 1 << 10,
FlagVector = 1 << 11,
FlagStaticMember = 1 << 12,
FlagIndirectVariable = 1 << 13,
FlagLValueReference = 1 << 14,
FlagRValueReference = 1 << 15,
// These values **must** match with LLVMRustDIFlags!!
bitflags! {
#[repr(C)]
#[derive(Debug, Default)]
flags DIFlags: ::libc::uint32_t {
const FlagZero = 0,
const FlagPrivate = 1,
const FlagProtected = 2,
const FlagPublic = 3,
const FlagFwdDecl = (1 << 2),
const FlagAppleBlock = (1 << 3),
const FlagBlockByrefStruct = (1 << 4),
const FlagVirtual = (1 << 5),
const FlagArtificial = (1 << 6),
const FlagExplicit = (1 << 7),
const FlagPrototyped = (1 << 8),
const FlagObjcClassComplete = (1 << 9),
const FlagObjectPointer = (1 << 10),
const FlagVector = (1 << 11),
const FlagStaticMember = (1 << 12),
const FlagLValueReference = (1 << 13),
const FlagRValueReference = (1 << 14),
}
}
}

Expand Down Expand Up @@ -1567,7 +1571,7 @@ extern "C" {
isLocalToUnit: bool,
isDefinition: bool,
ScopeLine: c_uint,
Flags: c_uint,
Flags: DIFlags,
isOptimized: bool,
Fn: ValueRef,
TParam: DIArray,
Expand Down Expand Up @@ -1595,7 +1599,7 @@ extern "C" {
LineNumber: c_uint,
SizeInBits: u64,
AlignInBits: u64,
Flags: c_uint,
Flags: DIFlags,
DerivedFrom: DIType,
Elements: DIArray,
RunTimeLang: c_uint,
Expand All @@ -1611,7 +1615,7 @@ extern "C" {
SizeInBits: u64,
AlignInBits: u64,
OffsetInBits: u64,
Flags: c_uint,
Flags: DIFlags,
Ty: DIType)
-> DIDerivedType;

Expand Down Expand Up @@ -1647,7 +1651,7 @@ extern "C" {
LineNo: c_uint,
Ty: DIType,
AlwaysPreserve: bool,
Flags: c_uint,
Flags: DIFlags,
ArgNo: c_uint)
-> DIVariable;

Expand Down Expand Up @@ -1707,7 +1711,7 @@ extern "C" {
LineNumber: c_uint,
SizeInBits: u64,
AlignInBits: u64,
Flags: c_uint,
Flags: DIFlags,
Elements: DIArray,
RunTimeLang: c_uint,
UniqueId: *const c_char)
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_llvm/lib.rs
Expand Up @@ -29,8 +29,12 @@
#![feature(link_args)]
#![feature(linked_from)]
#![feature(staged_api)]
#![cfg_attr(not(stage0), feature(rustc_private))]

extern crate libc;
#[macro_use]
#[no_link]
extern crate rustc_bitflags;

pub use self::IntPredicate::*;
pub use self::RealPredicate::*;
Expand Down
35 changes: 17 additions & 18 deletions src/librustc_trans/debuginfo/metadata.rs
Expand Up @@ -22,7 +22,8 @@ use context::SharedCrateContext;
use session::Session;

use llvm::{self, ValueRef};
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType, DILexicalBlock};
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor,
DICompositeType, DILexicalBlock, DIFlags};

use rustc::hir::def::CtorKind;
use rustc::hir::def_id::DefId;
Expand Down Expand Up @@ -69,8 +70,6 @@ pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
// ptr::null() doesn't work :(
pub const NO_SCOPE_METADATA: DIScope = (0 as DIScope);

const FLAGS_NONE: c_uint = 0;

#[derive(Copy, Debug, Hash, Eq, PartialEq, Clone)]
pub struct UniqueTypeId(ast::Name);

Expand Down Expand Up @@ -347,14 +346,14 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
llvm_type: member_llvm_types[0],
type_metadata: element_type_metadata,
offset: ComputedMemberOffset,
flags: FLAGS_NONE
flags: DIFlags::FlagZero,
},
MemberDescription {
name: "length".to_string(),
llvm_type: member_llvm_types[1],
type_metadata: type_metadata(cx, cx.tcx().types.usize, span),
offset: ComputedMemberOffset,
flags: FLAGS_NONE
flags: DIFlags::FlagZero,
},
];

Expand Down Expand Up @@ -838,7 +837,7 @@ struct MemberDescription {
llvm_type: Type,
type_metadata: DIType,
offset: MemberOffset,
flags: c_uint
flags: DIFlags,
}

// A factory for MemberDescriptions. It produces a list of member descriptions
Expand Down Expand Up @@ -922,7 +921,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
llvm_type: type_of::type_of(cx, fty),
type_metadata: type_metadata(cx, fty, self.span),
offset: offset,
flags: FLAGS_NONE,
flags: DIFlags::FlagZero,
}
}).collect()
}
Expand Down Expand Up @@ -987,7 +986,7 @@ impl<'tcx> TupleMemberDescriptionFactory<'tcx> {
llvm_type: type_of::type_of(cx, component_type),
type_metadata: type_metadata(cx, component_type, self.span),
offset: ComputedMemberOffset,
flags: FLAGS_NONE,
flags: DIFlags::FlagZero,
}
}).collect()
}
Expand Down Expand Up @@ -1039,7 +1038,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> {
llvm_type: type_of::type_of(cx, fty),
type_metadata: type_metadata(cx, fty, self.span),
offset: FixedMemberOffset { bytes: 0 },
flags: FLAGS_NONE,
flags: DIFlags::FlagZero,
}
}).collect()
}
Expand Down Expand Up @@ -1137,7 +1136,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
llvm_type: variant_llvm_type,
type_metadata: variant_type_metadata,
offset: FixedMemberOffset { bytes: 0 },
flags: FLAGS_NONE
flags: DIFlags::FlagZero
}
}).collect()
},
Expand Down Expand Up @@ -1171,7 +1170,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
llvm_type: variant_llvm_type,
type_metadata: variant_type_metadata,
offset: FixedMemberOffset { bytes: 0 },
flags: FLAGS_NONE
flags: DIFlags::FlagZero
}
]
}
Expand Down Expand Up @@ -1208,7 +1207,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
llvm_type: non_null_llvm_type,
type_metadata: non_null_type_metadata,
offset: FixedMemberOffset { bytes: 0 },
flags: FLAGS_NONE
flags: DIFlags::FlagZero
};

let unique_type_id = debug_context(cx).type_map
Expand Down Expand Up @@ -1245,7 +1244,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
llvm_type: artificial_struct_llvm_type,
type_metadata: artificial_struct_metadata,
offset: FixedMemberOffset { bytes: 0 },
flags: FLAGS_NONE
flags: DIFlags::FlagZero
}
]
},
Expand Down Expand Up @@ -1289,7 +1288,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
llvm_type: variant_llvm_type,
type_metadata: variant_type_metadata,
offset: FixedMemberOffset { bytes: 0 },
flags: FLAGS_NONE
flags: DIFlags::FlagZero
}
]
},
Expand Down Expand Up @@ -1318,7 +1317,7 @@ impl<'tcx> VariantMemberDescriptionFactory<'tcx> {
_ => type_metadata(cx, ty, self.span)
},
offset: ComputedMemberOffset,
flags: FLAGS_NONE
flags: DIFlags::FlagZero
}
}).collect()
}
Expand Down Expand Up @@ -1535,7 +1534,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
UNKNOWN_LINE_NUMBER,
bytes_to_bits(enum_type_size),
bytes_to_bits(enum_type_align),
0, // Flags
DIFlags::FlagZero,
ptr::null_mut(),
0, // RuntimeLang
unique_type_id_str.as_ptr())
Expand Down Expand Up @@ -1680,7 +1679,7 @@ fn create_struct_stub(cx: &CrateContext,
UNKNOWN_LINE_NUMBER,
bytes_to_bits(struct_size),
bytes_to_bits(struct_align),
0,
DIFlags::FlagZero,
ptr::null_mut(),
empty_array,
0,
Expand Down Expand Up @@ -1717,7 +1716,7 @@ fn create_union_stub(cx: &CrateContext,
UNKNOWN_LINE_NUMBER,
bytes_to_bits(union_size),
bytes_to_bits(union_align),
0, // Flags
DIFlags::FlagZero,
empty_array,
0, // RuntimeLang
unique_type_id.as_ptr())
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_trans/debuginfo/mod.rs
Expand Up @@ -22,8 +22,7 @@ use self::source_loc::InternalDebugLocation::{self, UnknownLocation};

use llvm;
use llvm::{ModuleRef, ContextRef, ValueRef};
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray,
FlagPrototyped};
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags};
use rustc::hir::def_id::DefId;
use rustc::ty::subst::Substs;

Expand Down Expand Up @@ -286,7 +285,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
is_local_to_unit,
true,
scope_line as c_uint,
FlagPrototyped as c_uint,
DIFlags::FlagPrototyped,
cx.sess().opts.optimize != config::OptLevel::No,
llfn,
template_parameters,
Expand Down Expand Up @@ -478,7 +477,7 @@ pub fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
loc.line as c_uint,
type_metadata,
cx.sess().opts.optimize != config::OptLevel::No,
0,
DIFlags::FlagZero,
argument_index)
};
source_loc::set_debug_location(cx, None,
Expand Down

0 comments on commit dbdd60e

Please sign in to comment.