From ffed4c7dc45f535a03df8b25a77968a8b03d7485 Mon Sep 17 00:00:00 2001 From: hadeptrai2k9 Date: Wed, 4 Mar 2026 01:27:48 +0700 Subject: [PATCH 1/2] Add "optforfuzzing" func attribute when fuzzing is enabled --- gen/functions.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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); } From 3b471dd628839415684eddca65293a0e47e42195 Mon Sep 17 00:00:00 2001 From: hadeptrai2k9 Date: Wed, 4 Mar 2026 09:16:20 +0700 Subject: [PATCH 2/2] Adding test file --- tests/codegen/attr_optforfuzzing.d | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/codegen/attr_optforfuzzing.d 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