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;
};
}
+/// 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) {
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,