[clang] Using type deduction to define __SIZE_TYPE__ and __PTRDIFF_TYPE__ (PR #155979)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 8 06:34:31 PDT 2025


================
@@ -1175,13 +1175,15 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   Builder.defineMacro("__UINTMAX_C_SUFFIX__", ConstSuffix);
   Builder.defineMacro("__UINTMAX_C(c)",
                       ConstSuffix.size() ? Twine("c##") + ConstSuffix : "c");
-  DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(LangAS::Default), Builder);
-  DefineFmt(LangOpts, "__PTRDIFF", TI.getPtrDiffType(LangAS::Default), TI,
-            Builder);
   DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
   DefineFmt(LangOpts, "__INTPTR", TI.getIntPtrType(), TI, Builder);
-  DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
+  // Use deduction to obtain the built-in __size_t and __ptrdiff_t types instead
+  // of standard integer types
+  Builder.defineMacro("__SIZE_TYPE__", "__typeof(sizeof(0))");
----------------
erichkeane wrote:

I don't have a good hold on whether this is a good idea or not.  We should probably have an RFC for this.

https://github.com/llvm/llvm-project/pull/155979


More information about the cfe-commits mailing list