[clang] [clang][Sema] Avoid out-of-bounds format_arg access (PR #229010)

Chen Miao via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 7 12:52:07 PDT 2026


ChenMiaoi wrote:

> This solution feels like a bit of a hack: we implicitly add an attribute that references an argument that doesn’t exist, then complain when we try to get that argument (which we only do because the compiler implicitly added an attribute). The diagnostic is also not great ‘format string is not a string literal’ when there is no argument to begin with is a rather janky.
> 
> Both the `format` and `format_arg` attributes are currently ignored on prototypeless declarations. We should probably just not be implicitly adding attributes that reference parameters in the first place if the function has no prototype.
> 
> A proper fix for this would go in `Sema::AddKnownFunctionAttributes()` I believe.
> 
> Additionally, this still needs a release note

Thanks for the explanation. That makes sense—I'll rework the fix and add a release note.

https://github.com/llvm/llvm-project/pull/229010


More information about the cfe-commits mailing list