Skip to content

enable -Wformat #378

Closed
Closed

Description

@nickdesaulniers

A previous attempt at re-enabling -Wformat showed that there were LOTS of instances of this warning throughout the codebase. Simply re-applying that patch and doing an arm64 defconfig, I experienced 236 unique instances of this warning. Similar to @kees ' work enabling -Wvla, I'd like to find and fix all of these, then re-send the patch re-enabling the warning.

Assuming these aren't false positives, I think the only tricky cases we may encounter may come from config dependent types. ex.

#ifdef CONFIG_FOO
int bar = 0;
#else 
float bar = 0;
#endif 
printk("bar: %d\n"); // warning: format specifies type 'int' but the argument has type 'float' [-Wformat]

which can be fixed via:

+prink("bar: "
+#ifdef CONFIG_FOO
+    "%d"
+#else
+    "%f"
+#endif
+    "\n");
-printk("bar: %d\n");

(or whatever maintainers prefer). I don't expect many of those cases, but maybe I'm mistaken.

Also (meta), usually we file individual issues, but maybe it's better to use this one lone issue to track all the instances? (not sure; open to thoughts).

Also, let's find a way to split the work? And keep each other cc'ed when sending patches? (we should probably set up a mailing list to always cc for patches related to Clang Built Linux)

Activity

  1. added
    enhancementNew feature or request
    [BUG] linuxA bug that should be fixed in the mainline kernel.
    low priorityThis bug is not critical and not a priority
    on Feb 25, 2019
  2. nathanchance commented on Feb 25, 2019

    @nathanchance
    Member

    Also (meta), usually we file individual issues, but maybe it's better to use this one lone issue to track all the instances? (not sure; open to thoughts).

    Given that some warnings might be easier fixed/received than others, it is still probably better to file individual issues and use the -Wformat label to link them all. We can either file issues as we deal with them or just take the list that I made above and file issues for all of them. I'd find the former easier to manage.

    we should probably set up a mailing list to always cc for patches related to Clang Built Linux

    I've been thinking this for a bit. I usually CC you but I am sure there are others who would like to be kept in the loop as well.

  3. nickdesaulniers commented on Feb 25, 2019

    @nickdesaulniers
    MemberAuthor
  4. nathanchance commented on Feb 25, 2019

    @nathanchance
    Member

    So the email we'd CC is clang-built-linux@googlegroups.com?

  5. nickdesaulniers commented on Feb 25, 2019

    @nickdesaulniers
    MemberAuthor

    it would be nice to get something on http://vger.kernel.org/vger-lists.html. I bet @arndb knows who to talk to about that.

  6. nathanchance commented on Feb 25, 2019

    @nathanchance
    Member
  7. arndb commented on Feb 26, 2019

    @arndb
  8. kragniz commented on Feb 26, 2019

    @kragniz
    Member

    I submitted a patch, tell me if I did something wrong: https://lore.kernel.org/r/20190226234853.20441-1-louis@kragniz.eu/

  9. jon-flatley commented on Feb 27, 2019

    @jon-flatley

    It looks good to me. In the future could you CC Nick and I on the patches? That will help us stay organized and will let us add a quick Reviewed-by if a patch needs some traction.

  10. 184 remaining items

  11. nhukc commented on Jun 8, 2020

    @nhukc

    The warnings leftover look valid to me. They all truncate before printing which seems like unintended behavior. From here https://lore.kernel.org/r/CAHk-=wgoxnmsj8GEVFJSvTwdnWm8wVJthefNk2n6+4TC=20e0Q@mail.gmail.com/ it looks like Linus thinks that using "hh" specifiers on an int is bad style.

    I filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95588

  12. nickdesaulniers commented on Nov 10, 2020

    @nickdesaulniers
    MemberAuthor

    Discussion on the list is that we should do a treewide removal of %h and %hh format modifiers for print like functions.
    https://lore.kernel.org/lkml/CAKwvOdku3o0nHhPppPOJzFXa3j1j_4r5ix3kbkduxY3YSpj9wg@mail.gmail.com/T/#m9795462050a04e8401a0ff4176760d189067316e

    See also commit cbacb5a ("docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]").

  13. nickdesaulniers commented on Dec 2, 2020

    @nickdesaulniers
    MemberAuthor

    Documentation in the kernel has been updated to reflect %h and %hh is frowned upon: https://lore.kernel.org/lkml/a68114afb134b8633905f5a25ae7c4e6799ce8f1.camel@perches.com/

    Next up is separate efforts to add a warning to checkpatch.pl, and possibly leverage clang-tidy to help automate the removal of these format flags.

  14. nickdesaulniers commented on Apr 22, 2021

    @nickdesaulniers
    MemberAuthor

    If I remove KBUILD_CFLAGS += -Wno-format from scripts/Makefile.extrawarn, I can repro, though for x86_64 defconfig, there's only 2 cases (net/ipv6/ah6.c:710, net/ipv6/esp6.c:1153)! But there are a lot more for ARCH=arm64 defconfig.

  15. nickdesaulniers commented on Jun 17, 2022

    @nickdesaulniers
    MemberAuthor

    https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?h=mm-nonmm-unstable&id=d30dfd490f7dc4cb6a7c11a647bd1ff7a22139e7 (accepted) will help with a bunch of calls to ntohs being passed to printk-like functions.

  16. nathanchance commented on Aug 10, 2022

    @nathanchance
    Member
  17. nickdesaulniers commented on Aug 11, 2022

    @nickdesaulniers
    MemberAuthor

    Reverted by Linus: https://git.kernel.org/linus/21f9c8a13bb2a0c24d9c6b86bc0896542a28c197

    Update: Shorten link (dileks)

  18. nickdesaulniers commented on Aug 19, 2022

    @nickdesaulniers
    MemberAuthor

    llvm/llvm-project#57102 is the upstream report.

    I've also posted https://reviews.llvm.org/D132266 to discuss feasibility of moving these to -Wformat-pedantic.

    Should that be accepted, I would first send https://lore.kernel.org/linux-kbuild/20220716084532.2324050-1-youngmin.nam@samsung.com/ in a series that then wrapped that in an if clang version >= 16 check re-enabling -Wformat else at least enable -Wformat-insufficient-args.

  19. nathanchance commented on Aug 19, 2022

    @nathanchance
    Member

    Should that be accepted, I would first send https://lore.kernel.org/linux-kbuild/20220716084532.2324050-1-youngmin.nam@samsung.com/ in a series that then wrapped that in an if clang version >= 16 check re-enabling -Wformat else at least enable -Wformat-insufficient-args.

    Ah, that is a decent workaround. It might be interesting to see if we could enable all the other sub warnings of -Wformat.

  20. nickdesaulniers commented on Aug 24, 2022

    @nickdesaulniers
    MemberAuthor

    https://reviews.llvm.org/D132568 is probably a better fix.

    @nathanchance had question regarding which flags were in the -Wformat group.

    https://github.com/llvm/llvm-project/blob/cff5bef948c91e4919de8a5fb9765e0edc13f3de/clang/include/clang/Basic/DiagnosticGroups.td#L934-L938 is the definition of the group. Also, https://clang.llvm.org/docs/DiagnosticsReference.html#wformat which is generated from that source mentions:

    Also controls -Wformat-extra-args, -Wformat-insufficient-args, -Wformat-invalid-specifier, -Wformat-security, -Wformat-y2k, -Wformat-zero-length, -Wnonnull.

    The kernel already explicitly disables -Wformat-security, so that shouldn't be re-enabled. https://clang.llvm.org/docs/DiagnosticsReference.html#wformat-y2k says that -Wformat-y2k does nothing in clang.

  21. inclyc commented on Sep 1, 2022

    @inclyc
    Member
  22. nickdesaulniers commented on Sep 1, 2022

    @nickdesaulniers
    MemberAuthor

    Thanks @inclyc !

    I'm working on a kernel patch for this. Looks like -Wformat-insufficient-args is clang-12+...

  23. nickdesaulniers commented on Sep 1, 2022

    @nickdesaulniers
    MemberAuthor
  24. nathanchance commented on Sep 4, 2022

    @nathanchance
    Member
  25. bwendling commented on Oct 11, 2022

    @bwendling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

-WformatReported upstreamThis bug was filed on LLVM’s issue tracker, Phabricator, or the kernel mailing list.[BUG] linuxA bug that should be fixed in the mainline kernel.[FIXED][LINUX] 6.0This bug was fixed in Linux 6.0enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions