@@ -1447,6 +1447,19 @@ pub const Object = struct {
14471447 try attributes.addFnAttr(.nosanitize_coverage, &o.builder);
14481448 }
14491449
1450+ const disable_intrinsics = func_analysis.disable_intrinsics or owner_mod.no_builtin;
1451+ if (disable_intrinsics) {
1452+ // The intent here is for compiler-rt and libc functions to not generate
1453+ // infinite recursion. For example, if we are compiling the memcpy function,
1454+ // and llvm detects that the body is equivalent to memcpy, it may replace the
1455+ // body of memcpy with a call to memcpy, which would then cause a stack
1456+ // overflow instead of performing memcpy.
1457+ try attributes.addFnAttr(.{ .string = .{
1458+ .kind = try o.builder.string("no-builtins"),
1459+ .value = .empty,
1460+ } }, &o.builder);
1461+ }
1462+
14501463 // TODO: disable this if safety is off for the function scope
14511464 const ssp_buf_size = owner_mod.stack_protector;
14521465 if (ssp_buf_size != 0) {
@@ -1750,6 +1763,7 @@ pub const Object = struct {
17501763 .prev_dbg_line = 0,
17511764 .prev_dbg_column = 0,
17521765 .err_ret_trace = err_ret_trace,
1766+ .disable_intrinsics = disable_intrinsics,
17531767 };
17541768 defer fg.deinit();
17551769 deinit_wip = false;
@@ -3129,17 +3143,6 @@ pub const Object = struct {
31293143 &o.builder,
31303144 );
31313145 }
3132- if (owner_mod.no_builtin) {
3133- // The intent here is for compiler-rt and libc functions to not generate
3134- // infinite recursion. For example, if we are compiling the memcpy function,
3135- // and llvm detects that the body is equivalent to memcpy, it may replace the
3136- // body of memcpy with a call to memcpy, which would then cause a stack
3137- // overflow instead of performing memcpy.
3138- try attributes.addFnAttr(.{ .string = .{
3139- .kind = try o.builder.string("no-builtins"),
3140- .value = .empty,
3141- } }, &o.builder);
3142- }
31433146 if (owner_mod.optimize_mode == .ReleaseSmall) {
31443147 try attributes.addFnAttr(.minsize, &o.builder);
31453148 try attributes.addFnAttr(.optsize, &o.builder);
@@ -4918,6 +4921,8 @@ pub const FuncGen = struct {
49184921
49194922 sync_scope: Builder.SyncScope,
49204923
4924+ disable_intrinsics: bool,
4925+
49214926 const Fuzz = struct {
49224927 counters_variable: Builder.Variable.Index,
49234928 pcs: std.ArrayListUnmanaged(Builder.Constant),
@@ -5443,7 +5448,7 @@ pub const FuncGen = struct {
54435448 var attributes: Builder.FunctionAttributes.Wip = .{};
54445449 defer attributes.deinit(&o.builder);
54455450
5446- if (self.ng.ownerModule().no_builtin ) {
5451+ if (self.disable_intrinsics ) {
54475452 try attributes.addFnAttr(.nobuiltin, &o.builder);
54485453 }
54495454
@@ -5770,7 +5775,7 @@ pub const FuncGen = struct {
57705775 try o.builder.intValue(.i8, 0xaa),
57715776 len,
57725777 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
5773- self.ng.ownerModule().no_builtin ,
5778+ self.disable_intrinsics ,
57745779 );
57755780 const owner_mod = self.ng.ownerModule();
57765781 if (owner_mod.valgrind) {
@@ -5821,7 +5826,7 @@ pub const FuncGen = struct {
58215826 try o.builder.intValue(.i8, 0xaa),
58225827 len,
58235828 .normal,
5824- self.ng.ownerModule().no_builtin ,
5829+ self.disable_intrinsics ,
58255830 );
58265831 const owner_mod = self.ng.ownerModule();
58275832 if (owner_mod.valgrind) {
@@ -9735,7 +9740,7 @@ pub const FuncGen = struct {
97359740 if (safety) try o.builder.intValue(.i8, 0xaa) else try o.builder.undefValue(.i8),
97369741 len,
97379742 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
9738- self.ng.ownerModule().no_builtin ,
9743+ self.disable_intrinsics ,
97399744 );
97409745 if (safety and owner_mod.valgrind) {
97419746 try self.valgrindMarkUndef(dest_ptr, len);
@@ -10057,7 +10062,7 @@ pub const FuncGen = struct {
1005710062 fill_byte,
1005810063 len,
1005910064 access_kind,
10060- self.ng.ownerModule().no_builtin ,
10065+ self.disable_intrinsics ,
1006110066 );
1006210067 }
1006310068 const owner_mod = self.ng.ownerModule();
@@ -10089,7 +10094,7 @@ pub const FuncGen = struct {
1008910094 fill_byte,
1009010095 len,
1009110096 access_kind,
10092- self.ng.ownerModule().no_builtin ,
10097+ self.disable_intrinsics ,
1009310098 );
1009410099 }
1009510100 return .none;
@@ -10119,7 +10124,7 @@ pub const FuncGen = struct {
1011910124 fill_byte,
1012010125 len,
1012110126 access_kind,
10122- self.ng.ownerModule().no_builtin ,
10127+ self.disable_intrinsics ,
1012310128 );
1012410129 }
1012510130 return .none;
@@ -10172,7 +10177,7 @@ pub const FuncGen = struct {
1017210177 elem_abi_align.toLlvm(),
1017310178 try o.builder.intValue(llvm_usize_ty, elem_abi_size),
1017410179 access_kind,
10175- self.ng.ownerModule().no_builtin ,
10180+ self.disable_intrinsics ,
1017610181 );
1017710182 } else _ = try self.wip.store(access_kind, value, it_ptr.toValue(), it_ptr_align);
1017810183 const next_ptr = try self.wip.gep(.inbounds, elem_llvm_ty, it_ptr.toValue(), &.{
@@ -10206,7 +10211,7 @@ pub const FuncGen = struct {
1020610211 fill_byte,
1020710212 len,
1020810213 access_kind,
10209- self.ng.ownerModule().no_builtin ,
10214+ self.disable_intrinsics ,
1021010215 );
1021110216 _ = try self.wip.br(end_block);
1021210217 self.wip.cursor = .{ .block = end_block };
@@ -10249,7 +10254,7 @@ pub const FuncGen = struct {
1024910254 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
1025010255 len,
1025110256 access_kind,
10252- self.ng.ownerModule().no_builtin ,
10257+ self.disable_intrinsics ,
1025310258 );
1025410259 _ = try self.wip.br(end_block);
1025510260 self.wip.cursor = .{ .block = end_block };
@@ -10263,7 +10268,7 @@ pub const FuncGen = struct {
1026310268 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
1026410269 len,
1026510270 access_kind,
10266- self.ng.ownerModule().no_builtin ,
10271+ self.disable_intrinsics ,
1026710272 );
1026810273 return .none;
1026910274 }
@@ -11397,7 +11402,7 @@ pub const FuncGen = struct {
1139711402 ptr_alignment,
1139811403 try o.builder.intValue(try o.lowerType(Type.usize), size_bytes),
1139911404 access_kind,
11400- fg.ng.ownerModule().no_builtin ,
11405+ fg.disable_intrinsics ,
1140111406 );
1140211407 return result_ptr;
1140311408 }
@@ -11565,7 +11570,7 @@ pub const FuncGen = struct {
1156511570 elem_ty.abiAlignment(zcu).toLlvm(),
1156611571 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)),
1156711572 access_kind,
11568- self.ng.ownerModule().no_builtin ,
11573+ self.disable_intrinsics ,
1156911574 );
1157011575 }
1157111576
0 commit comments