================
@@ -6344,12 +6345,27 @@ ExprResult 
Sema::PerformImplicitObjectArgumentInitialization(
   QualType FromRecordType, DestType;
   QualType ImplicitParamRecordType = Method->getFunctionObjectParameterType();
 
+  LangAS FromAS = From->getType().getAddressSpace();
   if (getLangOpts().HLSL &&
-      From->getType().getAddressSpace() == LangAS::hlsl_constant) {
+      (FromAS == LangAS::hlsl_constant ||
+       (FromAS == LangAS::hlsl_groupshared && Method->isConst()))) {
     QualType CastType = From->getType().getLocalUnqualifiedType().withConst();
     From = ImplicitCastExpr::Create(Context, CastType, CK_LValueToRValue, From,
                                     /*BasePath=*/nullptr, VK_PRValue,
                                     FPOptionsOverride());
+  } else if (getLangOpts().HLSL && FromAS == LangAS::hlsl_groupshared) {
+    ASTContext &Ctx = SemaRef.getASTContext();
+    QualType Ty = From->getType().getLocalUnqualifiedType();
+    ExprResult Res =
+        SemaRef.HLSL()
+            .CreateOutArgExprHelper(From, Ty, Ty,
+                                    InitializedEntity::InitializeTemporary(
+                                        Ty.getNonLValueExprType(Ctx)),
+                                    From->getBeginLoc(), /*IsInOut=*/true)
+            .get();
----------------
hekota wrote:

Nit - it would be easier to read if the entity initialization is moved out of 
the arguments.
And is the `.get()` at the end necessary?

```suggestion
    InitializedEntity TmpEntity =
        InitializedEntity::InitializeTemporary(Ty.getNonLValueExprType(Ctx));
    ExprResult Res =
        SemaRef.HLSL()
            .CreateOutArgExprHelper(From, Ty, Ty, TmpEntity,
                                    From->getBeginLoc(), /*IsInOut=*/true);
```

https://github.com/llvm/llvm-project/pull/229939
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to