[clang] [clang][sema] Add nonnull attribute to builtin format functions (PR #158626)
Radovan Božić via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 22 04:04:18 PDT 2025
================
@@ -293,6 +293,34 @@ bool Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx,
return isLike(ID, FormatIdx, HasVAListArg, "sS");
}
+bool Builtin::Context::IsNonNull(unsigned ID,
+ llvm::SmallVectorImpl<int> &Indxs) const {
+
+ const char *CalleePos = ::strchr(getAttributesString(ID), 'N');
+ if (!CalleePos)
+ return false;
+
+ ++CalleePos;
+ assert(*CalleePos == '<' &&
+ "Callback callee specifier must be followed by a '<'");
+ ++CalleePos;
+
+ char *EndPos;
+ int CalleeIdx = ::strtol(CalleePos, &EndPos, 10);
+ assert(CalleeIdx >= 0 && "Callee index is supposed to be positive!");
+ Indxs.push_back(CalleeIdx);
+
+ while (*EndPos == ',') {
+ const char *PayloadPos = EndPos + 1;
+
+ int PayloadIdx = ::strtol(PayloadPos, &EndPos, 10);
+ Indxs.push_back(PayloadIdx);
+ }
+
+ assert(*EndPos == '>' && "Callback callee specifier must end with a '>'");
+ return true;
----------------
bozicrHT wrote:
I refactored the parsing into a static helper `parseCommaSeparatedIndices`. Since `performsCallback` uses `SmallVector<int>` and `isNonNull` should use `SmallVector<unsigned>`, there are two options:
1. Change `isNonNull` to use int.
2. Make the helper templated on the element type to handle both int and unsigned.
We keep them separate because `CallbackAttr::CreateImplicit` requires `int*`, and changing that would need a separate PR. What are you thoughts, should I leave it as int or template it?
https://github.com/llvm/llvm-project/pull/158626
More information about the cfe-commits
mailing list