This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add getUnsignedPointerDiffType method
ClosedPublic

Authored by alexander-shaposhnikov on Sep 25 2017, 7:49 PM.

Details

Summary

C11 standard refers to the unsigned counterpart of the type ptrdiff_t
in the paragraph 7.21.6.1p7 where it defines the format specifier %tu.
In Clang (in PrintfFormatString.cpp, lines 508-510) there is a FIXME for this case,
in particular, right now Clang doesn't diagnose %tu issues at all, i.e.
it doesn't emit any warnings on the code printf("%tu", 3.14).
In this diff we add a method getUnsignedPointerDiffType for getting the corresponding type
similarly to how it's already done in the other analogous cases (size_t, ssize_t, ptrdiff_t etc)
and fix -Wformat diagnostics for %tu plus the emitted fix-it as well.

Diff Detail

Repository
rL LLVM

Event Timeline

alexander-shaposhnikov edited the summary of this revision. (Show Details)
alexander-shaposhnikov edited the summary of this revision. (Show Details)Sep 25 2017, 7:52 PM

The code for printf diagnostics + new tests are supposed to be added by a separate diff.

I think you should combine that diff and this one into a single patch, otherwise this patch is untestable.

include/clang/AST/ASTContext.h
1492–1493 ↗(On Diff #116635)

Wrap the comment, and you might want to refer to C11 7.21.6.1p7 as a justification for why this is needed.

Address the comments

alexander-shaposhnikov edited the summary of this revision. (Show Details)Sep 27 2017, 3:43 PM
alexander-shaposhnikov edited the summary of this revision. (Show Details)
alexander-shaposhnikov edited the summary of this revision. (Show Details)
aaron.ballman added inline comments.Sep 28 2017, 12:51 PM
test/FixIt/format.m
256 ↗(On Diff #116894)

Can you add some positive tests that show "%t" and "%tu" working properly without warnings?

This revision is now accepted and ready to land.Sep 28 2017, 3:25 PM
This revision was automatically updated to reflect the committed changes.