This is an archive of the discontinued LLVM Phabricator instance.

[Sema] check InitListExpr format strings like {"foo"}
ClosedPublic

Authored by inclyc on Nov 11 2022, 6:50 AM.

Details

Summary

Adds InitListExpr case in format string checks.

e.g.

int sprintf(char *__restrict, const char * __restrict, ...);

int foo()
{
    char data[100];
    constexpr const char* fmt2{"%d"};  // no-warning
    sprintf(data, fmt2, 123);
}

Fixes: https://github.com/llvm/llvm-project/issues/58900

Diff Detail

Event Timeline

inclyc created this revision.Nov 11 2022, 6:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 6:50 AM
inclyc published this revision for review.Nov 11 2022, 6:50 AM
inclyc added a reviewer: aaron.ballman.
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 6:51 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Do we need release notes here? This patch is just an improvement to https://reviews.llvm.org/D130906

aaron.ballman accepted this revision.Nov 22 2022, 12:45 PM

Do we need release notes here? This patch is just an improvement to https://reviews.llvm.org/D130906

I don't think we need release notes in this case, the existing ones work well enough.

LGTM with a request for an additional test case (you can add it when you land the changes, I don't expect surprises from the test, it's just for regression coverage).

clang/test/SemaCXX/format-strings.cpp
208

Cam you also add a test case for:

printf(fmt, "oops", 1.0f);

to show that we still issue diagnostics when they're appropriate?

This revision is now accepted and ready to land.Nov 22 2022, 12:45 PM
inclyc updated this revision to Diff 477279.Nov 22 2022, 12:56 PM

Address comments

  • add a test to coverage warnings if appropriate
This revision was landed with ongoing or failed builds.Nov 22 2022, 12:59 PM
This revision was automatically updated to reflect the committed changes.