https://github.com/YexuanXiao created 
https://github.com/llvm/llvm-project/pull/202209

Fix #192268.

>From ea93f709c85fa72b6aef42e5c07a8110b76712e0 Mon Sep 17 00:00:00 2001
From: Yexuan Xiao <[email protected]>
Date: Sun, 7 Jun 2026 23:10:47 +0800
Subject: [PATCH] [clang] Fix PredefinedSugarType reported as CXType_Unexposed

---
 clang/docs/ReleaseNotes.rst                      |  3 +++
 clang/include/clang-c/Index.h                    |  4 +++-
 clang/test/Index/print-type-predefined-sugar.cpp | 12 ++++++++++++
 clang/tools/libclang/CXType.cpp                  |  2 ++
 4 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Index/print-type-predefined-sugar.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f97e90634396a..d565f78f8d911 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -915,6 +915,9 @@ libclang
 - Fix crash in clang_getBinaryOperatorKindSpelling and 
clang_getUnaryOperatorKindSpelling
 - The clang_Module_getASTFile API is deprecated and now always returns nullptr
 - The clang_Cursor_getCommentRange API will now return a comment range for 
macro definitions that have documentation comments.
+- Added CXType_PredefinedSugar for __ptrdiff_t, __size_t, and
+  __signed_size_t types, which are no longer exposed as
+  CXType_Unexposed.
 
 Code Completion
 ---------------
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 119bd68ff9814..8427236e0b444 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3043,7 +3043,9 @@ enum CXTypeKind {
   /* HLSL Types */
   CXType_HLSLResource = 179,
   CXType_HLSLAttributedResource = 180,
-  CXType_HLSLInlineSpirv = 181
+  CXType_HLSLInlineSpirv = 181,
+
+  CXType_PredefinedSugar = 182
 };
 
 /**
diff --git a/clang/test/Index/print-type-predefined-sugar.cpp 
b/clang/test/Index/print-type-predefined-sugar.cpp
new file mode 100644
index 0000000000000..6394186e14b9d
--- /dev/null
+++ b/clang/test/Index/print-type-predefined-sugar.cpp
@@ -0,0 +1,12 @@
+// RUN: c-index-test -test-print-type %s -target x86_64-pc-linux-gnu 
-std=c++23 | FileCheck %s
+
+typedef struct { void **unused; } S;
+void test(S *x, S *y) {
+  (void)(x - y);
+  (void)sizeof(*x);
+  (void)0z;
+}
+
+// CHECK: BinaryOperator=- [type=__ptrdiff_t] [typekind=PredefinedSugar] 
[canonicaltype=long] [canonicaltypekind=Long] [isPOD=1]
+// CHECK: UnaryExpr= [type=__size_t] [typekind=PredefinedSugar] 
[canonicaltype=unsigned long] [canonicaltypekind=ULong] [isPOD=1]
+// CHECK: IntegerLiteral= [type=__signed_size_t] [typekind=PredefinedSugar] 
[canonicaltype=long] [canonicaltypekind=Long] [isPOD=1]
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index 3feb56334d79c..0063939dec423 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -122,6 +122,7 @@ static CXTypeKind GetTypeKind(QualType T) {
     TKCASE(Attributed);
     TKCASE(BTFTagAttributed);
     TKCASE(Atomic);
+    TKCASE(PredefinedSugar);
     default:
       return CXType_Unexposed;
   }
@@ -651,6 +652,7 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
     TKIND(BTFTagAttributed);
     TKIND(HLSLAttributedResource);
     TKIND(HLSLInlineSpirv);
+    TKIND(PredefinedSugar);
     TKIND(BFloat16);
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
 #include "clang/Basic/OpenCLImageTypes.def"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to