CanQualType for ssize_t

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

CanQualType for ssize_t

Boris Kolpackov via cfe-dev
Hi, 
I have a question regarding the right way to get CanQualType/QualType for "ssize_t".

has a number of methods: getIntMaxType, getUintMaxType, getSizeType etc but if i am not mistaken it doesn't have the counterpart for "ssize_t". 
After looking at the implementation of those methods i see that it's missing in the class TargetInfo either. https://clang.llvm.org/doxygen/include_2clang_2Basic_2TargetInfo_8h_source.html#l00228 .

Some context:

in PrintfSpecifier::getArgType (in ./lib/Analysis/PrintfFormatString.cpp)
there is a FIXME:

     case LengthModifier::AsSizeT:
         return ArgType(); // FIXME: ssize_t

as a result Clang doesn't analyze the format string "%zd" correctly
and doesn't warn on the following (broken) code:

    int main() {
      printf("%zd", 12.2);
      return 0;
    }

Kind regards, 
Alexander Shaposhnikov

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: CanQualType for ssize_t

Boris Kolpackov via cfe-dev


On Tue, Jul 11, 2017 at 5:19 PM, Alexander Shaposhnikov <[hidden email]> wrote:
Hi, 
I have a question regarding the right way to get CanQualType/QualType for "ssize_t".

has a number of methods: getIntMaxType, getUintMaxType, getSizeType etc but if i am not mistaken it doesn't have the counterpart for "ssize_t". 
After looking at the implementation of those methods i see that it's missing in the class TargetInfo either. https://clang.llvm.org/doxygen/include_2clang_2Basic_2TargetInfo_8h_source.html#l00228 .

Some context:

in PrintfSpecifier::getArgType (in ./lib/Analysis/PrintfFormatString.cpp)
there is a FIXME:

     case LengthModifier::AsSizeT:
         return ArgType(); // FIXME: ssize_t

as a result Clang doesn't analyze the format string "%zd" correctly
and doesn't warn on the following (broken) code:

    int main() {
      printf("%zd", 12.2);
      return 0;
    }

Kind regards, 
Alexander Shaposhnikov


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: CanQualType for ssize_t

Boris Kolpackov via cfe-dev
The C11 standard has the following paragraph for 'z':

Specifies that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies to a pointer to a signed integer type corresponding to size_t argument.

If I interpret it correctly (please correct me if I'm wrong) then this means that for '%zd' you can use a type that identical to the target's SizeType, except that it has to be signed.

Alex

On 12 July 2017 at 03:01, Александр Шапошников <[hidden email]> wrote:


On Tue, Jul 11, 2017 at 5:19 PM, Alexander Shaposhnikov <[hidden email]> wrote:
Hi, 
I have a question regarding the right way to get CanQualType/QualType for "ssize_t".

has a number of methods: getIntMaxType, getUintMaxType, getSizeType etc but if i am not mistaken it doesn't have the counterpart for "ssize_t". 
After looking at the implementation of those methods i see that it's missing in the class TargetInfo either. https://clang.llvm.org/doxygen/include_2clang_2Basic_2TargetInfo_8h_source.html#l00228 .

Some context:

in PrintfSpecifier::getArgType (in ./lib/Analysis/PrintfFormatString.cpp)
there is a FIXME:

     case LengthModifier::AsSizeT:
         return ArgType(); // FIXME: ssize_t

as a result Clang doesn't analyze the format string "%zd" correctly
and doesn't warn on the following (broken) code:

    int main() {
      printf("%zd", 12.2);
      return 0;
    }

Kind regards, 
Alexander Shaposhnikov



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: CanQualType for ssize_t

Boris Kolpackov via cfe-dev
Yeah, I think you are right,
my question was mostly about if it's on purpose that  TargetInfo and ASTContext don't expose this information (like they do for size_t).
I mean that there is getSizeType method, but there isn't getSignedSizeType and I'm wondering if it's expected. 
If it's not on purpose  - what would people say to adding it ? or what we should use instead.
Many thanks for the reply,
Kind regards,
Alexander Shaposhnikov



On Wed, Jul 12, 2017 at 4:10 AM, Alex L <[hidden email]> wrote:
The C11 standard has the following paragraph for 'z':

Specifies that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies to a pointer to a signed integer type corresponding to size_t argument.

If I interpret it correctly (please correct me if I'm wrong) then this means that for '%zd' you can use a type that identical to the target's SizeType, except that it has to be signed.

Alex

On 12 July 2017 at 03:01, Александр Шапошников <[hidden email]> wrote:


On Tue, Jul 11, 2017 at 5:19 PM, Alexander Shaposhnikov <[hidden email]> wrote:
Hi, 
I have a question regarding the right way to get CanQualType/QualType for "ssize_t".

has a number of methods: getIntMaxType, getUintMaxType, getSizeType etc but if i am not mistaken it doesn't have the counterpart for "ssize_t". 
After looking at the implementation of those methods i see that it's missing in the class TargetInfo either. https://clang.llvm.org/doxygen/include_2clang_2Basic_2TargetInfo_8h_source.html#l00228 .

Some context:

in PrintfSpecifier::getArgType (in ./lib/Analysis/PrintfFormatString.cpp)
there is a FIXME:

     case LengthModifier::AsSizeT:
         return ArgType(); // FIXME: ssize_t

as a result Clang doesn't analyze the format string "%zd" correctly
and doesn't warn on the following (broken) code:

    int main() {
      printf("%zd", 12.2);
      return 0;
    }

Kind regards, 
Alexander Shaposhnikov




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: CanQualType for ssize_t

Boris Kolpackov via cfe-dev


On 12 July 2017 at 21:00, Alexander Shaposhnikov <[hidden email]> wrote:
Yeah, I think you are right,
my question was mostly about if it's on purpose that  TargetInfo and ASTContext don't expose this information (like they do for size_t). 
I mean that there is getSizeType method, but there isn't getSignedSizeType and I'm wondering if it's expected. 
If it's not on purpose  - what would people say to adding it ? or what we should use instead.
Many thanks for the reply,
Kind regards,
Alexander Shaposhnikov


I think that the standard says that we can just take the signed version of the SizeType. A method like this in TargetInfo should suffice then:

IntType getSignedSizeType() const {
  switch (SizeType) {
  case UnsignedLongLong: return SignedLongLong;
  ....
  }
}

Then you should be able to add an appropriate method to the ASTContext that returns a QualType that corresponds to this Target type.

In my opinion this is a reasonable solution to the problem,
Alex
 


On Wed, Jul 12, 2017 at 4:10 AM, Alex L <[hidden email]> wrote:
The C11 standard has the following paragraph for 'z':

Specifies that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies to a pointer to a signed integer type corresponding to size_t argument.

If I interpret it correctly (please correct me if I'm wrong) then this means that for '%zd' you can use a type that identical to the target's SizeType, except that it has to be signed.

Alex

On 12 July 2017 at 03:01, Александр Шапошников <[hidden email]> wrote:


On Tue, Jul 11, 2017 at 5:19 PM, Alexander Shaposhnikov <[hidden email]> wrote:
Hi, 
I have a question regarding the right way to get CanQualType/QualType for "ssize_t".

has a number of methods: getIntMaxType, getUintMaxType, getSizeType etc but if i am not mistaken it doesn't have the counterpart for "ssize_t". 
After looking at the implementation of those methods i see that it's missing in the class TargetInfo either. https://clang.llvm.org/doxygen/include_2clang_2Basic_2TargetInfo_8h_source.html#l00228 .

Some context:

in PrintfSpecifier::getArgType (in ./lib/Analysis/PrintfFormatString.cpp)
there is a FIXME:

     case LengthModifier::AsSizeT:
         return ArgType(); // FIXME: ssize_t

as a result Clang doesn't analyze the format string "%zd" correctly
and doesn't warn on the following (broken) code:

    int main() {
      printf("%zd", 12.2);
      return 0;
    }

Kind regards, 
Alexander Shaposhnikov





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: CanQualType for ssize_t

Boris Kolpackov via cfe-dev
Sounds good, thanks!
Kind regards,
Alexander Shaposhnikov

On Thu, Jul 13, 2017 at 2:38 AM, Alex L via cfe-dev <[hidden email]> wrote:


On 12 July 2017 at 21:00, Alexander Shaposhnikov <[hidden email]> wrote:
Yeah, I think you are right,
my question was mostly about if it's on purpose that  TargetInfo and ASTContext don't expose this information (like they do for size_t). 
I mean that there is getSizeType method, but there isn't getSignedSizeType and I'm wondering if it's expected. 
If it's not on purpose  - what would people say to adding it ? or what we should use instead.
Many thanks for the reply,
Kind regards,
Alexander Shaposhnikov


I think that the standard says that we can just take the signed version of the SizeType. A method like this in TargetInfo should suffice then:

IntType getSignedSizeType() const {
  switch (SizeType) {
  case UnsignedLongLong: return SignedLongLong;
  ....
  }
}

Then you should be able to add an appropriate method to the ASTContext that returns a QualType that corresponds to this Target type.

In my opinion this is a reasonable solution to the problem,
Alex
 


On Wed, Jul 12, 2017 at 4:10 AM, Alex L <[hidden email]> wrote:
The C11 standard has the following paragraph for 'z':

Specifies that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies to a pointer to a signed integer type corresponding to size_t argument.

If I interpret it correctly (please correct me if I'm wrong) then this means that for '%zd' you can use a type that identical to the target's SizeType, except that it has to be signed.

Alex

On 12 July 2017 at 03:01, Александр Шапошников <[hidden email]> wrote:


On Tue, Jul 11, 2017 at 5:19 PM, Alexander Shaposhnikov <[hidden email]> wrote:
Hi, 
I have a question regarding the right way to get CanQualType/QualType for "ssize_t".

has a number of methods: getIntMaxType, getUintMaxType, getSizeType etc but if i am not mistaken it doesn't have the counterpart for "ssize_t". 
After looking at the implementation of those methods i see that it's missing in the class TargetInfo either. https://clang.llvm.org/doxygen/include_2clang_2Basic_2TargetInfo_8h_source.html#l00228 .

Some context:

in PrintfSpecifier::getArgType (in ./lib/Analysis/PrintfFormatString.cpp)
there is a FIXME:

     case LengthModifier::AsSizeT:
         return ArgType(); // FIXME: ssize_t

as a result Clang doesn't analyze the format string "%zd" correctly
and doesn't warn on the following (broken) code:

    int main() {
      printf("%zd", 12.2);
      return 0;
    }

Kind regards, 
Alexander Shaposhnikov





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev