X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Flibrustc_codegen_llvm%2Fattributes.rs;h=a9e4fdba030366ee60a2d104da1290cdcd68ae14;hb=a77206fa4a35e7926fb4404bd167b06e342b7626;hp=e3920d99c90bc644f5b5364428119f9b9b05b94c;hpb=b18b26924c640211a358535f14e39695c48b0ec3;p=rust.git diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index e3920d99c90..a9e4fdba030 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -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,