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..87dba105eb --- /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-built-in"{{.*}} } \ No newline at end of file