================
@@ -10524,6 +10524,11 @@ Sema::PerformCopyInitialization(const 
InitializedEntity &Entity,
   Expr *InitE = Init.get();
   assert(InitE && "No initialization expression?");
 
+  if (LangOpts.HLSL)
+    if (auto AdjTy = dyn_cast<DecayedType>(Entity.getType()))
+      if (AdjTy->getOriginalType()->isConstantArrayType())
+        InitE = HLSLArrayTemporaryExpr::Create(getASTContext(), InitE);
----------------
efriedma-quic wrote:

This implementation is surprising.  If arrays are supposed to be passed by 
value, decay shouldn't be happening in the first place.

Allowing decay to happen, then trying to fix it up later, has some weird 
implications: for example, `void f(int[2])` and `void f(int[4])` have the same 
type.  You introduce pointer types in places where they shouldn't really exist, 
and casts which aren't really supposed to happen.  And it's not clear to me the 
non-canonical type wrapper will be preserved in all the cases you need 
(preserving non-canonical types is best-effort; sometimes we're forced to 
canonicalize).

As an alternative approach, maybe we can introduce a new type to represent a 
"function argument of array type".  When we construct the function type, 
instead of decaying to a pointer, it would "decay" to "function argument of 
array type". The result is sort of similar, but instead of a non-canonical 
DecayedType, you have a canonical type which would be reliably preserved across 
the compiler.  For argument passing, initialization would work similarly to 
what you're doing now.

https://github.com/llvm/llvm-project/pull/79382
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to