From 49599f71e9865eadefa2ab0275e32ca9bedfbfd1 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Sun, 19 Jan 2014 13:03:37 +0100 Subject: [PATCH] Add sanitizer attributes. If the sanitizer is enabled (e.g. -sanitize=address) then the corresponding attribute (e.g. llvm::Attribute::SanitizerAddress) must be set. --- gen/functions.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gen/functions.cpp b/gen/functions.cpp index 7f3e12bb..68866678 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -25,6 +25,7 @@ #include "gen/llvmhelpers.h" #include "gen/logger.h" #include "gen/nested.h" +#include "gen/optimizer.h" #include "gen/pragma.h" #include "gen/runtime.h" #include "gen/tollvm.h" @@ -989,6 +990,22 @@ void DtoDefineFunction(FuncDeclaration* fd) { func->addFnAttr(llvm::Attribute::UWTable); } +#if LDC_LLVM_VER >= 303 + if (opts::sanitize != opts::None) { + // Set the required sanitizer attribute. + if (opts::sanitize == opts::AddressSanitizer) { + func->addFnAttr(llvm::Attribute::SanitizeAddress); + } + + if (opts::sanitize == opts::MemorySanitizer) { + func->addFnAttr(llvm::Attribute::SanitizeMemory); + } + + if (opts::sanitize == opts::ThreadSanitizer) { + func->addFnAttr(llvm::Attribute::SanitizeThread); + } + } +#endif std::string entryname("entry");