commit 427810f3edea1beba77e3f84dd695dd0a8c35f00 (tree)
parent e9ae9a5fc45a6ee85d988372a4d150032f52ef4c
Author: Alex Rønne Petersen <alex@alexrp.com>
Date: Thu, 31 Oct 2024 09:25:16 +0100
llvm: Don't set nonnull attribute on pointers in non-generic address spaces.
LLVM considers null pointers to be valid for such address spaces.
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
@@ -1341,7 +1341,10 @@ pub const Object = struct {
try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
}
}
- if (param_ty.zigTypeTag(zcu) != .optional and !ptr_info.flags.is_allowzero) {
+ if (param_ty.zigTypeTag(zcu) != .optional and
+ !ptr_info.flags.is_allowzero and
+ ptr_info.flags.address_space == .generic)
+ {
try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
}
if (ptr_info.flags.is_const) {
@@ -4358,7 +4361,10 @@ pub const Object = struct {
try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
}
}
- if (!param_ty.isPtrLikeOptional(zcu) and !ptr_info.flags.is_allowzero) {
+ if (!param_ty.isPtrLikeOptional(zcu) and
+ !ptr_info.flags.is_allowzero and
+ ptr_info.flags.address_space == .generic)
+ {
try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
}
switch (fn_info.cc) {
@@ -5410,7 +5416,10 @@ pub const FuncGen = struct {
try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
}
}
- if (param_ty.zigTypeTag(zcu) != .optional and !ptr_info.flags.is_allowzero) {
+ if (param_ty.zigTypeTag(zcu) != .optional and
+ !ptr_info.flags.is_allowzero and
+ ptr_info.flags.address_space == .generic)
+ {
try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
}
if (ptr_info.flags.is_const) {