[Lldb-commits] [lldb] 52956b0 - [HLSL] Implement intangible AST type (#97362)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 5 10:50:38 PDT 2024
Author: Helena Kotas
Date: 2024-08-05T10:50:34-07:00
New Revision: 52956b0f705499ae4a268d3629b402ecdc2cbbab
URL: https://github.com/llvm/llvm-project/commit/52956b0f705499ae4a268d3629b402ecdc2cbbab
DIFF: https://github.com/llvm/llvm-project/commit/52956b0f705499ae4a268d3629b402ecdc2cbbab.diff
LOG: [HLSL] Implement intangible AST type (#97362)
HLSL has a set of intangible types which are described in in the
[draft HLSL Specification
(**[Basic.types]**)](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf):
There are special implementation-defined types such as handle types,
which fall into a category of standard intangible types. Intangible
types are types that have no defined object representation or value
representation, as such the size is unknown at compile time.
A class type T is an intangible class type if it contains an base
classes or members of intangible class type, standard intangible type,
or arrays of such types. Standard intangible types and intangible class
types are collectively called intangible
types([9](https://microsoft.github.io/hlsl-specs/specs/hlsl.html#Intangible)).
This PR implements one standard intangible type `__hlsl_resource_t`
and sets up the infrastructure that will make it easier to add more
in the future, such as samplers or raytracing payload handles. The
HLSL intangible types are declared in
`clang/include/clang/Basic/HLSLIntangibleTypes.def` and this file is
included with related macro definition in most places that require edits
when a new type is added.
The new types are added as keywords and not typedefs to make sure they
cannot be redeclared, and they can only be declared in builtin implicit
headers. The `__hlsl_resource_t` type represents a handle to a memory
resource and it is going to be used in builtin HLSL buffer types like this:
template <typename T>
class RWBuffer {
[[hlsl::contained_type(T)]]
[[hlsl::is_rov(false)]]
[[hlsl::resource_class(uav)]]
__hlsl_resource_t Handle;
};
Part 1/3 of llvm/llvm-project#90631.
---------
Co-authored-by: Justin Bogner <mail at justinbogner.com>
Added:
clang/include/clang/Basic/HLSLIntangibleTypes.def
clang/test/AST/HLSL/hlsl_resource_t.hlsl
clang/test/SemaHLSL/BuiltIns/hlsl_resource_t.hlsl
Modified:
clang/include/clang-c/Index.h
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Sema/DeclSpec.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/module.modulemap
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/NSAPI.cpp
clang/lib/AST/PrintfFormatString.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/TargetInfo.h
clang/lib/Index/USRGeneration.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseTentative.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReader.cpp
clang/test/Modules/no-external-type-id.cppm
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXType.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Removed:
################################################################################
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 4b4adbfb236e7..f3d485b9e088d 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2978,7 +2978,10 @@ enum CXTypeKind {
CXType_ExtVector = 176,
CXType_Atomic = 177,
- CXType_BTFTagAttributed = 178
+ CXType_BTFTagAttributed = 178,
+
+ // HLSL Intangible Types
+ CXType_HLSLResource = 179,
};
/**
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index ec8b32533eca8..94cf9113cd43a 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1173,6 +1173,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/Type.h b/clang/include/clang/AST/Type.h
index dec51e032158e..0c886526c61ce 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2630,6 +2630,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
bool isBitIntType() const; // Bit-precise integer type
bool isOpenCLSpecificType() const; // Any OpenCL specific 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 +3026,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
@@ -8261,6 +8268,19 @@ inline bool Type::isOpenCLSpecificType() const {
isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
}
+#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 {
+#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 {
return isa<TemplateTypeParmType>(CanonicalType);
}
diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td
index 7d4353c2773a3..33398ecf5b849 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -872,6 +872,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..391f0dbfcec18
--- /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(__hlsl_resource_t, HLSLResource, HLSLResourceTy)
+
+#undef HLSL_INTANGIBLE_TYPE
diff --git a/clang/include/clang/Basic/Specifiers.h b/clang/include/clang/Basic/Specifiers.h
index fb11e8212f8b6..7bfa26543578d 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -98,6 +98,9 @@ namespace clang {
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
TST_##ImgType##_t, // OpenCL image types
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ TST_##Name, // HLSL Intangible Types
+#include "clang/Basic/HLSLIntangibleTypes.def"
TST_error // erroneous type
};
diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
index 7e638dc1ddcdb..2cea64e2bd590 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -654,6 +654,9 @@ KEYWORD(groupshared , KEYHLSL)
KEYWORD(in , KEYHLSL)
KEYWORD(inout , KEYHLSL)
KEYWORD(out , KEYHLSL)
+// HLSL Intangible Types
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) KEYWORD(Name, KEYHLSL)
+#include "clang/Basic/HLSLIntangibleTypes.def"
// OpenMP Type Traits
UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, OpenMPRequiredSimdAlign, KEYALL)
diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index 425b6e2a0b30c..06243f2624876 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -322,6 +322,9 @@ class DeclSpec {
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ static const TST TST_##Name = clang::TST_##Name;
+#include "clang/Basic/HLSLIntangibleTypes.def"
static const TST TST_error = clang::TST_error;
// type-qualifiers
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h
index 24ae6b768d379..f19eef6c5908d 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1121,6 +1121,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,
@@ -1133,7 +1136,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/include/module.modulemap b/clang/include/module.modulemap
index 00ecd47d35b62..b6ab99bb85d8a 100644
--- a/clang/include/module.modulemap
+++ b/clang/include/module.modulemap
@@ -70,6 +70,7 @@ module Clang_Basic {
textual header "clang/Basic/DiagnosticOptions.def"
textual header "clang/Basic/FPOptions.def"
textual header "clang/Basic/Features.def"
+ textual header "clang/Basic/HLSLIntangibleTypes.def"
textual header "clang/Basic/LangOptions.def"
textual header "clang/Basic/MSP430Target.def"
textual header "clang/Basic/OpenACCClauses.def"
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4c0b2fe9433f8..995d01734eea0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1384,6 +1384,12 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
#include "clang/Basic/OpenCLExtensionTypes.def"
}
+ if (LangOpts.HLSL) {
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ InitBuiltinType(SingletonId, BuiltinType::Id);
+#include "clang/Basic/HLSLIntangibleTypes.def"
+ }
+
if (Target.hasAArch64SVETypes() ||
(AuxTarget && AuxTarget->hasAArch64SVETypes())) {
#define SVE_TYPE(Name, Id, SingletonId) \
@@ -2242,6 +2248,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:
@@ -3355,6 +3366,10 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
case BuiltinType::Id: \
return;
#include "clang/Basic/AArch64SVEACLETypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ case BuiltinType::Id: \
+ return;
+#include "clang/Basic/HLSLIntangibleTypes.def"
case BuiltinType::Dependent:
llvm_unreachable("should never get here");
case BuiltinType::AMDGPUBufferRsrc:
@@ -8552,6 +8567,8 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
#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 103235547f482..c835b7241ce09 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1151,6 +1151,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 558e20ed3e423..d4b9095c7509b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11879,6 +11879,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 ead5da4e90f2f..aa89632ad390a 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3428,6 +3428,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 << 'u' << 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 28f66e71c2f2d..ed8d1cf1b98dd 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2741,6 +2741,13 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
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 48d1763125e6c..3d1f8488a8927 100644
--- a/clang/lib/AST/NSAPI.cpp
+++ b/clang/lib/AST/NSAPI.cpp
@@ -455,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 0456b5f96b210..e89ce2e4b3844 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2447,6 +2447,9 @@ bool Type::isSizelessBuiltinType() const {
// WebAssembly reference types
#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
#include "clang/Basic/WebAssemblyReferenceTypes.def"
+ // HLSL intangible types
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/HLSLIntangibleTypes.def"
return true;
default:
return false;
@@ -3454,6 +3457,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.");
@@ -4786,6 +4793,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 33e6ccbadc12d..0d653d6faaa82 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -430,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 b49dee24c3c1a..8d57c87e97e39 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -744,6 +744,10 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
case BuiltinType::Id: \
return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
#include "clang/Basic/OpenCLExtensionTypes.def"
+#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 a0c419cf1e208..4ccff581cadb2 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -87,6 +87,9 @@ class CGDebugInfo {
#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/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index defc79683e61f..a2c3e76f77b7c 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,16 @@ 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;
+
+ llvm_unreachable("Generic handling of HLSL types is not supported.");
+}
+
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 3f2dc0ae7b84d..527e73a0e21fc 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -113,6 +113,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 e0f567c5da342..652a6d2f92ad8 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"
@@ -593,6 +594,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 cd76f8406e7b7..e5d0cc42cc77d 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3630,6 +3630,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 8f17c053f4783..f38275c51d582 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -418,6 +418,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;
+ }
+
static void
setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
llvm::Function &F);
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index ad7870309c5df..f00bc56429f1a 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -785,6 +785,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/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 4a2d9a650e20c..6c5f4ac1f6e88 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4837,6 +4837,13 @@ void Parser::ParseDeclarationSpecifiers(
ParseHLSLQualifiers(DS.getAttributes());
continue;
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ case tok::kw_##Name: \
+ isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, \
+ DiagID, Policy); \
+ break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
+
case tok::less:
// GCC ObjC supports types like "<SomeProtocol>" as a synonym for
// "id<SomeProtocol>". This is hopelessly old fashioned and dangerous,
@@ -5847,6 +5854,8 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const {
case tok::kw___vector:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
// struct-or-union-specifier (C99) or class-specifier (C++)
case tok::kw_class:
@@ -5931,6 +5940,8 @@ bool Parser::isTypeSpecifierQualifier() {
case tok::kw___vector:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
// struct-or-union-specifier (C99) or class-specifier (C++)
case tok::kw_class:
@@ -6275,6 +6286,8 @@ bool Parser::isDeclarationSpecifier(
case tok::kw___write_only:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
case tok::kw___funcref:
case tok::kw_groupshared:
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 826e7b603ee82..b8e15b1aa6ce9 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1644,6 +1644,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
case tok::kw__Sat:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
{
if (!getLangOpts().CPlusPlus) {
Diag(Tok, diag::err_expected_expression);
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index c0eae73927cdd..9bb0fff329d72 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2455,6 +2455,11 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
Policy); \
break;
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ case tok::kw_##Name: \
+ DS.SetTypeSpecType(DeclSpec::TST_##Name, Loc, PrevSpec, DiagID, Policy); \
+ break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
case tok::annot_decltype:
case tok::kw_decltype:
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 0142271b8e6d1..9f6b4f6118ede 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1807,6 +1807,8 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
case tok::annot_pack_indexing_type:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
if (NextToken().is(tok::l_paren))
return TPResult::Ambiguous;
@@ -1933,6 +1935,8 @@ bool Parser::isCXXDeclarationSpecifierAType() {
case tok::kw__Sat:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case tok::kw_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
return true;
case tok::kw_auto:
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 9a4d52d4b6b71..5272786a92092 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -377,6 +377,8 @@ bool Declarator::isDeclarationOfFunction() const {
case TST_typename_pack_indexing:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
return false;
case TST_decltype_auto:
@@ -608,6 +610,10 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
case DeclSpec::TST_##ImgType##_t: \
return #ImgType "_t";
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ case DeclSpec::TST_##Name: \
+ return #Name;
+#include "clang/Basic/HLSLIntangibleTypes.def"
case DeclSpec::TST_error: return "(error)";
}
llvm_unreachable("Unknown typespec!");
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2cefa97cdc600..1f4bfa247b544 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8738,7 +8738,7 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
}
if (!NewVD->hasLocalStorage() && T->isSizelessType() &&
- !T.isWebAssemblyReferenceType()) {
+ !T.isWebAssemblyReferenceType() && !T->isHLSLSpecificType()) {
Diag(NewVD->getLocation(), diag::err_sizeless_nonlocal) << T;
NewVD->setInvalidDecl();
return;
@@ -18336,8 +18336,12 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
QualType EltTy = Context.getBaseElementType(T);
if (!EltTy->isDependentType() && !EltTy->containsErrors()) {
- if (RequireCompleteSizedType(Loc, EltTy,
- diag::err_field_incomplete_or_sizeless)) {
+ bool isIncomplete =
+ LangOpts.HLSL // HLSL allows sizeless builtin types
+ ? RequireCompleteType(Loc, EltTy, diag::err_incomplete_type)
+ : RequireCompleteSizedType(Loc, EltTy,
+ diag::err_field_incomplete_or_sizeless);
+ if (isIncomplete) {
// Fields of incomplete type force their record to be invalid.
Record->setInvalidDecl();
InvalidDecl = true;
@@ -18952,9 +18956,12 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
// elsewhere, after synthesized ivars are known.
}
} else if (!FDTy->isDependentType() &&
- RequireCompleteSizedType(
- FD->getLocation(), FD->getType(),
- diag::err_field_incomplete_or_sizeless)) {
+ (LangOpts.HLSL // HLSL allows sizeless builtin types
+ ? RequireCompleteType(FD->getLocation(), FD->getType(),
+ diag::err_incomplete_type)
+ : RequireCompleteSizedType(
+ FD->getLocation(), FD->getType(),
+ diag::err_field_incomplete_or_sizeless))) {
// Incomplete type
FD->setInvalidDecl();
EnclosingDecl->setInvalidDecl();
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d0ba12fe80f9a..b1b0d1cbbd31d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6077,6 +6077,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"
@@ -20869,6 +20871,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/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 3d4ccaf68c700..c45384f9da4cd 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -935,6 +935,8 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
case TST_BFloat16:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
+#include "clang/Basic/HLSLIntangibleTypes.def"
case TST_unknown_anytype:
case TST_error:
break;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6fa39cdccef2b..df537484aef45 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1357,6 +1357,12 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
break;
#include "clang/Basic/OpenCLImageTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
+ case DeclSpec::TST_##Name: \
+ Result = Context.SingletonId; \
+ break;
+#include "clang/Basic/HLSLIntangibleTypes.def"
+
case DeclSpec::TST_error:
Result = Context.IntTy;
declarator.setInvalidType(true);
diff --git a/clang/lib/Serialization/ASTCommon.cpp b/clang/lib/Serialization/ASTCommon.cpp
index 444a8a3d3a514..f30642f513ae4 100644
--- a/clang/lib/Serialization/ASTCommon.cpp
+++ b/clang/lib/Serialization/ASTCommon.cpp
@@ -263,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 657ea305f52cf..fccdecef27856 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7439,6 +7439,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/test/AST/HLSL/hlsl_resource_t.hlsl b/clang/test/AST/HLSL/hlsl_resource_t.hlsl
new file mode 100644
index 0000000000000..4a580ffc40572
--- /dev/null
+++ b/clang/test/AST/HLSL/hlsl_resource_t.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -disable-llvm-passes -o - 2>&1 %s | FileCheck %s
+
+struct MyBuffer {
+ __hlsl_resource_t handle;
+};
+
+// CHECK:CXXRecordDecl 0x{{[0-9a-f]+}} <{{.*}}> line:3:8 struct MyBuffer definition
+// CHECK:FieldDecl 0x{{[0-9a-f]+}} <line:4:3, col:21> col:21 handle '__hlsl_resource_t'
diff --git a/clang/test/Modules/no-external-type-id.cppm b/clang/test/Modules/no-external-type-id.cppm
index 3ca50be18a7fd..068e52646dcc1 100644
--- a/clang/test/Modules/no-external-type-id.cppm
+++ b/clang/test/Modules/no-external-type-id.cppm
@@ -23,7 +23,7 @@ export module b;
import a;
export int b();
-// CHECK: <DECL_FUNCTION {{.*}} op8=4048
+// CHECK: <DECL_FUNCTION {{.*}} op8=4056
// CHECK: <TYPE_FUNCTION_PROTO
//--- a.v1.cppm
diff --git a/clang/test/SemaHLSL/BuiltIns/hlsl_resource_t.hlsl b/clang/test/SemaHLSL/BuiltIns/hlsl_resource_t.hlsl
new file mode 100644
index 0000000000000..a17ec327ba9e7
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/hlsl_resource_t.hlsl
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple dxil-unknown-shadermodel6.3-library %s
+
+// Note: As HLSL resource type are sizeless type, we don't exhaustively
+// test for cases covered by sizeless-1.c and similar tests.
+
+typedef int __hlsl_resource_t; // expected-error {{cannot combine with previous 'int' declaration specifier}} expected-warning {{typedef requires a name}}
+typedef int __hlsl_resource_t[]; // expected-error {{cannot combine with previous 'int' declaration specifier}} expected-error {{expected unqualified-id}}
+
+__hlsl_resource_t r1;
+__hlsl_resource_t r2[10]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+__hlsl_resource_t r3[]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+groupshared __hlsl_resource_t r11;
+groupshared __hlsl_resource_t r12[10]; // expected-error {{array has sizeless element type 'groupshared __hlsl_resource_t'}}
+groupshared __hlsl_resource_t r13[]; // expected-error {{array has sizeless element type 'groupshared __hlsl_resource_t'}}
+
+static __hlsl_resource_t r21;
+static __hlsl_resource_t r22[10]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+static __hlsl_resource_t r23[]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+
+cbuffer CB {
+ __hlsl_resource_t r31;
+ __hlsl_resource_t r32[10]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+ __hlsl_resource_t r33[]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+}
+
+struct S {
+ __hlsl_resource_t r1;
+ __hlsl_resource_t r2[10]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+ __hlsl_resource_t r3[]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+};
+
+class C {
+ __hlsl_resource_t r1;
+ __hlsl_resource_t r2[10]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+ __hlsl_resource_t r3[]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+};
+
+union U {
+ __hlsl_resource_t r1;
+ __hlsl_resource_t r2[10]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+ __hlsl_resource_t r3[]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+};
+
+void f1(__hlsl_resource_t r1);
+void f2(__hlsl_resource_t r2[10]); // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+void f3(__hlsl_resource_t r3[]); // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+
+__hlsl_resource_t f4();
+
+void f(__hlsl_resource_t arg) {
+ __hlsl_resource_t r1;
+ __hlsl_resource_t r2[10]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+ __hlsl_resource_t r3[]; // expected-error {{array has sizeless element type '__hlsl_resource_t'}}
+
+ static __hlsl_resource_t r4;
+
+ __hlsl_resource_t foo = arg;
+ int a = arg; // expected-error {{cannot initialize a variable of type 'int' with an lvalue of type '__hlsl_resource_t'}}
+ int b = arg[0]; // expected-error {{subscripted value is not an array, pointer, or vector}}
+
+ foo == arg; // expected-error {{invalid operands to binary expression ('__hlsl_resource_t' and '__hlsl_resource_t')}}
+ foo + arg; // expected-error {{invalid operands to binary expression ('__hlsl_resource_t' and '__hlsl_resource_t')}}
+ foo && arg; // expected-error {{invalid operands to binary expression ('__hlsl_resource_t' and '__hlsl_resource_t')}} expected-error {{value of type '__hlsl_resource_t' is not contextually convertible to 'bool'}}
+ arg++; // expected-error {{cannot increment value of type '__hlsl_resource_t'}}
+}
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index c00cad1ad65af..52d0bd9167b88 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -1645,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 991767dc4c49c..f5d1fbf30c7dc 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -77,9 +77,11 @@ static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
BTCASE(OCLEvent);
BTCASE(OCLQueue);
BTCASE(OCLReserveID);
- default:
- return CXType_Unexposed;
- }
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) BTCASE(Id);
+#include "clang/Basic/HLSLIntangibleTypes.def"
+ default:
+ return CXType_Unexposed;
+ }
#undef BTCASE
}
@@ -628,6 +630,8 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
TKIND(OCLEvent);
TKIND(OCLQueue);
TKIND(OCLReserveID);
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) TKIND(Id);
+#include "clang/Basic/HLSLIntangibleTypes.def"
TKIND(Atomic);
}
#undef TKIND
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 484ca04fe04c9..78e9eeb7bc7aa 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4966,6 +4966,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:
@@ -6091,6 +6092,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:
More information about the lldb-commits
mailing list