[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-25 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes. Closed by commit rG0c9c9dd9a24f: [clang][Sema] Add truncation warning on fortified snprintf (authored by hazohelet). Changed prior to commit: https://reviews.llvm.org/D158562?vs=553246=553702#toc Repository: rG LLVM

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision. aaron.ballman added a comment. LGTM! Comment at: clang/lib/Sema/SemaChecking.cpp:1041 + ASTContext ) { + if (auto *Format = dyn_cast(FormatExpr); + Format && (Format->isOrdinary() ||

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-24 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 553246. hazohelet added a comment. Fixes `EstimateSizeFormatHandler`'s `%g` handling. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158562/new/ https://reviews.llvm.org/D158562 Files: clang/docs/ReleaseNotes.rst

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-24 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment. In D158562#4614835 , @aaron.ballman wrote: > Thank you for working on this! > > Precommit CI found an issue with libc++'s tests: > https://reviews.llvm.org/harbormaster/unit/view/8606248/ -- it'd be best if > those could be

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment. Thank you for working on this! Precommit CI found an issue with libc++'s tests: https://reviews.llvm.org/harbormaster/unit/view/8606248/ -- it'd be best if those could be addressed before landing the changes. CHANGES SINCE LAST ACTION

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment. Gcc can diagnose wider cases of overflow/truncation by specifying a higher level for it, like `-Wformat-overflow=2` (https://godbolt.org/z/n5facjW1c). The current clang counterpart only diagnoses when the format string is //always// larger than the buffer size. If we

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 552939. hazohelet marked 4 inline comments as done. hazohelet added a comment. Address review comments CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158562/new/ https://reviews.llvm.org/D158562 Files: clang/docs/ReleaseNotes.rst

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-23 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment. Thanks for the patch! Comment at: clang/lib/Sema/SemaChecking.cpp:1134 }; + auto ProcessFormatStringLiteral = + [&](const Expr *FormatExpr, StringRef , size_t ) { naive question, so will we create a lambda with capture

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment. Can't say much about the rest of the patch so I'd defer to someone else. Since gcc has `-Wformat-truncation`, can we disable this warning in clang as well? Can you add a test for that? Comment at: clang/lib/Sema/SemaChecking.cpp:1136-1137 +

[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

2023-08-22 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet created this revision. hazohelet added reviewers: aaron.ballman, serge-sans-paille, nickdesaulniers, tbaeder. Herald added a project: All. hazohelet requested review of this revision. Herald added a project: clang. This patch warns on `snprintf` calls whose `n` argument is known to be