[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t literals be typedefs instead of built-in types (PR #143653)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 11 00:14:19 PDT 2025
================
@@ -320,6 +321,69 @@ bool clang::analyze_format_string::ParseUTF8InvalidSpecifier(
// Methods on ArgType.
//===----------------------------------------------------------------------===//
+static bool namedTypeToLengthModifierKind(QualType QT,
+ LengthModifier::Kind &K) {
+ for (/**/; const auto *TT = QT->getAs<TypedefType>();
+ QT = TT->getDecl()->getUnderlyingType()) {
+ StringRef Name = TT->getDecl()->getIdentifier()->getName();
+ if (Name == "size_t" || Name == "__size_t") {
+ K = LengthModifier::AsSizeT;
+ return true;
+ } else if (Name == "__signed_size_t" ||
+ Name == "ssize_t" /*Not C99, but common in Unix.*/) {
+ K = LengthModifier::AsSizeT;
+ return true;
+ } else if (Name == "ptrdiff_t" || Name == "__ptrdiff_t") {
+ K = LengthModifier::AsPtrDiff;
+ return true;
+ } else if (Name == "intmax_t") {
+ K = LengthModifier::AsIntMax;
+ return true;
+ } else if (Name == "uintmax_t") {
+ K = LengthModifier::AsIntMax;
+ return true;
+ }
+ }
+ return false;
----------------
YexuanXiao wrote:
It needs to handle cases where the actual `size_t` is used, so comparing strings is necessary. I just optimized the old code and moved it to this location to reuse it.
https://github.com/llvm/llvm-project/pull/143653
More information about the cfe-commits
mailing list