@@ -267,9 +267,9 @@ CGHLSLRuntime::convertHLSLSpecificType(const Type *T,
267267 assert (T->isHLSLSpecificType () && " Not an HLSL specific type!" );
268268
269269 // Check if the target has a specific translation for this type first.
270- if (llvm::Type *LayoutTy =
270+ if (llvm::Type *TargetTy =
271271 CGM.getTargetCodeGenInfo ().getHLSLType (CGM, T, OffsetInfo))
272- return LayoutTy ;
272+ return TargetTy ;
273273
274274 llvm_unreachable (" Generic handling of HLSL types is not supported." );
275275}
@@ -326,9 +326,10 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(
326326 DeclsWithOffset.emplace_back (VD, OffsetInfo[OffsetIdx++]);
327327 }
328328
329- llvm::stable_sort (DeclsWithOffset, [](const auto &LHS, const auto &RHS) {
330- return CGHLSLOffsetInfo::compareOffsets (LHS.second , RHS.second );
331- });
329+ if (!OffsetInfo.empty ())
330+ llvm::stable_sort (DeclsWithOffset, [](const auto &LHS, const auto &RHS) {
331+ return CGHLSLOffsetInfo::compareOffsets (LHS.second , RHS.second );
332+ });
332333
333334 // Associate the buffer global variable with its constants
334335 SmallVector<llvm::Metadata *> BufGlobals;
@@ -1148,7 +1149,7 @@ std::optional<LValue> CGHLSLRuntime::emitBufferArraySubscriptExpr(
11481149 // be past the end of the in-memory object.
11491150 SmallVector<llvm::Value *, 2 > Indices;
11501151 Indices.push_back (Idx);
1151- Indices.push_back (llvm::ConstantInt::get (Indices[ 0 ] ->getType (), 0 ));
1152+ Indices.push_back (llvm::ConstantInt::get (Idx ->getType (), 0 ));
11521153
11531154 llvm::Value *GEP = CGF.Builder .CreateGEP (LayoutTy, Addr.emitRawPointer (CGF),
11541155 Indices, " cbufferidx" );
@@ -1319,8 +1320,9 @@ LValue CGHLSLRuntime::emitBufferMemberExpr(CodeGenFunction &CGF,
13191320 // Work out the buffer layout type to index into.
13201321 QualType RecType = CGM.getContext ().getCanonicalTagType (Rec);
13211322 assert (RecType->isStructureOrClassType () && " Invalid type in HLSL buffer" );
1322- // Since this is a member of the buffer and not the buffer itself, we
1323- // shouldn't have any offsets we need to contend with.
1323+ // Since this is a member of an object in the buffer and not the buffer's
1324+ // struct/class itself, we shouldn't have any offsets on the members we need
1325+ // to contend with.
13241326 CGHLSLOffsetInfo EmptyOffsets;
13251327 llvm::StructType *LayoutTy = HLSLBufferLayoutBuilder (CGM).layOutStruct (
13261328 RecType->getAsCanonical <RecordType>(), EmptyOffsets);
0 commit comments