MaskRay created this revision. MaskRay added reviewers: bkramer, CJ-Johnson, jdoerfert, rjmccall, rsmith. Herald added a project: clang. Herald added a subscriber: cfe-commits. MaskRay requested review of this revision.
After D17993 <https://reviews.llvm.org/D17993>, with -fno-delete-null-pointer-checks we add the dereferenceable attribute. We have observed that one target which worked before fails with -fno-delete-null-pointer-checks. Switching to dereferenceable_or_null fixes the problem. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D92297 Files: clang/lib/CodeGen/CGCall.cpp clang/test/CodeGenCXX/this-nonnull.cpp Index: clang/test/CodeGenCXX/this-nonnull.cpp =================================================================== --- clang/test/CodeGenCXX/this-nonnull.cpp +++ clang/test/CodeGenCXX/this-nonnull.cpp @@ -12,8 +12,8 @@ s.ReturnsVoid(); // CHECK-YES: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull dereferenceable(12) %0) - // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable(12) %0) + // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable_or_null(12) %0) } // CHECK-YES: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull dereferenceable(12)) -// CHECK-NO: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable(12)) +// CHECK-NO: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable_or_null(12)) Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -2168,13 +2168,17 @@ if (!CodeGenOpts.NullPointerIsValid && getContext().getTargetAddressSpace(FI.arg_begin()->type) == 0) { Attrs.addAttribute(llvm::Attribute::NonNull); + Attrs.addDereferenceableAttr( + getMinimumObjectSize( + FI.arg_begin()->type.castAs<PointerType>()->getPointeeType()) + .getQuantity()); + } else { + Attrs.addDereferenceableOrNullAttr( + getMinimumObjectSize( + FI.arg_begin()->type.castAs<PointerType>()->getPointeeType()) + .getQuantity()); } - Attrs.addDereferenceableAttr( - getMinimumObjectSize( - FI.arg_begin()->type.castAs<PointerType>()->getPointeeType()) - .getQuantity()); - ArgAttrs[IRArgs.first] = llvm::AttributeSet::get(getLLVMContext(), Attrs); }
Index: clang/test/CodeGenCXX/this-nonnull.cpp =================================================================== --- clang/test/CodeGenCXX/this-nonnull.cpp +++ clang/test/CodeGenCXX/this-nonnull.cpp @@ -12,8 +12,8 @@ s.ReturnsVoid(); // CHECK-YES: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull dereferenceable(12) %0) - // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable(12) %0) + // CHECK-NO: call void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable_or_null(12) %0) } // CHECK-YES: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* nonnull dereferenceable(12)) -// CHECK-NO: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable(12)) +// CHECK-NO: declare void @_ZN6Struct11ReturnsVoidEv(%struct.Struct* dereferenceable_or_null(12)) Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -2168,13 +2168,17 @@ if (!CodeGenOpts.NullPointerIsValid && getContext().getTargetAddressSpace(FI.arg_begin()->type) == 0) { Attrs.addAttribute(llvm::Attribute::NonNull); + Attrs.addDereferenceableAttr( + getMinimumObjectSize( + FI.arg_begin()->type.castAs<PointerType>()->getPointeeType()) + .getQuantity()); + } else { + Attrs.addDereferenceableOrNullAttr( + getMinimumObjectSize( + FI.arg_begin()->type.castAs<PointerType>()->getPointeeType()) + .getQuantity()); } - Attrs.addDereferenceableAttr( - getMinimumObjectSize( - FI.arg_begin()->type.castAs<PointerType>()->getPointeeType()) - .getQuantity()); - ArgAttrs[IRArgs.first] = llvm::AttributeSet::get(getLLVMContext(), Attrs); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits