Skip to content

Commit de42424

Browse files
committed
rustc_trans: do not emit !range/!nonnull for LLVM older than 3.9, to work around rust-lang#36023.
1 parent 5d47c91 commit de42424

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/librustc_trans/builder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
544544

545545

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

561564
pub fn nonnull_metadata(&self, load: ValueRef) {
565+
if !self.ccx.use_range_or_nonnull_metadata() {
566+
return;
567+
}
562568
unsafe {
563569
llvm::LLVMSetMetadata(load, llvm::MD_nonnull as c_uint,
564570
llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0));

src/librustc_trans/context.rs

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
5353
tcx: TyCtxt<'a, 'tcx, 'tcx>,
5454
check_overflow: bool,
5555
use_dll_storage_attrs: bool,
56+
57+
// HACK(eddyb) remove this after we make the required LLVM version 3.9
58+
// or later. See issue #36023 and PR #45225 for more details on the bug.
59+
use_range_or_nonnull_metadata: bool,
5660
}
5761

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

285289
let check_overflow = tcx.sess.overflow_checks();
286290

291+
// See the comment on the `use_range_or_nonnull_metadata` field.
292+
let use_range_or_nonnull_metadata = unsafe {
293+
(llvm::LLVMRustVersionMajor(), llvm::LLVMRustVersionMinor()) >= (3, 9)
294+
};
295+
287296
SharedCrateContext {
288297
tcx,
289298
check_overflow,
290299
use_dll_storage_attrs,
300+
use_range_or_nonnull_metadata,
291301
}
292302
}
293303

@@ -524,6 +534,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
524534
self.shared.use_dll_storage_attrs()
525535
}
526536

537+
pub fn use_range_or_nonnull_metadata(&self) -> bool {
538+
self.shared.use_range_or_nonnull_metadata
539+
}
540+
527541
/// Generate a new symbol name with the given prefix. This symbol name must
528542
/// only be used for definitions with `internal` or `private` linkage.
529543
pub fn generate_local_symbol_name(&self, prefix: &str) -> String {

src/test/codegen/loads.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
// compile-flags: -C no-prepopulate-passes
12+
// min-llvm-version 3.9
1213

1314
#![crate_type = "lib"]
1415

src/test/run-pass/issue-36023.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// min-llvm-version 3.9
12-
1311
use std::ops::Deref;
1412

1513
fn main() {

0 commit comments

Comments
 (0)