================
@@ -6250,13 +6250,102 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
   return false;
 }
 
+static bool isWin32InAllocaRecord(ASTContext &Context, QualType Ty) {
+  const RecordType *RT = Ty->getAs<RecordType>();
+  if (!RT)
+    return false;
+  const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
+  if (!RD)
+    return false;
+
+  const llvm::Triple &Triple = Context.getTargetInfo().getTriple();
+  if (Triple.getArch() != llvm::Triple::x86 || !Triple.isOSWindows())
+    return false;
+  if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
+    return false;
+
+  if (RD->canPassInRegisters())
+    return false;
+
+  TypeInfo Info = Context.getTypeInfo(Context.getCanonicalTagType(RD));
+  if (Info.isAlignRequired() && Info.Align > 4)
+    return false; // passed indirectly
+
+  return true;
+}
+
+static bool callHasSuspend(Sema &S, ArrayRef<Expr *> Args) {
+  if (S.getCurFunction() && S.getCurFunction()->isCoroutine()) {
+    for (const Expr *A : Args) {
+      if (A && A->containsCoroutineSuspendPoints())
+        return true;
+    }
+  }
+  return false;
+}
+
+static bool usesInAlloca(ASTContext &Context, const FunctionProtoType *Proto,
+                         ArrayRef<Expr *> Args) {
+  unsigned NumParams = Proto->getNumParams();
+  for (unsigned i = 0; i < NumParams; i++) {
+    if (isWin32InAllocaRecord(Context, Proto->getParamType(i)))
+      return true;
+  }
+  if (Proto->isVariadic()) {
+    for (size_t i = NumParams; i < Args.size(); i++) {
+      if (Args[i] && isWin32InAllocaRecord(Context, Args[i]->getType()))
+        return true;
+    }
+  }
+  return false;
+}
+
+static void disableCopyElision(Expr *E) {
+  if (auto *EWC = dyn_cast<ExprWithCleanups>(E))
+    E = EWC->getSubExpr();
+  if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E))
+    E = BTE->getSubExpr();
+  if (auto *CCE = dyn_cast<CXXConstructExpr>(E)) {
+    if (CCE->isElidable())
+      CCE->setElidable(false);
+  }
+}
+
+static ExprResult InitializeAndBypassArg(Sema &S,
+                                         const InitializedEntity &Entity,
+                                         Expr *Arg, bool IsListInitialization,
+                                         bool AllowExplicit) {
+  ExprResult Materialized =
+      S.CreateMaterializeTemporaryExpr(Arg->getType(), Arg, false);
+  if (Materialized.isInvalid())
+    return ExprError();
+  Expr *PreBypassArg = Materialized.get();
+
+  ExprResult ArgE =
+      S.PerformCopyInitialization(Entity, SourceLocation(), PreBypassArg,
----------------
etiennep-chromium wrote:

Done, I think that makes disableCopyElision unnecessary.

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

Reply via email to