From bdca2d0f485682f78ea155df9f9f1cbb5f461ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 5 Nov 2024 14:33:13 +0100 Subject: [PATCH] llvm: Also apply the nobuiltin attribute for the no_builtin module option. From `zig build-exe --help`: -fno-builtin Disable implicit builtin knowledge of functions It seems entirely reasonable and even expected that this option should imply both no-builtins on functions (which disables transformation of recognized code patterns to libcalls) and nobuiltin on call sites (which disables transformation of libcalls to intrinsics). We now match Clang's behavior for -fno-builtin. In both cases, we're painting with a fairly broad brush by applying this to an entire module, but it's better than nothing. #21833 proposes a more fine-grained way to apply nobuiltin. --- src/codegen/llvm.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 1b90453d49..aa5a027f05 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -5576,6 +5576,10 @@ pub const FuncGen = struct { var attributes: Builder.FunctionAttributes.Wip = .{}; defer attributes.deinit(&o.builder); + if (self.ng.ownerModule().no_builtin) { + try attributes.addFnAttr(.nobuiltin, &o.builder); + } + switch (modifier) { .auto, .never_tail, .always_tail => {}, .never_inline => try attributes.addFnAttr(.@"noinline", &o.builder),