diff --git a/.gitmodules b/.gitmodules index ffa7b321ba6b6..2834dd69ae094 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "src/llvm"] path = src/llvm - url = https://github.com/rust-lang/llvm.git + url = https://github.com/alexcrichton/llvm.git branch = master [submodule "src/rt/hoedown"] path = src/rt/hoedown diff --git a/.travis.yml b/.travis.yml index 6e242b74894c5..498b42e5999c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -109,29 +109,20 @@ matrix: # Linux builders, remaining docker images - env: IMAGE=arm-android - if: branch = auto - env: IMAGE=armhf-gnu - if: branch = auto - env: IMAGE=dist-various-1 DEPLOY=1 - if: branch = auto - env: IMAGE=dist-various-2 DEPLOY=1 if: branch = auto - env: IMAGE=dist-aarch64-linux DEPLOY=1 - if: branch = auto - env: IMAGE=dist-android DEPLOY=1 if: branch = auto - env: IMAGE=dist-arm-linux DEPLOY=1 - if: branch = auto - env: IMAGE=dist-armhf-linux DEPLOY=1 - if: branch = auto - env: IMAGE=dist-armv7-linux DEPLOY=1 if: branch = auto - env: IMAGE=dist-i586-gnu-i586-i686-musl DEPLOY=1 - if: branch = auto - env: IMAGE=dist-i686-freebsd DEPLOY=1 - if: branch = auto - env: IMAGE=dist-i686-linux DEPLOY=1 - if: branch = auto - env: IMAGE=dist-mips-linux DEPLOY=1 if: branch = auto - env: IMAGE=dist-mips64-linux DEPLOY=1 @@ -141,43 +132,30 @@ matrix: - env: IMAGE=dist-mipsel-linux DEPLOY=1 if: branch = auto - env: IMAGE=dist-powerpc-linux DEPLOY=1 - if: branch = auto - env: IMAGE=dist-powerpc64-linux DEPLOY=1 if: branch = auto - env: IMAGE=dist-powerpc64le-linux DEPLOY=1 if: branch = auto - env: IMAGE=dist-s390x-linux DEPLOY=1 - if: branch = auto - env: IMAGE=dist-x86_64-freebsd DEPLOY=1 - if: branch = auto - env: IMAGE=dist-x86_64-musl DEPLOY=1 - if: branch = auto - env: IMAGE=dist-x86_64-netbsd DEPLOY=1 if: branch = auto - env: IMAGE=asmjs if: branch = auto - env: IMAGE=i686-gnu - if: branch = auto - env: IMAGE=i686-gnu-nopt - if: branch = auto - env: IMAGE=wasm32-unknown - if: branch = auto - env: IMAGE=x86_64-gnu - if: branch = auto - env: IMAGE=x86_64-gnu-full-bootstrap if: branch = auto - env: IMAGE=x86_64-gnu-aux - if: branch = auto - env: IMAGE=x86_64-gnu-tools - if: branch = auto - env: IMAGE=x86_64-gnu-debug if: branch = auto - env: IMAGE=x86_64-gnu-nopt - if: branch = auto - env: IMAGE=x86_64-gnu-distcheck - if: branch = auto - env: IMAGE=x86_64-gnu-incremental - if: branch = auto - stage: publish toolstate if: branch = master AND type = push diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 3738828a4baed..2e3d441a80049 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -312,7 +312,7 @@ impl Build { initial_rustc: config.initial_rustc.clone(), initial_cargo: config.initial_cargo.clone(), local_rebuild: config.local_rebuild, - fail_fast: config.cmd.fail_fast(), + fail_fast: config.cmd.fail_fast() && false, verbosity: config.verbose, build: config.build, diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index ba8cf3a8e2eb5..828f3459dcc6d 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -107,7 +107,7 @@ impl Step for Llvm { // NOTE: remember to also update `config.toml.example` when changing the defaults! let llvm_targets = match build.config.llvm_targets { Some(ref s) => s, - None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX;Hexagon", + None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;MSP430;Sparc;NVPTX;Hexagon", }; let llvm_exp_targets = &build.config.llvm_experimental_targets; diff --git a/src/ci/docker/dist-i686-freebsd/Dockerfile b/src/ci/docker/dist-i686-freebsd/Dockerfile index 686afc97289b1..673fa4c0c4bc0 100644 --- a/src/ci/docker/dist-i686-freebsd/Dockerfile +++ b/src/ci/docker/dist-i686-freebsd/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:18.04 RUN apt-get update && apt-get install -y --no-install-recommends \ clang \ diff --git a/src/ci/docker/dist-x86_64-freebsd/Dockerfile b/src/ci/docker/dist-x86_64-freebsd/Dockerfile index 7483d395622c8..f9f5b7062f8a4 100644 --- a/src/ci/docker/dist-x86_64-freebsd/Dockerfile +++ b/src/ci/docker/dist-x86_64-freebsd/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:18.04 RUN apt-get update && apt-get install -y --no-install-recommends \ clang \ diff --git a/src/dlmalloc b/src/dlmalloc index d3812c3accaee..f229ef1cd942d 160000 --- a/src/dlmalloc +++ b/src/dlmalloc @@ -1 +1 @@ -Subproject commit d3812c3accaee7ad23068ed4fc089cc05c7a538f +Subproject commit f229ef1cd942d1bdad0a9e82f55a4472c32a1172 diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index b65b18d0caa8c..2e860f940a7a7 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -320,8 +320,8 @@ pub struct TargetOptions { /// Relocation model to use in object file. Corresponds to `llc /// -relocation-model=$relocation_model`. Defaults to "pic". pub relocation_model: String, - /// Code model to use. Corresponds to `llc -code-model=$code_model`. Defaults to "default". - pub code_model: String, + /// Code model to use. Corresponds to `llc -code-model=$code_model`. + pub code_model: Option, /// TLS model to use. Options are "global-dynamic" (default), "local-dynamic", "initial-exec" /// and "local-exec". This is similar to the -ftls-model option in GCC/Clang. pub tls_model: String, @@ -483,7 +483,7 @@ impl Default for TargetOptions { only_cdylib: false, executables: false, relocation_model: "pic".to_string(), - code_model: "default".to_string(), + code_model: None, tls_model: "global-dynamic".to_string(), disable_redzone: false, eliminate_frame_pointer: true, @@ -736,7 +736,7 @@ impl Target { key!(only_cdylib, bool); key!(executables, bool); key!(relocation_model); - key!(code_model); + key!(code_model, optional); key!(tls_model); key!(disable_redzone, bool); key!(eliminate_frame_pointer, bool); diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index b97e37f4c8fb9..9b9d7bd9d3682 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -299,12 +299,11 @@ pub enum RelocMode { #[repr(C)] pub enum CodeModel { Other, - Default, - JITDefault, Small, Kernel, Medium, Large, + None, } /// LLVMRustDiagnosticKind @@ -331,7 +330,6 @@ pub enum DiagnosticKind { pub enum ArchiveKind { Other, K_GNU, - K_MIPS64, K_BSD, K_COFF, } @@ -1546,7 +1544,7 @@ extern "C" { InlinedAt: MetadataRef) -> ValueRef; pub fn LLVMRustDIBuilderCreateOpDeref() -> i64; - pub fn LLVMRustDIBuilderCreateOpPlus() -> i64; + pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64; pub fn LLVMRustWriteTypeToString(Type: TypeRef, s: RustStringRef); pub fn LLVMRustWriteValueToString(value_ref: ValueRef, s: RustStringRef); @@ -1717,9 +1715,9 @@ extern "C" { Identifier: *const c_char, ) -> ModuleRef; pub fn LLVMGetModuleIdentifier(M: ModuleRef, size: *mut usize) -> *const c_char; - pub fn LLVMRustThinLTOGetDICompileUnit(M: ModuleRef, - CU1: *mut *mut c_void, - CU2: *mut *mut c_void); - pub fn LLVMRustThinLTOPatchDICompileUnit(M: ModuleRef, CU: *mut c_void); + pub fn LLVMRustLTOGetDICompileUnit(M: ModuleRef, + CU1: *mut *mut c_void, + CU2: *mut *mut c_void); + pub fn LLVMRustLTOPatchDICompileUnit(M: ModuleRef, CU: *mut c_void); pub fn LLVMRustThinLTORemoveAvailableExternally(M: ModuleRef); } diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index c75a026a0f8b9..8dcf7444dd18f 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -105,7 +105,6 @@ impl FromStr for ArchiveKind { fn from_str(s: &str) -> Result { match s { "gnu" => Ok(ArchiveKind::K_GNU), - "mips64" => Ok(ArchiveKind::K_MIPS64), "bsd" => Ok(ArchiveKind::K_BSD), "coff" => Ok(ArchiveKind::K_COFF), _ => Err(()), diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index b612247ffcd42..aea090167bb91 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -230,6 +230,17 @@ fn fat_lto(cgcx: &CodegenContext, let llmod = module.llvm().expect("can't lto pre-translated modules").llmod; info!("using {:?} as a base module", module.llmod_id); + // See comments in ThinLTO for what this is doing + let mut cu1 = ptr::null_mut(); + let mut cu2 = ptr::null_mut(); + unsafe { + llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2); + if !cu2.is_null() { + let msg = format!("multiple source DICompileUnits found"); + return Err(write::llvm_err(&diag_handler, msg)) + } + } + // For all other modules we translated we'll need to link them into our own // bitcode. All modules were translated in their own LLVM context, however, // and we want to move everything to the same LLVM context. Currently the @@ -265,14 +276,19 @@ fn fat_lto(cgcx: &CodegenContext, } cgcx.save_temp_bitcode(&module, "lto.input"); - // Internalize everything that *isn't* in our whitelist to help strip out - // more modules and such unsafe { + // Internalize everything that *isn't* in our whitelist to help strip + // out more modules and such let ptr = symbol_white_list.as_ptr(); llvm::LLVMRustRunRestrictionPass(llmod, ptr as *const *const libc::c_char, symbol_white_list.len() as libc::size_t); cgcx.save_temp_bitcode(&module, "lto.after-restriction"); + + // More documentation about this in ThinLTO below, but it suffices to + // say that this arises during normal LTO as well. + llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1); + cgcx.save_temp_bitcode(&module, "lto.after-patch"); } if cgcx.no_landing_pads { @@ -636,7 +652,7 @@ impl ThinModule { // an error. let mut cu1 = ptr::null_mut(); let mut cu2 = ptr::null_mut(); - llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2); + llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2); if !cu2.is_null() { let msg = format!("multiple source DICompileUnits found"); return Err(write::llvm_err(&diag_handler, msg)) @@ -712,7 +728,7 @@ impl ThinModule { // not too much) but for now at least gets LLVM to emit valid DWARF (or // so it appears). Hopefully we can remove this once upstream bugs are // fixed in LLVM. - llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1); + llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1); cgcx.save_temp_bitcode(&mtrans, "thin-lto-after-patch"); timeline.record("patch"); diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index a013af7a4600e..863f006985349 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -68,8 +68,7 @@ pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [ ("ropi-rwpi", llvm::RelocMode::ROPI_RWPI), ]; -pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeModel); 5] = [ - ("default", llvm::CodeModel::Default), +pub const CODE_GEN_MODEL_ARGS: &[(&str, llvm::CodeModel)] = &[ ("small", llvm::CodeModel::Small), ("kernel", llvm::CodeModel::Kernel), ("medium", llvm::CodeModel::Medium), @@ -170,20 +169,23 @@ pub fn target_machine_factory(sess: &Session) let ffunction_sections = sess.target.target.options.function_sections; let fdata_sections = ffunction_sections; - let code_model_arg = match sess.opts.cg.code_model { - Some(ref s) => &s, - None => &sess.target.target.options.code_model, - }; - - let code_model = match CODE_GEN_MODEL_ARGS.iter().find( - |&&arg| arg.0 == code_model_arg) { - Some(x) => x.1, - _ => { - sess.err(&format!("{:?} is not a valid code model", - code_model_arg)); - sess.abort_if_errors(); - bug!(); + let code_model_arg = sess.opts.cg.code_model.as_ref().or( + sess.target.target.options.code_model.as_ref(), + ); + + let code_model = match code_model_arg { + Some(s) => { + match CODE_GEN_MODEL_ARGS.iter().find(|arg| arg.0 == s) { + Some(x) => x.1, + _ => { + sess.err(&format!("{:?} is not a valid code model", + code_model_arg)); + sess.abort_if_errors(); + bug!(); + } + } } + None => llvm::CodeModel::None, }; let singlethread = sess.target.target.options.singlethread; diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs index 3064e2f7c7afd..b367eb6548d01 100644 --- a/src/librustc_trans/mir/mod.rs +++ b/src/librustc_trans/mir/mod.rs @@ -547,7 +547,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>, let ops = unsafe { [llvm::LLVMRustDIBuilderCreateOpDeref(), - llvm::LLVMRustDIBuilderCreateOpPlus(), + llvm::LLVMRustDIBuilderCreateOpPlusUconst(), byte_offset_of_var_in_env as i64, llvm::LLVMRustDIBuilderCreateOpDeref()] }; diff --git a/src/llvm b/src/llvm index 2717444753318..e997225f7fc8b 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 2717444753318e461e0c3b30dacd03ffbac96903 +Subproject commit e997225f7fc8b0a6526c0bc04c417b1d69b95db5 diff --git a/src/rustllvm/ArchiveWrapper.cpp b/src/rustllvm/ArchiveWrapper.cpp index b110013ceaed3..0641d2acb478c 100644 --- a/src/rustllvm/ArchiveWrapper.cpp +++ b/src/rustllvm/ArchiveWrapper.cpp @@ -42,7 +42,6 @@ struct RustArchiveIterator { enum class LLVMRustArchiveKind { Other, GNU, - MIPS64, BSD, COFF, }; @@ -51,8 +50,6 @@ static Archive::Kind fromRust(LLVMRustArchiveKind Kind) { switch (Kind) { case LLVMRustArchiveKind::GNU: return Archive::K_GNU; - case LLVMRustArchiveKind::MIPS64: - return Archive::K_MIPS64; case LLVMRustArchiveKind::BSD: return Archive::K_BSD; case LLVMRustArchiveKind::COFF: @@ -232,12 +229,22 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers, LLVMRustSetLastError(toString(MOrErr.takeError()).c_str()); return LLVMRustResult::Failure; } +#if LLVM_VERSION_GE(6, 0) + MOrErr->MemberName = sys::path::filename(MOrErr->MemberName); +#endif Members.push_back(std::move(*MOrErr)); } } - auto Pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false); - if (!Pair.second) + auto Result = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false); +#if LLVM_VERSION_GE(6, 0) + if (!Result) + return LLVMRustResult::Success; + LLVMRustSetLastError(toString(std::move(Result)).c_str()); +#else + if (!Result.second) return LLVMRustResult::Success; - LLVMRustSetLastError(Pair.second.message().c_str()); + LLVMRustSetLastError(Result.second.message().c_str()); +#endif + return LLVMRustResult::Failure; } diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 54a73a04bfa9e..1f9e2ec635423 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -23,9 +23,15 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetSubtargetInfo.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" +#if LLVM_VERSION_GE(6, 0) +#include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/IR/IntrinsicInst.h" +#else +#include "llvm/Target/TargetSubtargetInfo.h" +#endif + #if LLVM_VERSION_GE(4, 0) #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/FunctionImport.h" @@ -210,20 +216,15 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM, enum class LLVMRustCodeModel { Other, - Default, - JITDefault, Small, Kernel, Medium, Large, + None, }; static CodeModel::Model fromRust(LLVMRustCodeModel Model) { switch (Model) { - case LLVMRustCodeModel::Default: - return CodeModel::Default; - case LLVMRustCodeModel::JITDefault: - return CodeModel::JITDefault; case LLVMRustCodeModel::Small: return CodeModel::Small; case LLVMRustCodeModel::Kernel: @@ -360,7 +361,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( bool TrapUnreachable, bool Singlethread) { - auto CM = fromRust(RustCM); auto OptLevel = fromRust(RustOptLevel); auto RM = fromRust(RustReloc); @@ -399,6 +399,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( Options.ThreadModel = ThreadModel::Single; } +#if LLVM_VERSION_GE(6, 0) + Optional CM; +#else + CodeModel::Model CM = CodeModel::Model::Default; +#endif + if (RustCM != LLVMRustCodeModel::None) + CM = fromRust(RustCM); TargetMachine *TM = TheTarget->createTargetMachine( Trip.getTriple(), RealCPU, Feature, Options, RM, CM, OptLevel); return wrap(TM); @@ -1110,74 +1117,6 @@ LLVMRustParseBitcodeForThinLTO(LLVMContextRef Context, return wrap(std::move(*SrcOrError).release()); } -// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See -// the comment in `back/lto.rs` for why this exists. -extern "C" void -LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod, - DICompileUnit **A, - DICompileUnit **B) { - Module *M = unwrap(Mod); - DICompileUnit **Cur = A; - DICompileUnit **Next = B; - for (DICompileUnit *CU : M->debug_compile_units()) { - *Cur = CU; - Cur = Next; - Next = nullptr; - if (Cur == nullptr) - break; - } -} - -// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See -// the comment in `back/lto.rs` for why this exists. -extern "C" void -LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) { - Module *M = unwrap(Mod); - - // If the original source module didn't have a `DICompileUnit` then try to - // merge all the existing compile units. If there aren't actually any though - // then there's not much for us to do so return. - if (Unit == nullptr) { - for (DICompileUnit *CU : M->debug_compile_units()) { - Unit = CU; - break; - } - if (Unit == nullptr) - return; - } - - // Use LLVM's built-in `DebugInfoFinder` to find a bunch of debuginfo and - // process it recursively. Note that we specifically iterate over instructions - // to ensure we feed everything into it. - DebugInfoFinder Finder; - Finder.processModule(*M); - for (Function &F : M->functions()) { - for (auto &FI : F) { - for (Instruction &BI : FI) { - if (auto Loc = BI.getDebugLoc()) - Finder.processLocation(*M, Loc); - if (auto DVI = dyn_cast(&BI)) - Finder.processValue(*M, DVI); - if (auto DDI = dyn_cast(&BI)) - Finder.processDeclare(*M, DDI); - } - } - } - - // After we've found all our debuginfo, rewrite all subprograms to point to - // the same `DICompileUnit`. - for (auto &F : Finder.subprograms()) { - F->replaceUnit(Unit); - } - - // Erase any other references to other `DICompileUnit` instances, the verifier - // will later ensure that we don't actually have any other stale references to - // worry about. - auto *MD = M->getNamedMetadata("llvm.dbg.cu"); - MD->clearOperands(); - MD->addOperand(Unit); -} - extern "C" void LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) { Module *M = unwrap(Mod); @@ -1267,20 +1206,76 @@ LLVMRustParseBitcodeForThinLTO(LLVMContextRef Context, } extern "C" void -LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod, - DICompileUnit **A, - DICompileUnit **B) { +LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) { report_fatal_error("ThinLTO not available"); } +#endif // LLVM_VERSION_GE(4, 0) + extern "C" void -LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod) { - report_fatal_error("ThinLTO not available"); +LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod, + DICompileUnit **A, + DICompileUnit **B) { + Module *M = unwrap(Mod); + DICompileUnit **Cur = A; + DICompileUnit **Next = B; + for (DICompileUnit *CU : M->debug_compile_units()) { + *Cur = CU; + Cur = Next; + Next = nullptr; + if (Cur == nullptr) + break; + } } +// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See +// the comment in `back/lto.rs` for why this exists. extern "C" void -LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) { - report_fatal_error("ThinLTO not available"); -} +LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) { +#if LLVM_VERSION_GE(4, 0) + Module *M = unwrap(Mod); -#endif // LLVM_VERSION_GE(4, 0) + // If the original source module didn't have a `DICompileUnit` then try to + // merge all the existing compile units. If there aren't actually any though + // then there's not much for us to do so return. + if (Unit == nullptr) { + for (DICompileUnit *CU : M->debug_compile_units()) { + Unit = CU; + break; + } + if (Unit == nullptr) + return; + } + + // Use LLVM's built-in `DebugInfoFinder` to find a bunch of debuginfo and + // process it recursively. Note that we specifically iterate over instructions + // to ensure we feed everything into it. + DebugInfoFinder Finder; + Finder.processModule(*M); + for (Function &F : M->functions()) { + for (auto &FI : F) { + for (Instruction &BI : FI) { + if (auto Loc = BI.getDebugLoc()) + Finder.processLocation(*M, Loc); + if (auto DVI = dyn_cast(&BI)) + Finder.processValue(*M, DVI); + if (auto DDI = dyn_cast(&BI)) + Finder.processDeclare(*M, DDI); + } + } + } + + // After we've found all our debuginfo, rewrite all subprograms to point to + // the same `DICompileUnit`. + for (auto &F : Finder.subprograms()) { + F->replaceUnit(Unit); + } + + // Erase any other references to other `DICompileUnit` instances, the verifier + // will later ensure that we don't actually have any other stale references to + // worry about. + auto *MD = M->getNamedMetadata("llvm.dbg.cu"); + MD->clearOperands(); + MD->addOperand(Unit); +#endif +} diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 95130d596e165..3491e5a4aed5a 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -315,7 +315,11 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, // enable fpmath flag UnsafeAlgebra extern "C" void LLVMRustSetHasUnsafeAlgebra(LLVMValueRef V) { if (auto I = dyn_cast(unwrap(V))) { +#if LLVM_VERSION_GE(6, 0) + I->setFast(true); +#else I->setHasUnsafeAlgebra(true); +#endif } } @@ -866,7 +870,14 @@ extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() { return dwarf::DW_OP_deref; } -extern "C" int64_t LLVMRustDIBuilderCreateOpPlus() { return dwarf::DW_OP_plus; } +extern "C" int64_t LLVMRustDIBuilderCreateOpPlusUconst() { +#if LLVM_VERSION_GE(5, 0) + return dwarf::DW_OP_plus_uconst; +#else + // older LLVM used `plus` to behave like `plus_uconst`. + return dwarf::DW_OP_plus; +#endif +} extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Ty, RustStringRef Str) { RawRustStringOstream OS(Str); diff --git a/src/test/debuginfo/by-value-self-argument-in-trait-impl.rs b/src/test/debuginfo/by-value-self-argument-in-trait-impl.rs index c14f8c7b354fc..35bc3ae807af3 100644 --- a/src/test/debuginfo/by-value-self-argument-in-trait-impl.rs +++ b/src/test/debuginfo/by-value-self-argument-in-trait-impl.rs @@ -9,6 +9,7 @@ // except according to those terms. // min-lldb-version: 310 +// ignore-test // compile-flags:-g