Skip to content

Commit

Permalink
rustc_trans: do not emit !range/!nonnull for LLVM older than 3.9, to …
Browse files Browse the repository at this point in the history
…work around #36023.
  • Loading branch information
eddyb committed Oct 14, 2017
1 parent 5d47c91 commit de42424
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/librustc_trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {


pub fn range_metadata(&self, load: ValueRef, range: Range<u128>) {
if !self.ccx.use_range_or_nonnull_metadata() {
return;
}
unsafe {
let llty = val_ty(load);
let v = [
Expand All @@ -559,6 +562,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}

pub fn nonnull_metadata(&self, load: ValueRef) {
if !self.ccx.use_range_or_nonnull_metadata() {
return;
}
unsafe {
llvm::LLVMSetMetadata(load, llvm::MD_nonnull as c_uint,
llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0));
Expand Down
14 changes: 14 additions & 0 deletions src/librustc_trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
check_overflow: bool,
use_dll_storage_attrs: bool,

// HACK(eddyb) remove this after we make the required LLVM version 3.9
// or later. See issue #36023 and PR #45225 for more details on the bug.
use_range_or_nonnull_metadata: bool,
}

/// The local portion of a `CrateContext`. There is one `LocalCrateContext`
Expand Down Expand Up @@ -284,10 +288,16 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {

let check_overflow = tcx.sess.overflow_checks();

// See the comment on the `use_range_or_nonnull_metadata` field.
let use_range_or_nonnull_metadata = unsafe {
(llvm::LLVMRustVersionMajor(), llvm::LLVMRustVersionMinor()) >= (3, 9)
};

SharedCrateContext {
tcx,
check_overflow,
use_dll_storage_attrs,
use_range_or_nonnull_metadata,
}
}

Expand Down Expand Up @@ -524,6 +534,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
self.shared.use_dll_storage_attrs()
}

pub fn use_range_or_nonnull_metadata(&self) -> bool {
self.shared.use_range_or_nonnull_metadata
}

/// Generate a new symbol name with the given prefix. This symbol name must
/// only be used for definitions with `internal` or `private` linkage.
pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/loads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// compile-flags: -C no-prepopulate-passes
// min-llvm-version 3.9

#![crate_type = "lib"]

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/issue-36023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// min-llvm-version 3.9

use std::ops::Deref;

fn main() {
Expand Down

0 comments on commit de42424

Please sign in to comment.