Skip to content

Commit

Permalink
[clang] Add getSignedSizeType method
Browse files Browse the repository at this point in the history
C11 standard refers to the signed counterpart of the type size_t in
the paragraph 7.21.6.1 where it defines d, i, o, u, x, or x conversion specifiers
(in printf format string).
In Clang there is a FIXME (in lib/Analysis/PrintfFormatString.cpp) for this case
(which is not handled correctly at the moment).
This diff adds getSignedSizeType method to TargetInfo and exposes it 
in ASTContext similarly to how it is done for getSizeType.
lib/Analysis/PrintfFormatString.cpp will be changed in a separate commit.

Differential revision: https://reviews.llvm.org/D35378

Test plan: make check-all

llvm-svn: 308037
  • Loading branch information
alexander-shaposhnikov committed Jul 14, 2017
1 parent e1c4655 commit 1e898d9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/include/clang/AST/ASTContext.h
Expand Up @@ -1441,6 +1441,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// The sizeof operator requires this (C99 6.5.3.4p4).
CanQualType getSizeType() const;

/// \brief Return the unique signed counterpart of
/// the integer type corresponding to size_t.
CanQualType getSignedSizeType() const;

/// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
/// <stdint.h>.
CanQualType getIntMaxType() const;
Expand Down
14 changes: 14 additions & 0 deletions clang/include/clang/Basic/TargetInfo.h
Expand Up @@ -226,6 +226,20 @@ class TargetInfo : public RefCountedBase<TargetInfo> {

public:
IntType getSizeType() const { return SizeType; }
IntType getSignedSizeType() const {
switch (SizeType) {
case UnsignedShort:
return SignedShort;
case UnsignedInt:
return SignedInt;
case UnsignedLong:
return SignedLong;
case UnsignedLongLong:
return SignedLongLong;
default:
llvm_unreachable("Invalid SizeType");
}
}
IntType getIntMaxType() const { return IntMaxType; }
IntType getUIntMaxType() const {
return getCorrespondingUnsignedType(IntMaxType);
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/AST/ASTContext.cpp
Expand Up @@ -4525,6 +4525,12 @@ CanQualType ASTContext::getSizeType() const {
return getFromTargetType(Target->getSizeType());
}

/// Return the unique signed counterpart of the integer type
/// corresponding to size_t.
CanQualType ASTContext::getSignedSizeType() const {
return getFromTargetType(Target->getSignedSizeType());
}

/// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5).
CanQualType ASTContext::getIntMaxType() const {
return getFromTargetType(Target->getIntMaxType());
Expand Down

0 comments on commit 1e898d9

Please sign in to comment.