diff --git a/gen/functions.cpp b/gen/functions.cpp index 3c3e6d3d35..8b785f24dc 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -1172,6 +1172,10 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) { func->addFnAttr(LLAttribute::SanitizeAddress); } + if (opts::isSanitizerEnabled(opts::FuzzSanitizer)) { + func->addFnAttr(LLAttribute::OptForFuzzing); + } + if (opts::isSanitizerEnabled(opts::MemorySanitizer & noSanitizeMask)) { func->addFnAttr(LLAttribute::SanitizeMemory); } diff --git a/tests/codegen/attr_optforfuzzing.d b/tests/codegen/attr_optforfuzzing.d new file mode 100644 index 0000000000..5597e0155d --- /dev/null +++ b/tests/codegen/attr_optforfuzzing.d @@ -0,0 +1,6 @@ +// RUN: %ldc -c -output-ll -fsanitize=fuzzer -of=%t.ll %s && FileCheck %s < %t.ll + +// CHECK: define {{.*}} @f{{.*}} [[ATTR:#[0-9]+]] +extern(C) void f() {} + +// CHECK: attributes [[ATTR]] = { {{.*}}optforfuzzing{{.*}} } \ No newline at end of file