[clang] Add concepts for raw buffers (PR #119643)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 13 15:37:48 PST 2024
================
@@ -868,8 +868,54 @@ static Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc,
return TypedResExpr;
}
-static ConceptDecl *constructTypedBufferConceptDecl(Sema &S,
- NamespaceDecl *NSD) {
+static Expr *constructStructuredBufferConstraintExpr(Sema &S,
+ SourceLocation NameLoc,
+ TemplateTypeParmDecl *T) {
+ ASTContext &Context = S.getASTContext();
+
+ // Obtain the QualType for 'bool'
+ QualType BoolTy = Context.BoolTy;
+
+ // Create a QualType that points to this TemplateTypeParmDecl
+ QualType TType = Context.getTypeDeclType(T);
+
+ // Create a TypeSourceInfo for the template type parameter 'T'
+ TypeSourceInfo *TTypeSourceInfo =
+ Context.getTrivialTypeSourceInfo(TType, NameLoc);
+
+ TypeTraitExpr *IsIntangibleExpr =
+ TypeTraitExpr::Create(Context, BoolTy, NameLoc, UTT_IsIntangibleType,
+ {TTypeSourceInfo}, NameLoc, true);
+
+ // negate IsIntangibleExpr
+ UnaryOperator *NotIntangibleExpr = UnaryOperator::Create(
+ Context, IsIntangibleExpr, UO_Not, BoolTy, VK_LValue, OK_Ordinary,
+ NameLoc, false, FPOptionsOverride());
+
+ // element types also may not be of 0 size
+ UnaryExprOrTypeTraitExpr *SizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr(
+ UETT_SizeOf, TTypeSourceInfo, BoolTy, NameLoc, NameLoc);
+
+ // Create a BinaryOperator that checks if the size of the type is not equal to
+ // 1 Empty structs have a size of 1 in HLSL, so we need to check for that
+ IntegerLiteral *rhs = IntegerLiteral::Create(
+ Context, llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1, true),
+ Context.getSizeType(), NameLoc);
+
+ BinaryOperator *SizeGEQOneExpr =
+ BinaryOperator::Create(Context, SizeOfExpr, rhs, BO_GE, BoolTy, VK_LValue,
+ OK_Ordinary, NameLoc, FPOptionsOverride());
+
+ // Combine the two constraints
+ BinaryOperator *CombinedExpr = BinaryOperator::Create(
+ Context, NotIntangibleExpr, SizeGEQOneExpr, BO_LAnd, BoolTy, VK_LValue,
+ OK_Ordinary, NameLoc, FPOptionsOverride());
+
+ return CombinedExpr;
+}
+
+static ConceptDecl *constructTypedBufferConceptDecl(Sema &S, NamespaceDecl *NSD,
+ bool isTypedBuffer) {
----------------
hekota wrote:
This function should not have "Typed" in the name since it can create both typed and structured buffer concept decls.
https://github.com/llvm/llvm-project/pull/119643
More information about the cfe-commits
mailing list