Skip to content

Commit efaf125

Browse files
committed
break down constraint expression into simpler function
1 parent 63358a1 commit efaf125

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

clang/lib/Sema/HLSLExternalSemaSource.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ struct TemplateParameterListBuilder {
359359
return *this;
360360
}
361361

362-
Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc,
362+
BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context,
363+
SourceLocation NameLoc,
363364
TemplateTypeParmDecl *T) {
364-
clang::ASTContext &context = S.getASTContext();
365365
// Obtain the QualType for 'unsigned long'
366366
clang::QualType unsignedLongType = context.UnsignedLongTy;
367367

@@ -376,29 +376,18 @@ struct TemplateParameterListBuilder {
376376
clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo,
377377
unsignedLongType, NameLoc, NameLoc);
378378

379-
// Create an IntegerLiteral for the value '16'
380-
llvm::APInt intValue(context.getIntWidth(context.IntTy), 4);
381-
clang::IntegerLiteral *intLiteral = new (context)
382-
clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc);
383-
384-
// Create an ImplicitCastExpr to cast 'int' to 'unsigned long'
385-
FPOptionsOverride fpoo = FPOptionsOverride();
386-
clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create(
387-
context,
388-
unsignedLongType, // The type we are casting to (QualType for 'unsigned
389-
// long')
390-
clang::CK_IntegralCast, // CastKind (e.g., Integral cast)
391-
intLiteral, // Sub-expression being cast
392-
nullptr, // Base path, usually null for implicit casts
393-
clang::VK_LValue,
394-
fpoo // Value kind, typically VK_RValue for implicit casts
395-
);
379+
// Create an IntegerLiteral for the value '16' with size type
380+
clang::QualType sizeType = context.getSizeType();
381+
llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16);
382+
clang::IntegerLiteral *sizeLiteral = new (context)
383+
clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc);
396384

397385
clang::QualType BoolTy = context.BoolTy;
386+
FPOptionsOverride fpoo = FPOptionsOverride();
398387

399388
clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create(
400389
context, sizeofExpr, // Left-hand side expression
401-
implicitCastExpr, // Right-hand side expression
390+
sizeLiteral, // Right-hand side expression
402391
clang::BO_LE, // Binary operator kind (<=)
403392
BoolTy, // Result type (bool)
404393
clang::VK_LValue, // Value kind
@@ -409,6 +398,18 @@ struct TemplateParameterListBuilder {
409398
return binaryOperator;
410399
}
411400

401+
Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc,
402+
TemplateTypeParmDecl *T) {
403+
clang::ASTContext &context = S.getASTContext();
404+
405+
// first get the "sizeof(T) <= 16" expression, as a binary operator
406+
// TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin
407+
// and return a binary operator that evaluates the builtin on the given
408+
// template type parameter 'T'
409+
BinaryOperator *sizeOfLEQ16 = getSizeOfLEQ16Expr(context, NameLoc, T);
410+
return sizeOfLEQ16;
411+
}
412+
412413
ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl) {
413414
DeclContext *DC = S.CurContext;
414415
clang::ASTContext &context = S.getASTContext();

0 commit comments

Comments
 (0)