[clang] [clang][sema] Add nonnull attribute to builtin format functions (PR #160988)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 14 09:18:29 PDT 2025
Radovan =?utf-8?q?Božić?= <radovan.bozic at htecgroup.com>,
Radovan =?utf-8?q?Božić?= <radovan.bozic at htecgroup.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/160988 at github.com>
AaronBallman wrote:
> Thank you for the thoughtful feedback! I was wondering - are you suggesting introducing a new attribute (e.g. nullable) to explicitly mark arguments that can accept null? Wouldn’t that approach potentially break existing code and tests by triggering new warnings, since every unannotated pointer would be treated as non-null by default?
No, but yes. :-D
I think most pointers in standard library functions cannot be null. So it might be easier to maintain for our tablegen to assume *all* pointers are nonnull unless we add an annotation to say which parameters can be null. Then when generating the headers from tablegen, we'd add `__attribute__((nonnull))` to the parameters which must be nonnull.
But the attribute we should add, but not as part of this PR, is one from GCC: `nonnull_if_nonzero`. We need that for a number of the APIs where you *can* pass a null pointer but only when the size argument is zero.
https://github.com/llvm/llvm-project/pull/160988
More information about the cfe-commits
mailing list