================ @@ -6726,17 +6726,67 @@ QualType ASTContext::getTagDeclType(const TagDecl *Decl) const { return getTypeDeclType(const_cast<TagDecl*>(Decl)); } +// Inject __size_t, __signed_size_t, and __ptrdiff_t to provide portable hints +// and diagnostics. In C and C++, expressions of type size_t can be obtained via +// the sizeof operator, expressions of type ptrdiff_t via pointer subtraction, +// and expressions of type signed size_t via the z literal suffix (since C++23). +// However, no core language mechanism directly produces an expression of type +// unsigned ptrdiff_t. The unsigned ptrdiff_t type is solely required by format +// specifiers for printf and scanf. Consequently, no expression's type needs to +// be displayed as unsigned ptrdiff_t. Verification of whether a type is +// unsigned ptrdiff_t is also unnecessary, as no corresponding typedefs exist. +// Therefore, injecting a typedef for signed ptrdiff_t is not required. + /// getSizeType - Return the unique type for "size_t" (C99 7.17), the result /// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and /// needs to agree with the definition in <stddef.h>. -CanQualType ASTContext::getSizeType() const { +QualType ASTContext::getSizeType() const { + if (SizeType.isNull()) { + if (auto const &LO = getLangOpts(); !LO.HLSL && (LO.C99 || LO.CPlusPlus)) ---------------- YexuanXiao wrote:
I didn't find C89 in [LangOptions](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/LangOptions.def#L84-L91), perhaps this is Clang's design. Please let me know if it exists. https://github.com/llvm/llvm-project/pull/143653 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits