summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a837f0073274..f2451b16e78b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4641,11 +4641,17 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
LHS.getBaseInfo(), TBAAAccessInfo());
}
- // The HLSL runtime handle the subscript expression on global resource arrays.
- if (getLangOpts().HLSL && (E->getType()->isHLSLResourceRecord() ||
- E->getType()->isHLSLResourceRecordArray())) {
- std::optional<LValue> LV =
- CGM.getHLSLRuntime().emitResourceArraySubscriptExpr(E, *this);
+ // The HLSL runtime handles subscript expressions on global resource arrays
+ // and objects with HLSL buffer layouts.
+ if (getLangOpts().HLSL) {
+ std::optional<LValue> LV;
+ if (E->getType()->isHLSLResourceRecord() ||
+ E->getType()->isHLSLResourceRecordArray()) {
+ LV = CGM.getHLSLRuntime().emitResourceArraySubscriptExpr(E, *this);
+ } else if (E->getType().getAddressSpace() == LangAS::hlsl_constant) {
+ LV = CGM.getHLSLRuntime().emitBufferArraySubscriptExpr(E, *this,
+ EmitIdxAfterBase);
+ }
if (LV.has_value())
return *LV;
}
@@ -5110,6 +5116,11 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
EmitIgnoredExpr(E->getBase());
return EmitDeclRefLValue(DRE);
}
+ if (getLangOpts().HLSL &&
+ E->getType().getAddressSpace() == LangAS::hlsl_constant) {
+ // We have an HLSL buffer - emit using HLSL's layout rules.
+ return CGM.getHLSLRuntime().emitBufferMemberExpr(*this, E);
+ }
Expr *BaseExpr = E->getBase();
// Check whether the underlying base pointer is a constant null.