================
@@ -609,6 +621,44 @@ BuiltinTypeMethodBuilder::declareLocalVar(LocalVar &Var) {
   return *this;
 }
 
+template <typename V, typename S>
+BuiltinTypeMethodBuilder &BuiltinTypeMethodBuilder::concat(V Vec, S Scalar,
+                                                           QualType ResultTy) {
+  ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
+  Expr *VecExpr = convertPlaceholder(Vec);
+  auto *VecTy = VecExpr->getType()->castAs<VectorType>();
+  Expr *ScalarExpr = convertPlaceholder(Scalar);
+
+  // Save the vector to a local variable to avoid evaluating the placeholder
+  // multiple times or sharing the AST node.
+  LocalVar VecVar("vec_tmp", VecTy->desugar());
+  declareLocalVar(VecVar);
+  assign(VecVar, VecExpr);
+
+  QualType EltTy = VecTy->getElementType();
+  unsigned NumElts = VecTy->getNumElements();
+
+  SmallVector<Expr *, 4> Elts;
+  for (unsigned I = 0; I < NumElts; ++I) {
+    Elts.push_back(new (AST) ArraySubscriptExpr(
+        convertPlaceholder(VecVar), DeclBuilder.getConstantIntExpr(I), EltTy,
+        VK_PRValue, OK_Ordinary, SourceLocation()));
+  }
+  Elts.push_back(ScalarExpr);
+
+  auto *InitList =
+      new (AST) InitListExpr(AST, SourceLocation(), Elts, SourceLocation());
+  InitList->setType(ResultTy);
+
+  ExprResult Cast = DeclBuilder.SemaRef.BuildCStyleCastExpr(
----------------
Keenuts wrote:

Should thsi assert ResultTy is a vector type? Or should this even build a 
vector directly instead of doing a c-style cast?

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

Reply via email to