This is an archive of the discontinued LLVM Phabricator instance.

sanitizer_common: fix format strings
ClosedPublic

Authored by dvyukov on Aug 12 2021, 11:19 AM.

Details

Summary

Fix existing -Wformat warnings.

Depends on D107979.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Aug 12 2021, 11:19 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2021, 11:19 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka accepted this revision.Aug 12 2021, 12:46 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_libignore.cpp
108

It would be nice if we have consistency with pointers. As is we mix %p and 0x%zx but the produce different output.
Unfortunately we already have a lot of both.

compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
17

clang-tidy: error: 'algorithm' file not found [clang-diagnostic-error] ?

This revision is now accepted and ready to land.Aug 12 2021, 12:46 PM
dvyukov updated this revision to Diff 366190.Aug 12 2021, 10:40 PM

fix parent revision

dvyukov added inline comments.Aug 12 2021, 10:55 PM
compiler-rt/lib/sanitizer_common/sanitizer_libignore.cpp
108

Agree. It would be nice if we could teach compilers that uptr for '%p' is fine. But I did not find any ways to affect this checking.
Overall I tried to preserve %p in user reports, but for internal/debug output I just fixed the format strings (reinterpret_cast<void*> is too verbose).

compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
17

I don't know what to do with this. I've seen a number of similar warnings in test files (in all test files?). I think there is some issue in clang-tidy setup for tests. But I don't know how to fix and it's at least unrelated to this change.

This revision was landed with ongoing or failed builds.Aug 13 2021, 4:44 AM
This revision was automatically updated to reflect the committed changes.
quinnp added a subscriber: quinnp.EditedAug 13 2021, 3:30 PM

Hi, I think this patch broke some PowerPC bots.
For example:

Hi, I think this patch broke some PowerPC bots.
For example:

I've sent https://reviews.llvm.org/D108066 to fix this.
Turns out we don't have %l, that was somewhat surprising (no way to properly print longs).
Thanks for the report

bjope added a subscriber: bjope.Aug 14 2021, 8:40 AM

I'm seeing build failures like this in downstream builders:

bin/clang++ --target=i386-unknown-linux-gnu  -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/repo/llvm/compiler-rt/lib/gwp_asan/.. -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Werror -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-format-pedantic -nostdinc++ -fno-rtti -fno-exceptions -nostdinc++ -pthread -fno-omit-frame-pointer -fPIC -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-format-pedantic -nostdinc++ -UNDEBUG -MD -MT compiler-rt/lib/gwp_asan/CMakeFiles/RTGwpAsanBacktraceSanitizerCommon.i386.dir/optional/backtrace_sanitizer_common.cpp.o -MF compiler-rt/lib/gwp_asan/CMakeFiles/RTGwpAsanBacktraceSanitizerCommon.i386.dir/optional/backtrace_sanitizer_common.cpp.o.d -o compiler-rt/lib/gwp_asan/CMakeFiles/RTGwpAsanBacktraceSanitizerCommon.i386.dir/optional/backtrace_sanitizer_common.cpp.o -c /repo/llvm/compiler-rt/lib/gwp_asan/optional/backtrace_sanitizer_common.cpp
In file included from /repo/llvm/compiler-rt/lib/gwp_asan/optional/backtrace_sanitizer_common.cpp:17:
/repo/llvm/compiler-rt/lib/gwp_asan/../sanitizer_common/sanitizer_flag_parser.h:141:76: error: format specifies type 'size_t' (aka 'unsigned int') but the argument has type 'unsigned long' [-Werror,-Wformat]
  uptr num_symbols_should_write = internal_snprintf(buffer, size, "0x%zx", *t_);
                                                                     ~~~   ^~~
                                                                     %lx
1 error generated.

Hi Bjorn,
I've mailed D108105 which should fix all 32-bit warnings.
Thanks for reporting.

Hi Bjorn,
I've mailed D108105 which should fix all 32-bit warnings.
Thanks for reporting.

I've noticed that the problem resolved itself later. I think that maybe this patch fixed it: https://reviews.llvm.org/rG45138f788c9b3c4ac5d9ae4479841c411c15190e

Hi Bjorn,
I've mailed D108105 which should fix all 32-bit warnings.
Thanks for reporting.

I've noticed that the problem resolved itself later. I think that maybe this patch fixed it: https://reviews.llvm.org/rG45138f788c9b3c4ac5d9ae4479841c411c15190e

Ah, right, it should fix it as well. Did not notice it.