@@ -1057,26 +1057,51 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
1057
1057
Expr *Arg = Exprs[0 ];
1058
1058
#ifdef ENABLE_SPIRV_CODEGEN
1059
1059
if (hlsl::IsVKBufferPointerType (Ty) && Arg->getType ()->isIntegerType ()) {
1060
- for (auto *ctor : Ty->getAsCXXRecordDecl ()->ctors ()) {
1061
- if (auto *functionType = ctor->getType ()->getAs <FunctionProtoType>()) {
1062
- if (functionType->getNumParams () != 1 ||
1063
- !functionType->getParamType (0 )->isIntegerType ())
1064
- continue ;
1065
-
1066
- CanQualType argType = Arg->getType ()->getCanonicalTypeUnqualified ();
1067
- if (!Arg->isRValue ()) {
1068
- Arg = ImpCastExprToType (Arg, argType, CK_LValueToRValue).get ();
1069
- }
1070
- if (argType != Context.UnsignedLongLongTy ) {
1071
- Arg = ImpCastExprToType (Arg, Context.UnsignedLongLongTy ,
1072
- CK_IntegralCast)
1073
- .get ();
1074
- }
1075
- return CXXConstructExpr::Create (
1076
- Context, Ty, TyBeginLoc, ctor, false , {Arg}, false , false , false ,
1077
- false , CXXConstructExpr::ConstructionKind::CK_Complete,
1078
- SourceRange (LParenLoc, RParenLoc));
1060
+ typedef DeclContext::specific_decl_iterator<FunctionTemplateDecl> ft_iter;
1061
+ auto *recordDecl = Ty->getAsCXXRecordDecl ();
1062
+ auto *specDecl = cast<ClassTemplateSpecializationDecl>(recordDecl);
1063
+ auto *templatedDecl =
1064
+ specDecl->getSpecializedTemplate ()->getTemplatedDecl ();
1065
+ auto functionTemplateDecls =
1066
+ llvm::iterator_range<ft_iter>(ft_iter (templatedDecl->decls_begin ()),
1067
+ ft_iter (templatedDecl->decls_end ()));
1068
+ for (auto *ftd : functionTemplateDecls) {
1069
+ auto *fd = ftd->getTemplatedDecl ();
1070
+ if (fd->getNumParams () != 1 ||
1071
+ !fd->getParamDecl (0 )->getType ()->isIntegerType ())
1072
+ continue ;
1073
+
1074
+ void *insertPos;
1075
+ auto templateArgs = ftd->getInjectedTemplateArgs ();
1076
+ auto *functionDecl = ftd->findSpecialization (templateArgs, insertPos);
1077
+ if (!functionDecl) {
1078
+ DeclarationNameInfo DInfo (ftd->getDeclName (),
1079
+ recordDecl->getLocation ());
1080
+ auto *templateArgList = TemplateArgumentList::CreateCopy (
1081
+ Context, templateArgs.data (), templateArgs.size ());
1082
+ functionDecl = CXXConstructorDecl::Create (
1083
+ Context, recordDecl, Arg->getLocStart (), DInfo, Ty, TInfo, false ,
1084
+ false , false , false );
1085
+ functionDecl->setFunctionTemplateSpecialization (ftd, templateArgList,
1086
+ insertPos);
1087
+ } else if (functionDecl->getDeclKind () != Decl::Kind::CXXConstructor) {
1088
+ continue ;
1089
+ }
1090
+
1091
+ CanQualType argType = Arg->getType ()->getCanonicalTypeUnqualified ();
1092
+ if (!Arg->isRValue ()) {
1093
+ Arg = ImpCastExprToType (Arg, argType, CK_LValueToRValue).get ();
1094
+ }
1095
+ if (argType != Context.UnsignedLongLongTy ) {
1096
+ Arg = ImpCastExprToType (Arg, Context.UnsignedLongLongTy ,
1097
+ CK_IntegralCast)
1098
+ .get ();
1079
1099
}
1100
+ return CXXConstructExpr::Create (
1101
+ Context, Ty, TyBeginLoc, cast<CXXConstructorDecl>(functionDecl),
1102
+ false , {Arg}, false , false , false , false ,
1103
+ CXXConstructExpr::ConstructionKind::CK_Complete,
1104
+ SourceRange (LParenLoc, RParenLoc));
1080
1105
}
1081
1106
}
1082
1107
#endif
0 commit comments