From ac09ff7d647f483190c8745a09c8efa290adba91 Mon Sep 17 00:00:00 2001 From: hadeptrai2k9 Date: Wed, 4 Mar 2026 22:34:18 +0700 Subject: [PATCH 1/2] Add -fno-builtin command line flag --- driver/cl_options.cpp | 6 ++++++ driver/cl_options.h | 1 + gen/functions.cpp | 4 +++- tests/codegen/attr_fno_builtin.d | 6 ++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/codegen/attr_fno_builtin.d diff --git a/driver/cl_options.cpp b/driver/cl_options.cpp index 5b155a6797..e2de5d7982 100644 --- a/driver/cl_options.cpp +++ b/driver/cl_options.cpp @@ -20,6 +20,12 @@ namespace opts { // This vector is filled by parseCommandLine in main.cpp. llvm::SmallVector allArguments; +cl::opt noBuiltIn( + "fno-builtin", + cl::desc("Disable implicit builtin knowledge of functions"), + cl::ZeroOrMore +); + cl::OptionCategory linkingCategory("Linking options"); // Positional options first, in order: diff --git a/driver/cl_options.h b/driver/cl_options.h index 964874bcce..481b83adcc 100644 --- a/driver/cl_options.h +++ b/driver/cl_options.h @@ -41,6 +41,7 @@ extern cl::OptionCategory linkingCategory; egrep -e '^(cl::|#if|#e)' gen/cl_options.cpp \ | sed -re 's/^(cl::.*)\(.*$/ extern \1;/' */ +extern cl::opt noBuiltIn; extern cl::list fileList; extern cl::list runargs; extern cl::opt invokedByLDMD; diff --git a/gen/functions.cpp b/gen/functions.cpp index 3c3e6d3d35..1457e1ab77 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -1190,7 +1190,9 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) { if (opts::isUsingSampleBasedPGOProfile()) { func->addFnAttr("use-sample-profile"); } - + if (opts::noBuiltIn) { + func->addFnAttr("no-built-in"); + } if (fd->hasInlineAsm()) { // disable frame-pointer-elimination for functions with DMD-style inline asm func->addFnAttr("frame-pointer", "all"); diff --git a/tests/codegen/attr_fno_builtin.d b/tests/codegen/attr_fno_builtin.d new file mode 100644 index 0000000000..23e378fc9c --- /dev/null +++ b/tests/codegen/attr_fno_builtin.d @@ -0,0 +1,6 @@ +// RUN: %ldc -c -output-ll -fno-builtin -of=%t.ll %s && FileCheck %s < %t.ll + +// CHECK: define {{.*}} @builtin{{.*}} [[ATTR:#[0-9]+]] +extern(C) void builtin() {} + +// CHECK: attributes [[ATTR]] = { {{.*}}"no-builtins"{{.*}} } \ No newline at end of file From 21b12867f83e79343da1d678c165d12617671955 Mon Sep 17 00:00:00 2001 From: hadeptrai2k9 Date: Wed, 4 Mar 2026 23:26:35 +0700 Subject: [PATCH 2/2] fix failing tests --- tests/codegen/attr_fno_builtin.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/attr_fno_builtin.d b/tests/codegen/attr_fno_builtin.d index 23e378fc9c..87dba105eb 100644 --- a/tests/codegen/attr_fno_builtin.d +++ b/tests/codegen/attr_fno_builtin.d @@ -3,4 +3,4 @@ // CHECK: define {{.*}} @builtin{{.*}} [[ATTR:#[0-9]+]] extern(C) void builtin() {} -// CHECK: attributes [[ATTR]] = { {{.*}}"no-builtins"{{.*}} } \ No newline at end of file +// CHECK: attributes [[ATTR]] = { {{.*}}"no-built-in"{{.*}} } \ No newline at end of file