X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_codegen_llvm%2Fattributes.rs;h=a9e4fdba030366ee60a2d104da1290cdcd68ae14;hb=2b0cfa5b4c5099f45ca540ee1c7d8c1ecd5267d2;hp=fc1b365cf90ce57cfbeaf1a54a3d8ea83e0df4c8;hpb=138c50f0af57e2631aa09092b826e2c3efd224d2;p=rust.git diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index fc1b365cf90..a9e4fdba030 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -21,7 +21,7 @@ use crate::llvm::AttributePlace::Function; use crate::llvm::{self, Attribute}; use crate::llvm_util; -pub use syntax::attr::{self, InlineAttr, OptimizeAttr}; +pub use rustc_attr::{self as attr, InlineAttr, OptimizeAttr}; use crate::context::CodegenCx; use crate::value::Value; @@ -46,6 +46,31 @@ fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) { }; } +/// Apply LLVM sanitize attributes. +#[inline] +pub fn sanitize(cx: &CodegenCx<'ll, '_>, codegen_fn_flags: CodegenFnAttrFlags, llfn: &'ll Value) { + if let Some(ref sanitizer) = cx.tcx.sess.opts.debugging_opts.sanitizer { + match *sanitizer { + Sanitizer::Address => { + if !codegen_fn_flags.contains(CodegenFnAttrFlags::NO_SANITIZE_ADDRESS) { + llvm::Attribute::SanitizeAddress.apply_llfn(Function, llfn); + } + } + Sanitizer::Memory => { + if !codegen_fn_flags.contains(CodegenFnAttrFlags::NO_SANITIZE_MEMORY) { + llvm::Attribute::SanitizeMemory.apply_llfn(Function, llfn); + } + } + Sanitizer::Thread => { + if !codegen_fn_flags.contains(CodegenFnAttrFlags::NO_SANITIZE_THREAD) { + llvm::Attribute::SanitizeThread.apply_llfn(Function, llfn); + } + } + Sanitizer::Leak => {} + } + } +} + /// Tell LLVM to emit or not emit the information necessary to unwind the stack for the function. #[inline] pub fn emit_uwtable(val: &'ll Value, emit: bool) { @@ -288,6 +313,7 @@ pub fn from_fn_attrs( if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR) { Attribute::NoAlias.apply_llfn(llvm::AttributePlace::ReturnValue, llfn); } + sanitize(cx, codegen_fn_attrs.flags, llfn); unwind( llfn,