llvm: Don't set nonnull attribute on pointers in non-generic address spaces.

LLVM considers null pointers to be valid for such address spaces.
This commit is contained in:
Alex Rønne Petersen 2024-10-31 09:25:16 +01:00
parent e9ae9a5fc4
commit 427810f3ed
No known key found for this signature in database

View file

@ -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) {