This is an archive of the discontinued LLVM Phabricator instance.

[XRay] fix more -Wformat warnings
ClosedPublic

Authored by dim on Nov 23 2021, 12:36 PM.

Details

Summary

Building xray with recent clang on a 64-bit system results in a number
of -Wformat warnings:

compiler-rt/lib/xray/xray_allocator.h:70:11: warning: format specifies type 'int' but the argument has type '__sanitizer::uptr' (aka 'unsigned long') [-Wformat]
          RoundedSize, B);
          ^~~~~~~~~~~
compiler-rt/lib/xray/xray_allocator.h:119:11: warning: format specifies type 'int' but the argument has type '__sanitizer::uptr' (aka 'unsigned long') [-Wformat]
          RoundedSize, B);
          ^~~~~~~~~~~

Since __sanitizer::uptr has the same size as size_t, these can be
fixed by using the printf specifier %zu.

compiler-rt/lib/xray/xray_basic_logging.cpp:348:46: warning: format specifies type 'int' but the argument has type '__sanitizer::tid_t' (aka 'unsigned long long') [-Wformat]
      Report("Cleaned up log for TID: %d\n", GetTid());
                                      ~~     ^~~~~~~~
                                      %llu
compiler-rt/lib/xray/xray_basic_logging.cpp:353:62: warning: format specifies type 'int' but the argument has type '__sanitizer::tid_t' (aka 'unsigned long long') [-Wformat]
      Report("Skipping buffer for TID: %d; Offset = %llu\n", GetTid(),
                                       ~~                    ^~~~~~~~
                                       %llu

Since __sanitizer::tid_t is effectively declared as `unsigned long
long`, these can be fixed by using the printf specifier %llu.

compiler-rt/lib/xray/xray_basic_logging.cpp:354:14: warning: format specifies type 'unsigned long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
             TLD.BufferOffset);
             ^~~~~~~~~~~~~~~~

Since BufferOffset is declared as size_t, this one can be fixed by
using %zu as a printf specifier.

compiler-rt/lib/xray/xray_interface.cpp:172:50: warning: format specifies type 'int' but the argument has type 'uint64_t' (aka 'unsigned long') [-Wformat]
    Report("Unsupported sled kind '%d' @%04x\n", Sled.Address, int(Sled.Kind));
                                   ~~            ^~~~~~~~~~~~
                                   %lu

Since `xray::SledEntry::Address is declared as uint64_t, this one
can be fixed by using PRIu64, and adding <cinttypes>.

compiler-rt/lib/xray/xray_interface.cpp:308:62: warning: format specifies type 'long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
    Report("System page size is not a power of two: %lld\n", PageSize);
                                                    ~~~~     ^~~~~~~~
                                                    %zu
compiler-rt/lib/xray/xray_interface.cpp:359:64: warning: format specifies type 'long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
    Report("Provided page size is not a power of two: %lld\n", PageSize);
                                                      ~~~~     ^~~~~~~~
                                                      %zu

Since PageSize is declared as size_t, these can be fixed by using
%zu as a printf specifier.

Diff Detail

Event Timeline

dim created this revision.Nov 23 2021, 12:36 PM
dim requested review of this revision.Nov 23 2021, 12:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2021, 12:36 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
MaskRay added inline comments.
compiler-rt/lib/xray/xray_allocator.h
69
dim updated this revision to Diff 389292.Nov 23 2021, 1:02 PM

Drop trailing dots from report messages.

dim updated this revision to Diff 389295.Nov 23 2021, 1:03 PM

Squash commits because arc tricked me.

vitalybuka added inline comments.Dec 3 2021, 11:23 AM
compiler-rt/lib/xray/xray_interface.cpp
172–173

%llu

dim added inline comments.Dec 3 2021, 11:47 AM
compiler-rt/lib/xray/xray_interface.cpp
172–173

This can only be done by adding a cast, as Sled.Address is uint64_t. There's a cast here anyway, so maybe another one's OK?

vitalybuka accepted this revision.Dec 3 2021, 12:04 PM
vitalybuka added inline comments.
compiler-rt/lib/xray/xray_interface.cpp
172–173

I see.
PRIu64 is OK.

This revision is now accepted and ready to land.Dec 3 2021, 12:04 PM
This revision was automatically updated to reflect the committed changes.