[Lldb-commits] [clang] [lldb] [HLSL] Intangible AST type (PR #97362)

Helena Kotas via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 1 16:17:09 PDT 2024


https://github.com/hekota created https://github.com/llvm/llvm-project/pull/97362

llvm/llvm-project#90631



>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/4] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h                       |  4 +++-
 clang/include/clang/AST/ASTContext.h                |  1 +
 clang/include/clang/AST/BuiltinTypes.def            |  3 +++
 clang/include/clang/AST/Type.h                      | 12 ++++++++++++
 clang/include/clang/Serialization/ASTBitCodes.h     |  5 ++++-
 clang/lib/AST/ASTContext.cpp                        |  8 ++++++++
 clang/lib/AST/ExprConstant.cpp                      |  1 +
 clang/lib/AST/ItaniumMangle.cpp                     |  4 ++++
 clang/lib/AST/MicrosoftMangle.cpp                   |  5 +++++
 clang/lib/AST/NSAPI.cpp                             |  1 +
 clang/lib/AST/Type.cpp                              |  3 +++
 clang/lib/AST/TypeLoc.cpp                           |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp                   |  5 +++++
 clang/lib/CodeGen/CGDebugInfo.h                     |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp                 | 13 +++++++++++++
 clang/lib/CodeGen/CGHLSLRuntime.h                   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp                  |  4 ++++
 clang/lib/CodeGen/ItaniumCXXABI.cpp                 |  1 +
 clang/lib/Index/USRGeneration.cpp                   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp               |  3 +++
 clang/lib/Serialization/ASTReader.cpp               |  3 +++
 clang/tools/libclang/CIndex.cpp                     |  1 +
 clang/tools/libclang/CXType.cpp                     |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp    |  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   bool isBitIntType() const;                    // Bit-precise integer type
   bool isOpenCLSpecificType() const;            // Any OpenCL specific type
 
+  bool isHLSLResourceType() const;                // HLSL resource type
+  bool isHLSLSpecificType() const;              // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
          isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa<TemplateTypeParmType>(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 316350d779e90..807e80184781a 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1078,6 +1078,9 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
+  /// \brief The HLSL resource type
+  PREDEF_TYPE_HLSL_RESOURCE_ID = 75,
+
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)                   \
   PREDEF_TYPE_##Id##_ID,
@@ -1112,7 +1115,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 504;
+const unsigned NUM_PREDEF_TYPE_IDS = 505;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index fca200988fea1..f704295a4918d 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1358,6 +1358,8 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
+  InitBuiltinType(HLSLResourceTy, BuiltinType::HLSLResource);
+
   if (Target.hasAArch64SVETypes()) {
 #define SVE_TYPE(Name, Id, SingletonId) \
     InitBuiltinType(SingletonId, BuiltinType::Id);
@@ -2159,6 +2161,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
       Width = Target->getPointerWidth(AS);
       Align = Target->getPointerAlign(AS);
       break;
+    case BuiltinType::HLSLResource:
+      // TODO: What should we do here? Matching `void *` for now...
+      Width = 0;
+      Align = 8;
+      break;
     // The SVE types are effectively target-specific.  The length of an
     // SVE_VECTOR_TYPE is only known at runtime, but it is always a multiple
     // of 128 bits.  There is one predicate bit for each vector byte, so the
@@ -8210,6 +8217,7 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
     case BuiltinType::OCLSampler:
+    case BuiltinType::HLSLResource:
     case BuiltinType::Dependent:
 #define PPC_VECTOR_TYPE(Name, Id, Size) \
     case BuiltinType::Id:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 8124069cdf805..ffe4334e3d3cb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11845,6 +11845,7 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
     case BuiltinType::OCLClkEvent:
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
+    case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
     case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 2cac03ba163f9..4610e473bc846 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3374,6 +3374,10 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
     Out << type_name.size() << type_name; \
     break;
 #include "clang/Basic/OpenCLExtensionTypes.def"
+  case BuiltinType::HLSLResource:
+    // TODO: Do we need a mangling scheme here?
+    llvm_unreachable("mangling an HLSL handle type?");
+    break;
   // The SVE types are effectively target-specific.  The mangling scheme
   // is defined in the appendices to the Procedure Call Standard for the
   // Arm Architecture.
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index d87be5f2043a9..6482100e6b7bc 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2576,6 +2576,11 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
     break;
 #include "clang/Basic/OpenCLExtensionTypes.def"
 
+  case BuiltinType::HLSLResource:
+    // TODO: Do we need a mangling scheme here?
+    llvm_unreachable("mangling an HLSL handle type?");
+    break;
+
   case BuiltinType::NullPtr:
     Out << "$$T";
     break;
diff --git a/clang/lib/AST/NSAPI.cpp b/clang/lib/AST/NSAPI.cpp
index 48d1763125e6c..b6ce458632a7c 100644
--- a/clang/lib/AST/NSAPI.cpp
+++ b/clang/lib/AST/NSAPI.cpp
@@ -443,6 +443,7 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
   case BuiltinType::OCLReserveID:
+  case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 656b733a13b0e..3e4b8ce09c33c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3481,6 +3481,8 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
     return "queue_t";
   case OCLReserveID:
     return "reserve_id_t";
+  case HLSLResource:
+    return "<hlsl resource>";
   case IncompleteMatrixIdx:
     return "<incomplete matrix index type>";
   case ArraySection:
@@ -4772,6 +4774,7 @@ bool Type::canHaveNullability(bool ResultIfUnknown) const {
     case BuiltinType::OCLClkEvent:
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
+    case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
     case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index 33e6ccbadc12d..6cf9bbf98dddf 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -418,6 +418,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
   case BuiltinType::OCLReserveID:
+  case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index a072475ba7705..0dde1f6a9d606 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -744,6 +744,11 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
     return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
 #include "clang/Basic/OpenCLExtensionTypes.def"
 
+  case BuiltinType::HLSLResource:
+    // TODO: We probably need a valid name here, which means we'll also want to
+    // update `BuiltinType::getName`...
+    return getOrCreateStructPtrType("<hlsl resource>", HLSLResourceTy);
+
 #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
     {
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 2731c627d9dc3..cb366029beb80 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -81,6 +81,7 @@ class CGDebugInfo {
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
   llvm::DIType *Id##Ty = nullptr;
 #include "clang/Basic/OpenCLExtensionTypes.def"
+  llvm::DIType *HLSLResourceTy = nullptr;
 #define WASM_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 55ba21ae2ba69..10b4fb2c84f1b 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -15,6 +15,7 @@
 #include "CGHLSLRuntime.h"
 #include "CGDebugInfo.h"
 #include "CodeGenModule.h"
+#include "TargetInfo.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/IR/Metadata.h"
@@ -115,6 +116,18 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) {
 
 } // namespace
 
+llvm::Type *CGHLSLRuntime::convertHLSLSpecificType(const Type *T) {
+  assert(T->isHLSLSpecificType() && "Not an HLSL specific type!");
+
+  // Check if the target has a specific translation for this type first.
+  if (llvm::Type *TargetTy = CGM.getTargetCodeGenInfo().getHLSLType(CGM, T))
+    return TargetTy;
+
+  // TODO: What do we actually want to do generically here? OpenCL uses a
+  // pointer in a particular address space.
+  llvm_unreachable("Generic handling of HLSL types is not implemented yet");
+}
+
 llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 4036ce711bea1..0f5050ca11ae1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -111,6 +111,8 @@ class CGHLSLRuntime {
   CGHLSLRuntime(CodeGenModule &CGM) : CGM(CGM) {}
   virtual ~CGHLSLRuntime() {}
 
+  llvm::Type *convertHLSLSpecificType(const Type *T);
+
   void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
   void generateGlobalCtorDtorCalls();
 
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp
index d823c336e39bf..ce99017c3f424 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -13,6 +13,7 @@
 #include "CodeGenTypes.h"
 #include "CGCXXABI.h"
 #include "CGCall.h"
+#include "CGHLSLRuntime.h"
 #include "CGOpenCLRuntime.h"
 #include "CGRecordLayout.h"
 #include "TargetInfo.h"
@@ -443,6 +444,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
     case BuiltinType::OCLReserveID:
       ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
       break;
+    case BuiltinType::HLSLResource:
+      ResultType = CGM.getHLSLRuntime().convertHLSLSpecificType(Ty);
+      break;
     case BuiltinType::SveInt8:
     case BuiltinType::SveUint8:
     case BuiltinType::SveInt8x2:
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 01a735c1437e1..12f00d7c3776a 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3352,6 +3352,7 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
     case BuiltinType::OCLClkEvent:
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
+    case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
     case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 5036ddee35fd1..71c74e48cd55f 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -758,6 +758,8 @@ void USRGenerator::VisitType(QualType T) {
           Out << "@BT at OCLReserveID"; break;
         case BuiltinType::OCLSampler:
           Out << "@BT at OCLSampler"; break;
+        case BuiltinType::HLSLResource:
+          Out << "@BT at HLSLResource"; break;
 #define SVE_TYPE(Name, Id, SingletonId) \
         case BuiltinType::Id: \
           Out << "@BT@" << Name; break;
diff --git a/clang/lib/Serialization/ASTCommon.cpp b/clang/lib/Serialization/ASTCommon.cpp
index 3385cb8aad7e4..e223aaca3acd6 100644
--- a/clang/lib/Serialization/ASTCommon.cpp
+++ b/clang/lib/Serialization/ASTCommon.cpp
@@ -238,6 +238,9 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
   case BuiltinType::OCLReserveID:
     ID = PREDEF_TYPE_RESERVE_ID_ID;
     break;
+  case BuiltinType::HLSLResource:
+    ID = PREDEF_TYPE_HLSL_RESOURCE_ID;
+    break;
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id: \
     ID = PREDEF_TYPE_##Id##_ID; \
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 43013ab61474e..2438960e4d3bf 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7377,6 +7377,9 @@ QualType ASTReader::GetType(TypeID ID) {
     case PREDEF_TYPE_RESERVE_ID_ID:
       T = Context.OCLReserveIDTy;
       break;
+    case PREDEF_TYPE_HLSL_RESOURCE_ID:
+      T = Context.HLSLResourceTy;
+      break;
     case PREDEF_TYPE_AUTO_DEDUCT:
       T = Context.getAutoDeductType();
       break;
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 35312e3d2ae70..a349e45415f31 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -1635,6 +1635,7 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
   case BuiltinType::OCLReserveID:
+  case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
 #define PPC_VECTOR_TYPE(Name, Id, Size) case BuiltinType::Id:
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index 991767dc4c49c..df83918288d73 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -77,6 +77,7 @@ static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
     BTCASE(OCLEvent);
     BTCASE(OCLQueue);
     BTCASE(OCLReserveID);
+    BTCASE(HLSLResource);
   default:
     return CXType_Unexposed;
   }
@@ -628,6 +629,7 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
     TKIND(OCLEvent);
     TKIND(OCLQueue);
     TKIND(OCLReserveID);
+    TKIND(HLSLResource);
     TKIND(Atomic);
   }
 #undef TKIND
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index eb7f6232ac981..54bee28f72427 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4963,6 +4963,7 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
     case clang::BuiltinType::Kind::OCLQueue:
     case clang::BuiltinType::Kind::OCLReserveID:
     case clang::BuiltinType::Kind::OCLSampler:
+    case clang::BuiltinType::Kind::HLSLResource:
     case clang::BuiltinType::Kind::ArraySection:
     case clang::BuiltinType::Kind::OMPArrayShaping:
     case clang::BuiltinType::Kind::OMPIterator:
@@ -6088,6 +6089,7 @@ uint32_t TypeSystemClang::GetNumPointeeChildren(clang::QualType type) {
     case clang::BuiltinType::OCLImage3dWO:
     case clang::BuiltinType::OCLImage3dRW:
     case clang::BuiltinType::OCLSampler:
+    case clang::BuiltinType::HLSLResource:
       return 0;
     case clang::BuiltinType::Bool:
     case clang::BuiltinType::Char_U:

>From 3db38e63698203dd1d2bd5e702740b712ba73435 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Mon, 17 Jun 2024 16:07:28 -0600
Subject: [PATCH 2/4] wip: Name __builtin_hlsl_resource_t and give it a size
 for now

---
 clang/lib/AST/ASTContext.cpp      | 7 ++++---
 clang/lib/AST/ItaniumMangle.cpp   | 3 +--
 clang/lib/AST/MicrosoftMangle.cpp | 3 +--
 clang/lib/AST/Type.cpp            | 2 +-
 clang/lib/CodeGen/CGDebugInfo.cpp | 5 ++---
 clang/lib/Sema/Sema.cpp           | 3 +++
 6 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index f704295a4918d..286e30ffd6506 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2162,9 +2162,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
       Align = Target->getPointerAlign(AS);
       break;
     case BuiltinType::HLSLResource:
-      // TODO: What should we do here? Matching `void *` for now...
-      Width = 0;
-      Align = 8;
+      // TODO: We actually want this to have a size of zero, but for now we'll
+      // just treat it like a pointer to make progress.
+      Width = Target->getPointerWidth(LangAS::Default);
+      Align = Target->getPointerAlign(LangAS::Default);
       break;
     // The SVE types are effectively target-specific.  The length of an
     // SVE_VECTOR_TYPE is only known at runtime, but it is always a multiple
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 4610e473bc846..f67b212abf6fa 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3375,8 +3375,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
     break;
 #include "clang/Basic/OpenCLExtensionTypes.def"
   case BuiltinType::HLSLResource:
-    // TODO: Do we need a mangling scheme here?
-    llvm_unreachable("mangling an HLSL handle type?");
+    Out << "25__builtin_hlsl_resource_t";
     break;
   // The SVE types are effectively target-specific.  The mangling scheme
   // is defined in the appendices to the Procedure Call Standard for the
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 6482100e6b7bc..f58f00a641e6e 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2577,8 +2577,7 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
 #include "clang/Basic/OpenCLExtensionTypes.def"
 
   case BuiltinType::HLSLResource:
-    // TODO: Do we need a mangling scheme here?
-    llvm_unreachable("mangling an HLSL handle type?");
+    mangleArtificialTagType(TagTypeKind::Struct, "__builtin_hlsl_resource_t");
     break;
 
   case BuiltinType::NullPtr:
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 3e4b8ce09c33c..7018a7f016313 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3482,7 +3482,7 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
   case OCLReserveID:
     return "reserve_id_t";
   case HLSLResource:
-    return "<hlsl resource>";
+    return "__builtin_hlsl_resource_t";
   case IncompleteMatrixIdx:
     return "<incomplete matrix index type>";
   case ArraySection:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0dde1f6a9d606..e7d75dc166d85 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -745,9 +745,8 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
 #include "clang/Basic/OpenCLExtensionTypes.def"
 
   case BuiltinType::HLSLResource:
-    // TODO: We probably need a valid name here, which means we'll also want to
-    // update `BuiltinType::getName`...
-    return getOrCreateStructPtrType("<hlsl resource>", HLSLResourceTy);
+    return getOrCreateStructPtrType("__builtin_hlsl_resource_t",
+                                    HLSLResourceTy);
 
 #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 069978c1b4023..fefc98c2f3d2b 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -382,6 +382,9 @@ void Sema::Initialize() {
     addImplicitTypedef("size_t", Context.getSizeType());
   }
 
+  if (getLangOpts().HLSL)
+    addImplicitTypedef("__builtin_hlsl_resource_t", Context.HLSLResourceTy);
+
   // Initialize predefined OpenCL types and supported extensions and (optional)
   // core features.
   if (getLangOpts().OpenCL) {

>From fd38cf90b13173fe71d28fed447fd57146a09e8d Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Fri, 21 Jun 2024 12:10:24 -0700
Subject: [PATCH 3/4] Add HLSLIntangibleTypes.def and first HLSL intangible
 type HLSLResource.

Modify all places where HLSLResource needs to be added to use the def file.

Future intangible types will be added just to HLSLIntangibleTypes.def and everything else should just work.

Add getHLSLType virtual method to TargetCodeGenInfo to be overridden in future DirectXTargetCodeGenInfo class (#95952).
---
 clang/include/clang-c/Index.h                 |  4 ++-
 clang/include/clang/AST/ASTContext.h          |  3 +-
 clang/include/clang/AST/BuiltinTypes.def      |  2 --
 clang/include/clang/AST/Type.h                | 20 +++++++----
 clang/include/clang/AST/TypeProperties.td     |  4 +++
 .../clang/Basic/HLSLIntangibleTypes.def       | 33 +++++++++++++++++++
 .../include/clang/Serialization/ASTBitCodes.h |  6 ++--
 clang/include/module.modulemap                |  1 +
 clang/lib/AST/ASTContext.cpp                  | 20 ++++++-----
 clang/lib/AST/ASTImporter.cpp                 |  4 +++
 clang/lib/AST/ExprConstant.cpp                |  3 +-
 clang/lib/AST/ItaniumMangle.cpp               |  9 +++--
 clang/lib/AST/MicrosoftMangle.cpp             | 12 ++++---
 clang/lib/AST/NSAPI.cpp                       |  3 +-
 clang/lib/AST/PrintfFormatString.cpp          |  2 ++
 clang/lib/AST/Type.cpp                        |  9 +++--
 clang/lib/AST/TypeLoc.cpp                     |  3 +-
 clang/lib/CodeGen/CGDebugInfo.cpp             |  8 ++---
 clang/lib/CodeGen/CGDebugInfo.h               |  4 ++-
 clang/lib/CodeGen/CodeGenTypes.cpp            |  7 ++--
 clang/lib/CodeGen/ItaniumCXXABI.cpp           |  3 +-
 clang/lib/CodeGen/TargetInfo.h                |  5 +++
 clang/lib/Index/USRGeneration.cpp             | 10 ++++--
 clang/lib/Sema/SemaExpr.cpp                   |  4 +++
 clang/lib/Serialization/ASTCommon.cpp         |  8 +++--
 clang/lib/Serialization/ASTReader.cpp         |  8 +++--
 clang/tools/libclang/CIndex.cpp               |  3 +-
 clang/tools/libclang/CXType.cpp               |  6 ++--
 28 files changed, 148 insertions(+), 56 deletions(-)
 create mode 100644 clang/include/clang/Basic/HLSLIntangibleTypes.def

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index b47407f571dfe..07f8e54b5bc4d 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2968,7 +2968,9 @@ enum CXTypeKind {
   CXType_Atomic = 177,
   CXType_BTFTagAttributed = 178,
 
-  CXType_HLSLResource = 179
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                           \
+  CXType_##Id,
+#include "clang/Basic/HLSLIntangibleTypes.def"
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 57e4d7c7c6d33..c2b2decda7ea2 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,7 +1130,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
-  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
@@ -1150,6 +1149,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
+#include "clang/Basic/HLSLIntangibleTypes.def"
 
   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
   mutable QualType AutoDeductTy;     // Deduction against 'auto'.
diff --git a/clang/include/clang/AST/BuiltinTypes.def b/clang/include/clang/AST/BuiltinTypes.def
index 74c6585688a71..80548014fb484 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,8 +257,6 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
-// HLSL resource type
-BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
 
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 720ce7715903c..ab5d536fb7a31 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,10 +2626,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   bool isBitIntType() const;                    // Bit-precise integer type
   bool isOpenCLSpecificType() const;            // Any OpenCL specific type
 
-  bool isHLSLResourceType() const;                // HLSL resource type
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
+#include "clang/Basic/HLSLIntangibleTypes.def"
   bool isHLSLSpecificType() const;              // Any HLSL specific type
 
-
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -3022,6 +3022,9 @@ class BuiltinType : public Type {
 // AMDGPU types
 #define AMDGPU_TYPE(Name, Id, SingletonId) Id,
 #include "clang/Basic/AMDGPUTypes.def"
+// HLSL intangible Types
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) Id,
+#include "clang/Basic/HLSLIntangibleTypes.def"
 // All other builtin types
 #define BUILTIN_TYPE(Id, SingletonId) Id,
 #define LAST_BUILTIN_TYPE(Id) LastKind = Id
@@ -7891,12 +7894,17 @@ inline bool Type::isOpenCLSpecificType() const {
          isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
-inline bool Type::isHLSLResourceType() const {
-  return isSpecificBuiltinType(BuiltinType::HLSLResource);
-}
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  inline bool Type::is##Id##Type() const {                                     \
+    return isSpecificBuiltinType(BuiltinType::Id);                             \
+  }
+#include "clang/Basic/HLSLIntangibleTypes.def"
 
 inline bool Type::isHLSLSpecificType() const {
-  return isHLSLResourceType();
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
+  return
+#include "clang/Basic/HLSLIntangibleTypes.def"
+      false; // end boolean or operation
 }
 
 inline bool Type::isTemplateTypeParmType() const {
diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td
index aba14b222a03a..abca6d1678d4e 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -865,6 +865,10 @@ let Class = BuiltinType in {
       case BuiltinType::ID: return ctx.SINGLETON_ID;
 #include "clang/Basic/AMDGPUTypes.def"
 
+#define HLSL_INTANGIBLE_TYPE(NAME, ID, SINGLETON_ID) \
+      case BuiltinType::ID: return ctx.SINGLETON_ID;
+#include "clang/Basic/HLSLIntangibleTypes.def"
+
 #define BUILTIN_TYPE(ID, SINGLETON_ID) \
       case BuiltinType::ID: return ctx.SINGLETON_ID;
 #include "clang/AST/BuiltinTypes.def"
diff --git a/clang/include/clang/Basic/HLSLIntangibleTypes.def b/clang/include/clang/Basic/HLSLIntangibleTypes.def
new file mode 100644
index 0000000000000..7a872e55b4dcb
--- /dev/null
+++ b/clang/include/clang/Basic/HLSLIntangibleTypes.def
@@ -0,0 +1,33 @@
+//===-- HLSLIntangibleTypes.def - HLSL standard intangible types ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--------------------------------------------------------------------------===//
+//
+// This file defines HLSL standard intangible types. These are implementation-
+// defined types such as handle types that have no defined object 
+// representation or value representation and their size is unknown at compile
+// time.
+//
+// The macro is:
+//
+//    HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)
+//
+// where:
+//
+//  - Name is the name of the builtin type.
+//
+//  - BuiltinType::Id is the enumerator defining the type.
+//
+//  - Context.SingletonId is the global singleton of this type.
+//
+// To include this file, define HLSL_INTANGIBLE_TYPE.
+// The macro will be undefined after inclusion.
+//
+//===----------------------------------------------------------------------===//
+
+HLSL_INTANGIBLE_TYPE("__builtin_hlsl_resource_t", HLSLResource, HLSLResourceTy)
+
+#undef HLSL_INTANGIBLE_TYPE
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 807e80184781a..8bcf3f03088ed 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1078,9 +1078,6 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
-  /// \brief The HLSL resource type
-  PREDEF_TYPE_HLSL_RESOURCE_ID = 75,
-
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)                   \
   PREDEF_TYPE_##Id##_ID,
@@ -1103,6 +1100,9 @@ enum PredefinedTypeIDs {
 // \brief AMDGPU types with auto numeration
 #define AMDGPU_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
 #include "clang/Basic/AMDGPUTypes.def"
+// \brief HLSL intangible types with auto numeration
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) PREDEF_TYPE_##Id##_ID,
+#include "clang/Basic/HLSLIntangibleTypes.def"
 
   /// The placeholder type for unresolved templates.
   PREDEF_TYPE_UNRESOLVED_TEMPLATE,
diff --git a/clang/include/module.modulemap b/clang/include/module.modulemap
index acd960c9c932a..b8469f8196b1d 100644
--- a/clang/include/module.modulemap
+++ b/clang/include/module.modulemap
@@ -69,6 +69,7 @@ module Clang_Basic {
   textual header "clang/Basic/DiagnosticOptions.def"
   textual header "clang/Basic/Features.def"
   textual header "clang/Basic/FPOptions.def"
+  textual header "clang/Basic/HLSLIntangibleTypes.def"
   textual header "clang/Basic/MSP430Target.def"
   textual header "clang/Basic/LangOptions.def"
   textual header "clang/Basic/OpenCLExtensions.def"
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 286e30ffd6506..966bfe1302589 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1358,7 +1358,11 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
 #include "clang/Basic/OpenCLExtensionTypes.def"
   }
 
-  InitBuiltinType(HLSLResourceTy, BuiltinType::HLSLResource);
+  if (LangOpts.HLSL) {
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+    InitBuiltinType(SingletonId, BuiltinType::Id);
+#include "clang/Basic/HLSLIntangibleTypes.def"
+  }
 
   if (Target.hasAArch64SVETypes()) {
 #define SVE_TYPE(Name, Id, SingletonId) \
@@ -2161,12 +2165,6 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
       Width = Target->getPointerWidth(AS);
       Align = Target->getPointerAlign(AS);
       break;
-    case BuiltinType::HLSLResource:
-      // TODO: We actually want this to have a size of zero, but for now we'll
-      // just treat it like a pointer to make progress.
-      Width = Target->getPointerWidth(LangAS::Default);
-      Align = Target->getPointerAlign(LangAS::Default);
-      break;
     // The SVE types are effectively target-specific.  The length of an
     // SVE_VECTOR_TYPE is only known at runtime, but it is always a multiple
     // of 128 bits.  There is one predicate bit for each vector byte, so the
@@ -2223,6 +2221,11 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
     Align = ALIGN;                                                             \
     break;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
+      Width = 0;
+      Align = 8;
+      break;
     }
     break;
   case Type::ObjCObjectPointer:
@@ -8218,11 +8221,12 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
     case BuiltinType::OCLSampler:
-    case BuiltinType::HLSLResource:
     case BuiltinType::Dependent:
 #define PPC_VECTOR_TYPE(Name, Id, Size) \
     case BuiltinType::Id:
 #include "clang/Basic/PPCTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
 #define BUILTIN_TYPE(KIND, ID)
 #define PLACEHOLDER_TYPE(KIND, ID) \
     case BuiltinType::KIND:
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1b67feaae8874..90985c6fd3c94 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1103,6 +1103,10 @@ ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
   case BuiltinType::Id:                                                        \
     return Importer.getToContext().SingletonId;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case BuiltinType::Id:                                                        \
+    return Importer.getToContext().SingletonId;
+#include "clang/Basic/HLSLIntangibleTypes.def"
 #define SHARED_SINGLETON_TYPE(Expansion)
 #define BUILTIN_TYPE(Id, SingletonId) \
   case BuiltinType::Id: return Importer.getToContext().SingletonId;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index ffe4334e3d3cb..88eaa356438b4 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11845,7 +11845,6 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
     case BuiltinType::OCLClkEvent:
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
-    case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
     case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
@@ -11858,6 +11857,8 @@ GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
       return GCCTypeClass::None;
 
     case BuiltinType::Dependent:
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index f67b212abf6fa..d364fe8476b42 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3374,9 +3374,6 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
     Out << type_name.size() << type_name; \
     break;
 #include "clang/Basic/OpenCLExtensionTypes.def"
-  case BuiltinType::HLSLResource:
-    Out << "25__builtin_hlsl_resource_t";
-    break;
   // The SVE types are effectively target-specific.  The mangling scheme
   // is defined in the appendices to the Procedure Call Standard for the
   // Arm Architecture.
@@ -3432,6 +3429,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
     Out << 'u' << type_name.size() << type_name;                               \
     break;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case BuiltinType::Id:                                                        \
+    type_name = Name;                                                          \
+    Out << type_name.size() << type_name;                                      \
+    break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
   }
 }
 
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index f58f00a641e6e..86fe46cdfd640 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2576,10 +2576,6 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
     break;
 #include "clang/Basic/OpenCLExtensionTypes.def"
 
-  case BuiltinType::HLSLResource:
-    mangleArtificialTagType(TagTypeKind::Struct, "__builtin_hlsl_resource_t");
-    break;
-
   case BuiltinType::NullPtr:
     Out << "$$T";
     break;
@@ -2606,8 +2602,14 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
     mangleArtificialTagType(TagTypeKind::Struct, MangledName);                 \
     mangleArtificialTagType(TagTypeKind::Struct, MangledName, {"__clang"});    \
     break;
-
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
+
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case BuiltinType::Id:                                                        \
+    mangleArtificialTagType(TagTypeKind::Struct, Name);                        \
+    break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
+
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/AST/NSAPI.cpp b/clang/lib/AST/NSAPI.cpp
index b6ce458632a7c..3d1f8488a8927 100644
--- a/clang/lib/AST/NSAPI.cpp
+++ b/clang/lib/AST/NSAPI.cpp
@@ -443,7 +443,6 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
   case BuiltinType::OCLReserveID:
-  case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
@@ -456,6 +455,8 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
   case BuiltinType::BoundMember:
   case BuiltinType::UnresolvedTemplate:
   case BuiltinType::Dependent:
diff --git a/clang/lib/AST/PrintfFormatString.cpp b/clang/lib/AST/PrintfFormatString.cpp
index 3031d76abbd75..3c6cd2d0f4341 100644
--- a/clang/lib/AST/PrintfFormatString.cpp
+++ b/clang/lib/AST/PrintfFormatString.cpp
@@ -867,6 +867,8 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt,
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
 #define SIGNED_TYPE(Id, SingletonId)
 #define UNSIGNED_TYPE(Id, SingletonId)
 #define FLOATING_TYPE(Id, SingletonId)
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 7018a7f016313..9e4b0818c0dd6 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3481,8 +3481,6 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
     return "queue_t";
   case OCLReserveID:
     return "reserve_id_t";
-  case HLSLResource:
-    return "__builtin_hlsl_resource_t";
   case IncompleteMatrixIdx:
     return "<incomplete matrix index type>";
   case ArraySection:
@@ -3515,6 +3513,10 @@ StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
   case Id:                                                                     \
     return Name;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case Id:                                                                     \
+    return Name;
+#include "clang/Basic/HLSLIntangibleTypes.def"
   }
 
   llvm_unreachable("Invalid builtin type.");
@@ -4774,7 +4776,6 @@ bool Type::canHaveNullability(bool ResultIfUnknown) const {
     case BuiltinType::OCLClkEvent:
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
-    case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
     case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
@@ -4787,6 +4788,8 @@ bool Type::canHaveNullability(bool ResultIfUnknown) const {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
     case BuiltinType::BuiltinFn:
     case BuiltinType::NullPtr:
     case BuiltinType::IncompleteMatrixIdx:
diff --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index 6cf9bbf98dddf..0d653d6faaa82 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -418,7 +418,6 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
   case BuiltinType::OCLReserveID:
-  case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
@@ -431,6 +430,8 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
   case BuiltinType::BuiltinFn:
   case BuiltinType::IncompleteMatrixIdx:
   case BuiltinType::ArraySection:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index e7d75dc166d85..8ea9b0525b0c3 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -743,10 +743,10 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
   case BuiltinType::Id: \
     return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
 #include "clang/Basic/OpenCLExtensionTypes.def"
-
-  case BuiltinType::HLSLResource:
-    return getOrCreateStructPtrType("__builtin_hlsl_resource_t",
-                                    HLSLResourceTy);
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case BuiltinType::Id:                                                        \
+    return getOrCreateStructPtrType(Name, SingletonId);
+#include "clang/Basic/HLSLIntangibleTypes.def"
 
 #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index cb366029beb80..b29c325ad147b 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -81,11 +81,13 @@ class CGDebugInfo {
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
   llvm::DIType *Id##Ty = nullptr;
 #include "clang/Basic/OpenCLExtensionTypes.def"
-  llvm::DIType *HLSLResourceTy = nullptr;
 #define WASM_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  llvm::DIType *SingletonId = nullptr;
+#include "clang/Basic/HLSLIntangibleTypes.def"
 
   /// Cache of previously constructed Types.
   llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp
index ce99017c3f424..34eee13e35584 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -444,9 +444,6 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
     case BuiltinType::OCLReserveID:
       ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
       break;
-    case BuiltinType::HLSLResource:
-      ResultType = CGM.getHLSLRuntime().convertHLSLSpecificType(Ty);
-      break;
     case BuiltinType::SveInt8:
     case BuiltinType::SveUint8:
     case BuiltinType::SveInt8x2:
@@ -542,6 +539,10 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   case BuiltinType::Id:                                                        \
     return llvm::PointerType::get(getLLVMContext(), AS);
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
+      ResultType = CGM.getHLSLRuntime().convertHLSLSpecificType(Ty);
+      break;
     case BuiltinType::Dependent:
 #define BUILTIN_TYPE(Id, SingletonId)
 #define PLACEHOLDER_TYPE(Id, SingletonId) \
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 12f00d7c3776a..4d0ab4d88a7cc 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3352,7 +3352,6 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
     case BuiltinType::OCLClkEvent:
     case BuiltinType::OCLQueue:
     case BuiltinType::OCLReserveID:
-    case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) \
     case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
@@ -3365,6 +3364,8 @@ static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
     case BuiltinType::ShortAccum:
     case BuiltinType::Accum:
     case BuiltinType::LongAccum:
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index f242d9e36ed40..e42d60879d5ca 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -413,6 +413,11 @@ class TargetCodeGenInfo {
     return nullptr;
   }
 
+  /// Return an LLVM type that corresponds to a HLSL type
+  virtual llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const {
+    return nullptr;
+  }
+
 protected:
   static std::string qualifyWindowsLibrary(StringRef Lib);
 
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 71c74e48cd55f..0d68e03ee912b 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -757,9 +757,8 @@ void USRGenerator::VisitType(QualType T) {
         case BuiltinType::OCLReserveID:
           Out << "@BT at OCLReserveID"; break;
         case BuiltinType::OCLSampler:
-          Out << "@BT at OCLSampler"; break;
-        case BuiltinType::HLSLResource:
-          Out << "@BT at HLSLResource"; break;
+          Out << "@BT at OCLSampler";
+          break;
 #define SVE_TYPE(Name, Id, SingletonId) \
         case BuiltinType::Id: \
           Out << "@BT@" << Name; break;
@@ -779,6 +778,11 @@ void USRGenerator::VisitType(QualType T) {
     Out << "@BT@" << #Name;                                                    \
     break;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case BuiltinType::Id:                                                        \
+    Out << "@BT@" << Name;                                                     \
+    break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
         case BuiltinType::ShortAccum:
           Out << "@BT at ShortAccum"; break;
         case BuiltinType::Accum:
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4a2f3a65eac96..b35f30f545d85 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6171,6 +6171,8 @@ static bool isPlaceholderToRemoveAsArg(QualType type) {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
 #define PLACEHOLDER_TYPE(ID, SINGLETON_ID)
 #define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID:
 #include "clang/AST/BuiltinTypes.def"
@@ -21005,6 +21007,8 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define PLACEHOLDER_TYPE(Id, SingletonId)
 #include "clang/AST/BuiltinTypes.def"
diff --git a/clang/lib/Serialization/ASTCommon.cpp b/clang/lib/Serialization/ASTCommon.cpp
index e223aaca3acd6..06dbfc1644f5d 100644
--- a/clang/lib/Serialization/ASTCommon.cpp
+++ b/clang/lib/Serialization/ASTCommon.cpp
@@ -238,9 +238,6 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
   case BuiltinType::OCLReserveID:
     ID = PREDEF_TYPE_RESERVE_ID_ID;
     break;
-  case BuiltinType::HLSLResource:
-    ID = PREDEF_TYPE_HLSL_RESOURCE_ID;
-    break;
 #define SVE_TYPE(Name, Id, SingletonId) \
   case BuiltinType::Id: \
     ID = PREDEF_TYPE_##Id##_ID; \
@@ -266,6 +263,11 @@ serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
     ID = PREDEF_TYPE_##Id##_ID;                                                \
     break;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case BuiltinType::Id:                                                        \
+    ID = PREDEF_TYPE_##Id##_ID;                                                \
+    break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
   case BuiltinType::BuiltinFn:
     ID = PREDEF_TYPE_BUILTIN_FN;
     break;
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 2438960e4d3bf..c5ce9f9b24b14 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7377,9 +7377,6 @@ QualType ASTReader::GetType(TypeID ID) {
     case PREDEF_TYPE_RESERVE_ID_ID:
       T = Context.OCLReserveIDTy;
       break;
-    case PREDEF_TYPE_HLSL_RESOURCE_ID:
-      T = Context.HLSLResourceTy;
-      break;
     case PREDEF_TYPE_AUTO_DEDUCT:
       T = Context.getAutoDeductType();
       break;
@@ -7429,6 +7426,11 @@ QualType ASTReader::GetType(TypeID ID) {
     T = Context.SingletonId;                                                   \
     break;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  case PREDEF_TYPE_##Id##_ID:                                                  \
+    T = Context.SingletonId;                                                   \
+    break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
     }
 
     assert(!T.isNull() && "Unknown predefined type");
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index a349e45415f31..83719f3bed2d7 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -1635,7 +1635,6 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
   case BuiltinType::OCLClkEvent:
   case BuiltinType::OCLQueue:
   case BuiltinType::OCLReserveID:
-  case BuiltinType::HLSLResource:
 #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AArch64SVEACLETypes.def"
 #define PPC_VECTOR_TYPE(Name, Id, Size) case BuiltinType::Id:
@@ -1646,6 +1645,8 @@ bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index df83918288d73..ed6477d0a5dc6 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -77,7 +77,8 @@ static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
     BTCASE(OCLEvent);
     BTCASE(OCLQueue);
     BTCASE(OCLReserveID);
-    BTCASE(HLSLResource);
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) BTCASE(Id);
+#include "clang/Basic/HLSLIntangibleTypes.def"
   default:
     return CXType_Unexposed;
   }
@@ -629,7 +630,8 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
     TKIND(OCLEvent);
     TKIND(OCLQueue);
     TKIND(OCLReserveID);
-    TKIND(HLSLResource);
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) TKIND(Id);
+#include "clang/Basic/HLSLIntangibleTypes.def"
     TKIND(Atomic);
   }
 #undef TKIND

>From 8be57cc4e6a1feeec85e1dabb0c437c198f403ba Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Mon, 1 Jul 2024 15:38:40 -0700
Subject: [PATCH 4/4] Add typedef and simple AST test

---
 clang/lib/AST/Type.cpp                 |  5 ++++-
 clang/lib/Sema/Sema.cpp                |  6 ++++++
 clang/test/AST/HLSL/hlsl_resource.hlsl | 11 +++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/HLSL/hlsl_resource.hlsl

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 9e4b0818c0dd6..420e9c7ec6d29 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2446,7 +2446,10 @@ bool Type::isSizelessBuiltinType() const {
       // WebAssembly reference types
 #define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-      return true;
+      // HLSL intangible types
+      // #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case
+      // BuiltinType::Id: #include "clang/Basic/HLSLIntangibleTypes.def"
+      //       return true;
     default:
       return false;
     }
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index fefc98c2f3d2b..4f67c1f59bac5 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -508,6 +508,12 @@ void Sema::Initialize() {
 #include "clang/Basic/AMDGPUTypes.def"
   }
 
+  if (getLangOpts().HLSL) {
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
+  addImplicitTypedef(Name, Context.SingletonId);
+#include "clang/Basic/HLSLIntangibleTypes.def"
+  }
+
   if (Context.getTargetInfo().hasBuiltinMSVaList()) {
     DeclarationName MSVaList = &Context.Idents.get("__builtin_ms_va_list");
     if (IdResolver.begin(MSVaList) == IdResolver.end())
diff --git a/clang/test/AST/HLSL/hlsl_resource.hlsl b/clang/test/AST/HLSL/hlsl_resource.hlsl
new file mode 100644
index 0000000000000..895b6ad39883e
--- /dev/null
+++ b/clang/test/AST/HLSL/hlsl_resource.hlsl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -syntax-only -disable-llvm-passes -o - %s | FileCheck %s
+
+struct MyBuffer {
+  __builtin_hlsl_resource_t handle;
+};
+
+// CHECK:TypedefDecl 0x{{[0-9a-f]+}} <<invalid sloc>> <invalid sloc> implicit referenced __builtin_hlsl_resource_t '__builtin_hlsl_resource_t'
+// CHECK-NEXT:BuiltinType 0x{{[0-9a-f]+}} '__builtin_hlsl_resource_t'
+
+// CHECK:CXXRecordDecl 0x{{[0-9a-f]+}} <clang/test/AST/HLSL/hlsl_resource.hlsl:3:1, line:5:1> line:3:8 struct MyBuffer definition
+// CHECK:FieldDecl 0x{{[0-9a-f]+}} <line:4:3, col:29> col:29 handle '__builtin_hlsl_resource_t'



More information about the lldb-commits mailing list