@@ -812,6 +812,7 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
812812 " indexing of array subsets it not supported yet" );
813813
814814 // get the resource array type
815+ ASTContext &AST = ArrayDecl->getASTContext ();
815816 const Type *ResArrayTy = ArrayDecl->getType ().getTypePtr ();
816817 assert (ResArrayTy->isHLSLResourceRecordArray () &&
817818 " expected array of resource classes" );
@@ -821,44 +822,39 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
821822 // dimensional array). The index is calculated as a sum of all indices
822823 // multiplied by the total size of the array at that level.
823824 Value *Index = nullptr ;
824- Value *Multiplier = nullptr ;
825825 const ArraySubscriptExpr *ASE = ArraySubsExpr;
826826 while (ASE != nullptr ) {
827827 Value *SubIndex = CGF.EmitScalarExpr (ASE->getIdx ());
828828 if (const auto *ArrayTy =
829829 dyn_cast<ConstantArrayType>(ASE->getType ().getTypePtr ())) {
830- Value *SubMultiplier =
831- llvm::ConstantInt::get (CGM.IntTy , ArrayTy->getSExtSize ());
832- Multiplier = Multiplier ? CGF.Builder .CreateMul (Multiplier, SubMultiplier)
833- : SubMultiplier;
830+ Value *Multiplier = llvm::ConstantInt::get (
831+ CGM.IntTy , AST.getConstantArrayElementCount (ArrayTy));
834832 SubIndex = CGF.Builder .CreateMul (SubIndex, Multiplier);
835833 }
836834
837835 Index = Index ? CGF.Builder .CreateAdd (Index, SubIndex) : SubIndex;
838836 ASE = dyn_cast<ArraySubscriptExpr>(ASE->getBase ()->IgnoreParenImpCasts ());
839837 }
840838
841- // find binding info for the resource array
842- // (for implicit binding an HLSLResourceBindingAttr should have been added by
843- // SemaHLSL)
839+ // find binding info for the resource array (for implicit binding
840+ // an HLSLResourceBindingAttr should have been added by SemaHLSL)
844841 QualType ResourceTy = ArraySubsExpr->getType ();
845842 HLSLVkBindingAttr *VkBinding = ArrayDecl->getAttr <HLSLVkBindingAttr>();
846843 HLSLResourceBindingAttr *RBA = ArrayDecl->getAttr <HLSLResourceBindingAttr>();
847844 assert ((VkBinding || RBA) && " resource array must have a binding attribute" );
848845
849846 // lookup the resource class constructor based on the resource type and
850847 // binding
851- ASTContext &AST = ArrayDecl->getASTContext ();
852848 CXXConstructorDecl *CD = findResourceConstructorDecl (
853849 AST, ResourceTy, VkBinding || RBA->hasRegisterSlot ());
854850
855851 // create a temporary variable for the resource class instance (we need to
856852 // return an LValue)
857853 RawAddress TmpVar = CGF.CreateMemTemp (ResourceTy);
858- if (CGF.EmitLifetimeStart (TmpVar.getPointer ())) {
854+ if (CGF.EmitLifetimeStart (TmpVar.getPointer ()))
859855 CGF.pushFullExprCleanup <CodeGenFunction::CallLifetimeEnd>(
860856 NormalEHLifetimeMarker, TmpVar);
861- }
857+
862858 AggValueSlot ValueSlot = AggValueSlot::forAddr (
863859 TmpVar, Qualifiers (), AggValueSlot::IsDestructed_t (true ),
864860 AggValueSlot::DoesNotNeedGCBarriers, AggValueSlot::IsAliased_t (false ),
0 commit comments