Skip to content

Conversation

erichkeane
Copy link
Collaborator

As a followup to the previous AST changes, the next step is to generate the proper expressions in Sema. This patch does so for +,*,&,|,^ by modeling them as compound operators.

This also causes the legality of some expressions to change, as these have to be legal operations, but were previously unchecked, so there are some test changes.

This does not yet generate any CIR, that will happen in the next patch.

As a followup to the previous AST changes, the next step is to generate
the proper expressions in Sema.  This patch does so for +,*,&,|,^ by
modeling them as compound operators.

This also causes the legality of some expressions to change, as these
have to be legal operations, but were previously unchecked, so there are
some test changes.

This does not yet generate any CIR, that will happen in the next patch.
@erichkeane erichkeane requested review from andykaylor and mmha October 9, 2025 21:30
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" ClangIR Anything related to the ClangIR project labels Oct 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Erich Keane (erichkeane)

Changes

As a followup to the previous AST changes, the next step is to generate the proper expressions in Sema. This patch does so for +,*,&,|,^ by modeling them as compound operators.

This also causes the legality of some expressions to change, as these have to be legal operations, but were previously unchecked, so there are some test changes.

This does not yet generate any CIR, that will happen in the next patch.


Patch is 300.54 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/162740.diff

17 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5)
  • (modified) clang/include/clang/Sema/SemaOpenACC.h (+5)
  • (modified) clang/lib/Sema/SemaOpenACC.cpp (+166-1)
  • (modified) clang/lib/Sema/SemaOpenACCClause.cpp (+17-21)
  • (modified) clang/test/CIR/CodeGenOpenACC/combined-reduction-clause-default-ops.cpp (+140-211)
  • (modified) clang/test/CIR/CodeGenOpenACC/combined-reduction-clause-float.cpp (-243)
  • (modified) clang/test/CIR/CodeGenOpenACC/compute-reduction-clause-default-ops.c (+130-187)
  • (modified) clang/test/CIR/CodeGenOpenACC/compute-reduction-clause-default-ops.cpp (+133-204)
  • (modified) clang/test/CIR/CodeGenOpenACC/compute-reduction-clause-float.c (-244)
  • (modified) clang/test/CIR/CodeGenOpenACC/compute-reduction-clause-float.cpp (-243)
  • (modified) clang/test/CIR/CodeGenOpenACC/loop-reduction-clause-default-ops.cpp (+143-214)
  • (modified) clang/test/CIR/CodeGenOpenACC/loop-reduction-clause-float.cpp (-243)
  • (modified) clang/test/SemaOpenACC/combined-construct-reduction-clause.cpp (+6-1)
  • (modified) clang/test/SemaOpenACC/compute-construct-clause-ast.cpp (-27)
  • (modified) clang/test/SemaOpenACC/compute-construct-reduction-clause.c (+15-4)
  • (modified) clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp (+15-1)
  • (modified) clang/test/SemaOpenACC/loop-construct-reduction-ast.cpp (-54)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5be63c027cba7..adc55549ce0d2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13662,6 +13662,11 @@ def warn_acc_var_referenced_lacks_op
               "reference has no effect">,
       InGroup<DiagGroup<"openacc-var-lacks-operation">>,
       DefaultError;
+def err_acc_reduction_recipe_no_op
+    : Error<"variable of type %0 referenced in OpenACC 'reduction' clause does "
+            "not have a valid operation available">;
+def note_acc_reduction_recipe_noop_field
+    : Note<"while forming combiner for compound type %0">;
 
 // AMDGCN builtins diagnostics
 def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;
diff --git a/clang/include/clang/Sema/SemaOpenACC.h b/clang/include/clang/Sema/SemaOpenACC.h
index 09fdf75fbbd09..a411371eb90d9 100644
--- a/clang/include/clang/Sema/SemaOpenACC.h
+++ b/clang/include/clang/Sema/SemaOpenACC.h
@@ -228,6 +228,11 @@ class SemaOpenACC : public SemaBase {
 
   bool DiagnoseAllowedClauses(OpenACCDirectiveKind DK, OpenACCClauseKind CK,
                               SourceLocation ClauseLoc);
+  bool CreateReductionCombinerRecipe(
+      SourceLocation loc, OpenACCReductionOperator ReductionOperator,
+      QualType VarTy,
+      llvm::SmallVectorImpl<OpenACCReductionRecipe::CombinerRecipe>
+          &CombinerRecipes);
 
 public:
   // Needed from the visitor, so should be public.
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 4824b5a3082a4..0fa997e7809b3 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -2898,6 +2898,15 @@ OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe(
           dyn_cast<ArraySectionExpr>(VarExpr->IgnoreParenImpCasts()))
     VarTy = ArraySectionExpr::getBaseOriginalType(ASE);
 
+  llvm::SmallVector<OpenACCReductionRecipe::CombinerRecipe, 1> CombinerRecipes;
+
+  // We use the 'set-ness' of the alloca-decl to determine whether the combiner
+  // is 'set' or not, so we can skip any attempts at it if we're going to fail
+  // at any of the combiners.
+  if (CreateReductionCombinerRecipe(VarExpr->getBeginLoc(), ReductionOperator,
+                                    VarTy, CombinerRecipes))
+    return OpenACCReductionRecipe::Empty();
+
   VarDecl *AllocaDecl = CreateAllocaDecl(
       getASTContext(), SemaRef.getCurContext(), VarExpr->getBeginLoc(),
       &getASTContext().Idents.get("openacc.reduction.init"), VarTy);
@@ -2946,5 +2955,161 @@ OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe(
     AllocaDecl->setInit(Init.get());
     AllocaDecl->setInitStyle(VarDecl::CallInit);
   }
-  return OpenACCReductionRecipe(AllocaDecl, {});
+
+  return OpenACCReductionRecipe(AllocaDecl, CombinerRecipes);
+}
+
+bool SemaOpenACC::CreateReductionCombinerRecipe(
+    SourceLocation Loc, OpenACCReductionOperator ReductionOperator,
+    QualType VarTy,
+    llvm::SmallVectorImpl<OpenACCReductionRecipe::CombinerRecipe>
+        &CombinerRecipes) {
+  // Now we can try to generate the 'combiner' recipe. This is a little
+  // complicated in that if the 'VarTy' is an array type, we want to take its
+  // element type so we can generate that.  Additionally, if this is a struct,
+  // we have two options: If there is overloaded operators, we want to take
+  // THOSE, else we want to do the individual elements.
+
+  BinaryOperatorKind BinOp;
+  switch (ReductionOperator) {
+  case OpenACCReductionOperator::Invalid:
+    // This can only happen when there is an error, and since these inits
+    // are used for code generation, we can just ignore/not bother doing any
+    // initialization here.
+    CombinerRecipes.push_back({nullptr, nullptr, nullptr});
+    return false;
+  case OpenACCReductionOperator::Addition:
+    BinOp = BinaryOperatorKind::BO_AddAssign;
+    break;
+  case OpenACCReductionOperator::Multiplication:
+    BinOp = BinaryOperatorKind::BO_MulAssign;
+    break;
+  case OpenACCReductionOperator::BitwiseAnd:
+    BinOp = BinaryOperatorKind::BO_AndAssign;
+    break;
+  case OpenACCReductionOperator::BitwiseOr:
+    BinOp = BinaryOperatorKind::BO_OrAssign;
+    break;
+  case OpenACCReductionOperator::BitwiseXOr:
+    BinOp = BinaryOperatorKind::BO_XorAssign;
+    break;
+
+  case OpenACCReductionOperator::Max:
+  case OpenACCReductionOperator::Min:
+  case OpenACCReductionOperator::And:
+  case OpenACCReductionOperator::Or:
+    // We just want a 'NYI' error in the backend, so leave an empty combiner
+    // recipe, and claim success.
+    CombinerRecipes.push_back({nullptr, nullptr, nullptr});
+    return false;
+  }
+
+  // If VarTy is an array type, at the top level only, we want to do our
+  // compares/decomp/etc at the element level.
+  if (VarTy->isArrayType())
+    VarTy = QualType{VarTy->getPointeeOrArrayElementType(), 0};
+
+  auto tryCombiner = [&, this](DeclRefExpr *LHSDRE, DeclRefExpr *RHSDRE,
+                               bool IncludeTrap) {
+    // TODO: OpenACC: we have to figure out based on the bin-op how to do the
+    // ones that we can't just use compound operators for.  So &&, ||, max, and
+    // min aren't really clear what we could do here.
+    if (IncludeTrap) {
+      // Trap all of the errors here, we'll emit our own at the end.
+      Sema::TentativeAnalysisScope Trap{SemaRef};
+
+      return SemaRef.BuildBinOp(SemaRef.getCurScope(), Loc, BinOp, LHSDRE,
+                                RHSDRE,
+                                /*ForFoldExpr=*/false);
+    } else {
+      return SemaRef.BuildBinOp(SemaRef.getCurScope(), Loc, BinOp, LHSDRE,
+                                RHSDRE,
+                                /*ForFoldExpr=*/false);
+    }
+  };
+
+  struct CombinerAttemptTy {
+    VarDecl *LHS;
+    DeclRefExpr *LHSDRE;
+    VarDecl *RHS;
+    DeclRefExpr *RHSDRE;
+    Expr *Op;
+  };
+
+  auto formCombiner = [&, this](QualType Ty) -> CombinerAttemptTy {
+    VarDecl *LHSDecl = CreateAllocaDecl(
+        getASTContext(), SemaRef.getCurContext(), Loc,
+        &getASTContext().Idents.get("openacc.reduction.combiner.lhs"), Ty);
+    auto *LHSDRE = DeclRefExpr::Create(
+        getASTContext(), NestedNameSpecifierLoc{}, SourceLocation{}, LHSDecl,
+        /*ReferstoEnclosingVariableOrCapture=*/false,
+        DeclarationNameInfo{DeclarationName{LHSDecl->getDeclName()},
+                            LHSDecl->getBeginLoc()},
+        Ty, clang::VK_LValue, LHSDecl, nullptr, NOUR_None);
+    VarDecl *RHSDecl = CreateAllocaDecl(
+        getASTContext(), SemaRef.getCurContext(), Loc,
+        &getASTContext().Idents.get("openacc.reduction.combiner.lhs"), Ty);
+    auto *RHSDRE = DeclRefExpr::Create(
+        getASTContext(), NestedNameSpecifierLoc{}, SourceLocation{}, RHSDecl,
+        /*ReferstoEnclosingVariableOrCapture=*/false,
+        DeclarationNameInfo{DeclarationName{RHSDecl->getDeclName()},
+                            RHSDecl->getBeginLoc()},
+        Ty, clang::VK_LValue, RHSDecl, nullptr, NOUR_None);
+
+    ExprResult BinOpResult = tryCombiner(LHSDRE, RHSDRE, /*IncludeTrap=*/true);
+
+    return {LHSDecl, LHSDRE, RHSDecl, RHSDRE, BinOpResult.get()};
+  };
+
+  CombinerAttemptTy TopLevelCombinerInfo = formCombiner(VarTy);
+
+  if (TopLevelCombinerInfo.Op) {
+    if (!TopLevelCombinerInfo.Op->containsErrors() &&
+        TopLevelCombinerInfo.Op->isInstantiationDependent()) {
+      // If this is instantiation dependent, we're just going to 'give up' here
+      // and count on us to get it right during instantaition.
+      CombinerRecipes.push_back({nullptr, nullptr, nullptr});
+      return false;
+    } else if (!TopLevelCombinerInfo.Op->containsErrors()) {
+      // Else, we succeeded, we can just return this combiner.
+      CombinerRecipes.push_back({TopLevelCombinerInfo.LHS,
+                                 TopLevelCombinerInfo.RHS,
+                                 TopLevelCombinerInfo.Op});
+      return false;
+    }
+  }
+
+  // Since the 'root' level didn't fail, the only thing that could be successful
+  // is a struct that we decompose on its individual fields.
+
+  RecordDecl *RD = VarTy->getAsRecordDecl();
+  if (!RD) {
+    Diag(Loc, diag::err_acc_reduction_recipe_no_op) << VarTy;
+    tryCombiner(TopLevelCombinerInfo.LHSDRE, TopLevelCombinerInfo.RHSDRE,
+                /*IncludeTrap=*/false);
+    return true;
+  }
+
+  for (const FieldDecl *FD : RD->fields()) {
+    CombinerAttemptTy FieldCombinerInfo = formCombiner(FD->getType());
+
+    if (!FieldCombinerInfo.Op || FieldCombinerInfo.Op->containsErrors()) {
+      Diag(Loc, diag::err_acc_reduction_recipe_no_op) << FD->getType();
+      Diag(FD->getBeginLoc(), diag::note_acc_reduction_recipe_noop_field) << RD;
+      tryCombiner(FieldCombinerInfo.LHSDRE, FieldCombinerInfo.RHSDRE,
+                  /*IncludeTrap=*/false);
+      return true;
+    }
+
+    if (FieldCombinerInfo.Op->isInstantiationDependent()) {
+      // If this is instantiation dependent, we're just going to 'give up' here
+      // and count on us to get it right during instantaition.
+      CombinerRecipes.push_back({nullptr, nullptr, nullptr});
+    } else {
+      CombinerRecipes.push_back(
+          {FieldCombinerInfo.LHS, FieldCombinerInfo.RHS, FieldCombinerInfo.Op});
+    }
+  }
+
+  return false;
 }
diff --git a/clang/lib/Sema/SemaOpenACCClause.cpp b/clang/lib/Sema/SemaOpenACCClause.cpp
index b0869293c1664..fb67950588466 100644
--- a/clang/lib/Sema/SemaOpenACCClause.cpp
+++ b/clang/lib/Sema/SemaOpenACCClause.cpp
@@ -1975,30 +1975,26 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
       Diag(Loc, PD);
 
     Diag(VarLoc, diag::note_acc_reduction_type_summary);
+    return ExprError();
   };
 
   // If the type is already scalar, or is dependent, just give up.
   if (IsValidMemberOfComposite(CurType)) {
     // Nothing to do here, is valid.
   } else if (auto *RD = CurType->getAsRecordDecl()) {
-    if (!RD->isStruct() && !RD->isClass()) {
-      EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
-                            << RD << diag::OACCReductionTy::NotClassStruct);
-      return ExprError();
-    }
+    if (!RD->isStruct() && !RD->isClass())
+      return EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
+                                   << RD
+                                   << diag::OACCReductionTy::NotClassStruct);
 
-    if (!RD->isCompleteDefinition()) {
-      EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
-                            << RD << diag::OACCReductionTy::NotComplete);
-      return ExprError();
-    }
+    if (!RD->isCompleteDefinition())
+      return EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
+                                   << RD << diag::OACCReductionTy::NotComplete);
 
     if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
-        CXXRD && !CXXRD->isAggregate()) {
-      EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
-                            << CXXRD << diag::OACCReductionTy::NotAgg);
-      return ExprError();
-    }
+        CXXRD && !CXXRD->isAggregate())
+      return EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
+                                   << CXXRD << diag::OACCReductionTy::NotAgg);
 
     for (FieldDecl *FD : RD->fields()) {
       if (!IsValidMemberOfComposite(FD->getType())) {
@@ -2007,15 +2003,15 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
             << FD->getName() << RD->getName();
         Notes.push_back({FD->getBeginLoc(), PD});
         // TODO: member here.note_acc_reduction_member_of_composite
-        EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
-                              << FD->getType()
-                              << diag::OACCReductionTy::MemberNotScalar);
-        return ExprError();
+        return EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
+                                     << FD->getType()
+                                     << diag::OACCReductionTy::MemberNotScalar);
       }
     }
   } else {
-    EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
-                          << CurType << diag::OACCReductionTy::NotScalar);
+    return EmitDiags(VarLoc, PDiag(diag::err_acc_reduction_type)
+                                 << CurType
+                                 << diag::OACCReductionTy::NotScalar);
   }
 
   // OpenACC3.3: 2.9.11: Reduction clauses on nested constructs for the same
diff --git a/clang/test/CIR/CodeGenOpenACC/combined-reduction-clause-default-ops.cpp b/clang/test/CIR/CodeGenOpenACC/combined-reduction-clause-default-ops.cpp
index 7b74b7cee1e75..040ddd3ca458c 100644
--- a/clang/test/CIR/CodeGenOpenACC/combined-reduction-clause-default-ops.cpp
+++ b/clang/test/CIR/CodeGenOpenACC/combined-reduction-clause-default-ops.cpp
@@ -8,12 +8,19 @@ struct DefaultOperators {
   bool b;
 };
 
+struct DefaultOperatorsNoFloats {
+  int i;
+  unsigned int u;
+  bool b;
+};
+
 template<typename T>
 void acc_combined() {
   T someVar;
   T someVarArr[5];
+  struct DefaultOperatorsNoFloats someVarNoFloats;
+  struct DefaultOperatorsNoFloats someVarArrNoFloats[5];
 #pragma acc parallel loop reduction(+:someVar)
-  for(int i=0;i < 5; ++i);
 // CHECK: acc.reduction.recipe @reduction_add__ZTS16DefaultOperators : !cir.ptr<!rec_DefaultOperators> reduction_operator <add> init {
 // CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr<!rec_DefaultOperators>{{.*}})
 // CHECK-NEXT: %[[ALLOCA:.*]] = cir.alloca !rec_DefaultOperators, !cir.ptr<!rec_DefaultOperators>, ["openacc.reduction.init", init]
@@ -39,6 +46,7 @@ void acc_combined() {
 // TODO OpenACC: Expecting combination operation here
 // CHECK-NEXT: acc.yield %[[LHSARG]] : !cir.ptr<!rec_DefaultOperators>
 // CHECK-NEXT: }
+  for(int i=0;i < 5; ++i);
 #pragma acc parallel loop reduction(*:someVar)
 
 // CHECK-NEXT: acc.reduction.recipe @reduction_mul__ZTS16DefaultOperators : !cir.ptr<!rec_DefaultOperators> reduction_operator <mul> init {
@@ -121,86 +129,67 @@ void acc_combined() {
 // CHECK-NEXT: acc.yield %[[LHSARG]] : !cir.ptr<!rec_DefaultOperators>
 // CHECK-NEXT: }
   for(int i=0;i < 5; ++i);
-#pragma acc parallel loop reduction(&:someVar)
-
-// CHECK-NEXT: acc.reduction.recipe @reduction_iand__ZTS16DefaultOperators : !cir.ptr<!rec_DefaultOperators> reduction_operator <iand> init {
-// CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr<!rec_DefaultOperators>{{.*}})
-// CHECK-NEXT: %[[ALLOCA:.*]] = cir.alloca !rec_DefaultOperators, !cir.ptr<!rec_DefaultOperators>, ["openacc.reduction.init", init]
-// CHECK-NEXT: %[[GET_I:.*]] = cir.get_member %[[ALLOCA]][0] {name = "i"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!s32i>
+#pragma acc parallel loop reduction(&:someVarNoFloats)
+// CHECK-NEXT: acc.reduction.recipe @reduction_iand__ZTS24DefaultOperatorsNoFloats : !cir.ptr<!rec_DefaultOperatorsNoFloats> reduction_operator <iand> init {
+// CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr<!rec_DefaultOperatorsNoFloats>{{.*}})
+// CHECK-NEXT: %[[ALLOCA:.*]] = cir.alloca !rec_DefaultOperatorsNoFloats, !cir.ptr<!rec_DefaultOperatorsNoFloats>, ["openacc.reduction.init", init]
+// CHECK-NEXT: %[[GET_I:.*]] = cir.get_member %[[ALLOCA]][0] {name = "i"} : !cir.ptr<!rec_DefaultOperatorsNoFloats> -> !cir.ptr<!s32i>
 // CHECK-NEXT: %[[ALL_ONES:.*]] = cir.const #cir.int<-1> : !s32i
 // CHECK-NEXT: cir.store {{.*}} %[[ALL_ONES]], %[[GET_I]] : !s32i, !cir.ptr<!s32i>
-// CHECK-NEXT: %[[GET_U:.*]] = cir.get_member %[[ALLOCA]][1] {name = "u"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!u32i>
+// CHECK-NEXT: %[[GET_U:.*]] = cir.get_member %[[ALLOCA]][1] {name = "u"} : !cir.ptr<!rec_DefaultOperatorsNoFloats> -> !cir.ptr<!u32i>
 // CHECK-NEXT: %[[ALL_ONES:.*]] = cir.const #cir.int<4294967295> : !u32i
 // CHECK-NEXT: cir.store {{.*}} %[[ALL_ONES]], %[[GET_U]] : !u32i, !cir.ptr<!u32i>
-// CHECK-NEXT: %[[GET_F:.*]] = cir.get_member %[[ALLOCA]][2] {name = "f"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!cir.float>
-// CHECK-NEXT: %[[ALL_ONES:.*]] = cir.const #cir.fp<0xFF{{.*}}> : !cir.float
-// CHECK-NEXT: cir.store {{.*}} %[[ALL_ONES]], %[[GET_F]] : !cir.float, !cir.ptr<!cir.float>
-// CHECK-NEXT: %[[GET_D:.*]] = cir.get_member %[[ALLOCA]][3] {name = "d"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!cir.double>
-// CHECK-NEXT: %[[ALL_ONES:.*]] = cir.const #cir.fp<0xFF{{.*}}> : !cir.double
-// CHECK-NEXT: cir.store {{.*}} %[[ALL_ONES]], %[[GET_D]] : !cir.double, !cir.ptr<!cir.double>
-// CHECK-NEXT: %[[GET_B:.*]] = cir.get_member %[[ALLOCA]][4] {name = "b"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!cir.bool>
+// CHECK-NEXT: %[[GET_B:.*]] = cir.get_member %[[ALLOCA]][2] {name = "b"} : !cir.ptr<!rec_DefaultOperatorsNoFloats> -> !cir.ptr<!cir.bool>
 // CHECK-NEXT: %[[ALL_ONES:.*]] = cir.const #true
 // CHECK-NEXT: cir.store {{.*}} %[[ALL_ONES]], %[[GET_B]] : !cir.bool, !cir.ptr<!cir.bool>
 // CHECK-NEXT: acc.yield
 //
 // CHECK-NEXT: } combiner {
-// CHECK-NEXT: ^bb0(%[[LHSARG:.*]]: !cir.ptr<!rec_DefaultOperators> {{.*}}, %[[RHSARG:.*]]: !cir.ptr<!rec_DefaultOperators> {{.*}})
+// CHECK-NEXT: ^bb0(%[[LHSARG:.*]]: !cir.ptr<!rec_DefaultOperatorsNoFloats> {{.*}}, %[[RHSARG:.*]]: !cir.ptr<!rec_DefaultOperatorsNoFloats> {{.*}})
 // TODO OpenACC: Expecting combination operation here
-// CHECK-NEXT: acc.yield %[[LHSARG]] : !cir.ptr<!rec_DefaultOperators>
+// CHECK-NEXT: acc.yield %[[LHSARG]] : !cir.ptr<!rec_DefaultOperatorsNoFloats>
 // CHECK-NEXT: }
-  for(int i=0;i < 5; ++i);
-#pragma acc parallel loop reduction(|:someVar)
-// CHECK-NEXT: acc.reduction.recipe @reduction_ior__ZTS16DefaultOperators : !cir.ptr<!rec_DefaultOperators> reduction_operator <ior> init {
-// CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr<!rec_DefaultOperators>{{.*}})
-// CHECK-NEXT: %[[ALLOCA:.*]] = cir.alloca !rec_DefaultOperators, !cir.ptr<!rec_DefaultOperators>, ["openacc.reduction.init", init]
-// CHECK-NEXT: %[[GET_I:.*]] = cir.get_member %[[ALLOCA]][0] {name = "i"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!s32i>
+  for(int i = 0; i < 5; ++i);
+#pragma acc parallel loop reduction(|:someVarNoFloats)
+// CHECK-NEXT: acc.reduction.recipe @reduction_ior__ZTS24DefaultOperatorsNoFloats : !cir.ptr<!rec_DefaultOperatorsNoFloats> reduction_operator <ior> init {
+// CHECK-NEXT: ^bb0(%[[ARG:.*]]: !cir.ptr<!rec_DefaultOperatorsNoFloats>{{.*}})
+// CHECK-NEXT: %[[ALLOCA:.*]] = cir.alloca !rec_DefaultOperatorsNoFloats, !cir.ptr<!rec_DefaultOperatorsNoFloats>, ["openacc.reduction.init", init]
+// CHECK-NEXT: %[[GET_I:.*]] = cir.get_member %[[ALLOCA]][0] {name = "i"} : !cir.ptr<!rec_DefaultOperatorsNoFloats> -> !cir.ptr<!s32i>
 // CHECK-NEXT: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i
 // CHECK-NEXT: cir.store {{.*}} %[[ZERO]], %[[GET_I]] : !s32i, !cir.ptr<!s32i>
-// CHECK-NEXT: %[[GET_U:.*]] = cir.get_member %[[ALLOCA]][1] {name = "u"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!u32i>
+// CHECK-NEXT: %[[GET_U:.*]] = cir.get_member %[[ALLOCA]][1] {name = "u"} : !cir.ptr<!rec_DefaultOperatorsNoFloats> -> !cir.ptr<!u32i>
 // CHECK-NEXT: %[[ZERO:.*]] = cir.const #cir.int<0> : !u32i
 // CHECK-NEXT: cir.store {{.*}} %[[ZERO]], %[[GET_U]] : !u32i, !cir.ptr<!u32i>
-// CHECK-NEXT: %[[GET_F:.*]] = cir.get_member %[[ALLOCA]][2] {name = "f"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!cir.float>
-// CHECK-NEXT: %[[ZERO:.*]] = cir.const #cir.fp<0{{.*}}> : !cir.float
-// CHECK-NEXT: cir.store {{.*}} %[[ZERO]], %[[GET_F]] : !cir.float, !cir.ptr<!cir.float>
-// CHECK-NEXT: %[[GET_D:.*]] = cir.get_member %[[ALLOCA]][3] {name = "d"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!cir.double>
-// CHECK-NEXT: %[[ZERO:.*]] = cir.const #cir.fp<0{{.*}}> : !cir.double
-// CHECK-NEXT: cir.store {{.*}} %[[ZERO]], %[[GET_D]] : !cir.double, !cir.ptr<!cir.double>
-// CHECK-NEXT: %[[GET_B:.*]] = cir.get_member %[[ALLOCA]][4] {name = "b"} : !cir.ptr<!rec_DefaultOperators> -> !cir.ptr<!cir.bool>
+// CHECK-NEXT: %[[GET_B:.*]] = cir.get_member %[[ALLOCA]][2] {name = "b"} : !cir.ptr<!rec_DefaultOperatorsNoFloats> -> !cir.ptr<!cir.bool>
 // CHECK-NEXT: %[[ZERO:.*]] = cir.const #false
 // CHECK-NEXT: cir.store {{.*}} %[[ZERO]], %[[GET_B]] : !cir.bool, !cir.ptr<!cir.bool>
 // CHECK-NEXT: acc.yield
 //
 // CHECK-NEXT: } combiner {
-// CHECK-NEXT: ^bb0(%[[LHSARG:.*]]: !cir.ptr<!rec_DefaultOperators> {{.*}}, %[[RHSARG:.*]]: !cir.ptr<!rec_DefaultOperators> {{.*}})
+// CHECK-NEXT: ^bb0(%[[LHSARG:.*]]: !cir.ptr<!r...
[truncated]

Copy link
Contributor

@andykaylor andykaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

// If VarTy is an array type, at the top level only, we want to do our
// compares/decomp/etc at the element level.
if (VarTy->isArrayType())
VarTy = QualType{VarTy->getPointeeOrArrayElementType(), 0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if this is a multi-dimensional array you want the lowest level element type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but only 1 level :) Only 1 level of arrays are allowed elsewhere in Sema. I should probably replace this with a single-unwrap + an assert though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops! I made the same problem in the Sema checking as well! So I'll push another patch to fix this, then update this to do the right thing. Thanks!

@erichkeane
Copy link
Collaborator Author

This will actually have about 20 tests that crash now with the new assert. I am quite sure I have been messing up my uses of Array Section functions in quite a few places, so I have to put this on pause until I've figured out what I'm doing/what the right way to do stuff with this is.

@erichkeane erichkeane enabled auto-merge (squash) October 10, 2025 19:09
@erichkeane erichkeane merged commit 6010df0 into llvm:main Oct 10, 2025
9 of 10 checks passed
@thurstond
Copy link
Contributor

I think this may have broken a buildbot (https://lab.llvm.org/buildbot/#/builders/55/builds/18467/steps/11/logs/stdio):

FAIL: Clang :: SemaOpenACC/loop-construct-reduction-clause.cpp (22104 of 91237)
******************** TEST 'Clang :: SemaOpenACC/loop-construct-reduction-clause.cpp' FAILED ********************
Exit Code: 134
Command Output (stderr):
--
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify # RUN: at line 1
+ /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify
libc++abi: Pure virtual function called!
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/SemaOpenACC/Output/loop-construct-reduction-clause.cpp.script: line 1: 3724937 Aborted                 /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify

@erichkeane
Copy link
Collaborator Author

Yikes, you're probably right! Though I've got no clue with that error message... You wouldn't happen to have seen something like that in the past, would you?

@erichkeane
Copy link
Collaborator Author

erichkeane commented Oct 10, 2025

I think this may have broken a buildbot (https://lab.llvm.org/buildbot/#/builders/55/builds/18467/steps/11/logs/stdio):

FAIL: Clang :: SemaOpenACC/loop-construct-reduction-clause.cpp (22104 of 91237)
******************** TEST 'Clang :: SemaOpenACC/loop-construct-reduction-clause.cpp' FAILED ********************
Exit Code: 134
Command Output (stderr):
--
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify # RUN: at line 1
+ /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify
libc++abi: Pure virtual function called!
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/SemaOpenACC/Output/loop-construct-reduction-clause.cpp.script: line 1: 3724937 Aborted                 /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify

Upon further reflection, with it being friday and EOD, I'm just going to revert (added auto-revert) here: #162920

ANY feedback on how to repro/etc would be very much appreciated though, thats an error type i haven't seen before.

erichkeane added a commit to erichkeane/llvm-project that referenced this pull request Oct 10, 2025
…lvm#162740)"

This reverts commit 6010df0.

This apparently fails some sanitizer test as reported here:
llvm#162740

It isn't really clear where this happens, but reverting as it is a
friday, and I have no idea if I'll be able to repro this anytime soon,
  let alone fix it.
erichkeane added a commit that referenced this pull request Oct 10, 2025
#162920)

…#162740)"

This reverts commit 6010df0.

This apparently fails some sanitizer test as reported here:
#162740

It isn't really clear where this happens, but reverting as it is a
friday, and I have no idea if I'll be able to repro this anytime soon,
  let alone fix it.
@thurstond
Copy link
Contributor

Upon further reflection, with it being friday and EOD, I'm just going to revert (added auto-revert) here: #162920

Thanks for the quick revert!

ANY feedback on how to repro/etc would be very much appreciated though, thats an error type i haven't seen before.

The buildbot can be reproduced with the instructions at https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

replacing the example command with your revision and the relevant bot type (HWASan):

BUILDBOT_REVISION=6010df0402e2f5cca0ded446a70492dedc43ab7e llvm-zorg/zorg/buildbot/builders/sanitizers/buildbot_bootstrap_hwasan.sh

Note that HWASan requires an Arm machine.

@erichkeane
Copy link
Collaborator Author

Upon further reflection, with it being friday and EOD, I'm just going to revert (added auto-revert) here: #162920

Thanks for the quick revert!

ANY feedback on how to repro/etc would be very much appreciated though, thats an error type i haven't seen before.

The buildbot can be reproduced with the instructions at https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

replacing the example command with your revision and the relevant bot type (HWASan):

BUILDBOT_REVISION=6010df0402e2f5cca0ded446a70492dedc43ab7e llvm-zorg/zorg/buildbot/builders/sanitizers/buildbot_bootstrap_hwasan.sh

Note that HWASan requires an Arm machine.

Hmm... I don't really have the ability to get an ARM machine, but I saw a similar (though slightly different?) sansi-build failure with an x86-64 machine, so maybe I'll get lucky.,

Thanks!

@thurstond
Copy link
Contributor

Though I've got no clue with that error message... You wouldn't happen to have seen something like that in the past, would you?

I haven't seen it before.

I'll try to spin up a bot and see if there's more output.

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 10, 2025
…r recipes (… (#162920)

…#162740)"

This reverts commit 6010df0.

This apparently fails some sanitizer test as reported here:
llvm/llvm-project#162740

It isn't really clear where this happens, but reverting as it is a
friday, and I have no idea if I'll be able to repro this anytime soon,
  let alone fix it.
@thurstond
Copy link
Contributor

When I ran the buildbot script, I did reproduce the scary libc++abi: Pure virtual function called! message:

******************** TEST 'Clang :: SemaOpenACC/loop-construct-reduction-clause.cpp' FAILED ********************
Exit Code: 134

Command Output (stderr):
--
/home/thurston/buildbot_repro/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/thurston/buildbot_repro/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/thurston/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify # RUN: at line 1
+ /home/thurston/buildbot_repro/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/thurston/buildbot_repro/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/thurston/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify
libc++abi: Pure virtual function called!
/home/thurston/buildbot_repro/llvm_build_hwasan/tools/clang/test/SemaOpenACC/Output/loop-construct-reduction-clause.cpp.script: line 1: 1815580 Aborted                 /home/thurston/buildbot_repro/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/thurston/buildbot_repro/llvm_build_hwasan/lib/clang/22/include -nostdsysteminc /home/thurston/llvm-project/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp -fopenacc -verify

--

but when I tried running the test command, all I get are memory leaks (which are still worth fixing, but doesn't explain the "pure virtual function" error):

Direct leak of 120 byte(s) in 1 object(s) allocated from:
    #0 0xc7425bb0c970 in malloc /home/thurston/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:147:3
    #1 0xc74262a23140 in safe_malloc /home/thurston/llvm-project/llvm/include/llvm/Support/MemAlloc.h:26:18
    #2 0xc74262a23140 in llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long) /home/thurston/llvm-project/llvm/lib/Support/SmallVector.cpp:151:15
    #3 0xc742681d4be0 in grow_pod /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:139:11
    #4 0xc742681d4be0 in grow /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:525:41
    #5 0xc742681d4be0 in llvm::SmallVectorImpl<clang::OpenACCReductionRecipe::CombinerRecipe>::operator=(llvm::SmallVectorImpl<clang::OpenACCReductionRecipe::CombinerRecipe> const&) /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1036:11
    #6 0xc7426a5ed960 in SmallVector /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1238:27
    #7 0xc7426a5ed960 in OpenACCReductionRecipe /home/thurston/llvm-project/clang/include/clang/AST/OpenACCClause.h:1281:8
    #8 0xc7426a5ed960 in __uninitialized_copy<clang::OpenACCReductionRecipe, const clang::OpenACCReductionRecipe *, const clang::OpenACCReductionRecipe *, clang::OpenACCReductionRecipe *, std::__1::__always_false> /home/thurston/buildbot_repro/libcxx_install_hwasan/include/c++/v1/__memory/uninitialized_algorithms.h:66:56
    #9 0xc7426a5ed960 in uninitialized_copy<const clang::OpenACCReductionRecipe *, clang::OpenACCReductionRecipe *> /home/thurston/buildbot_repro/libcxx_install_hwasan/include/c++/v1/__memory/uninitialized_algorithms.h:76:19
    #10 0xc7426a5ed960 in uninitialized_copy<llvm::ArrayRef<clang::OpenACCReductionRecipe> &, clang::OpenACCReductionRecipe *> /home/thurston/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2056:10
    #11 0xc7426a5ed960 in clang::OpenACCReductionClause::OpenACCReductionClause(clang::SourceLocation, clang::SourceLocation, clang::OpenACCReductionOperator, llvm::ArrayRef<clang::Expr*>, llvm::ArrayRef<clang::OpenACCReductionRecipe>, clang::SourceLocation) /home/thurston/llvm-project/clang/include/clang/AST/OpenACCClause.h:1328:5
    #12 0xc7426a5ed3f0 in clang::OpenACCReductionClause::Create(clang::ASTContext const&, clang::SourceLocation, clang::SourceLocation, clang::OpenACCReductionOperator, llvm::ArrayRef<clang::Expr*>, llvm::ArrayRef<clang::OpenACCReductionRecipe>, clang::SourceLocation) /home/thurston/llvm-project/clang/lib/AST/OpenACCClause.cpp:514:20
    #13 0xc742689f1254 in clang::SemaOpenACC::CheckReductionClause(llvm::ArrayRef<clang::OpenACCClause const*>, clang::OpenACCDirectiveKind, clang::SourceLocation, clang::SourceLocation, clang::OpenACCReductionOperator, llvm::ArrayRef<clang::Expr*>, llvm::ArrayRef<clang::OpenACCReductionRecipe>, clang::SourceLocation) /home/thurston/llvm-project/clang/lib/Sema/SemaOpenACCClause.cpp:2228:15
    #14 0xc74269143240 in VisitReductionClause /home/thurston/llvm-project/clang/lib/Sema/TreeTransform.h:12394:40
    #15 0xc74269143240 in Visit /home/thurston/llvm-project/clang/include/clang/Basic/OpenACCClauses.def:65:1
    #16 0xc74269143240 in TransformOpenACCClause /home/thurston/llvm-project/clang/lib/Sema/TreeTransform.h:12491:13
    #17 0xc74269143240 in clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformOpenACCClauseList(clang::OpenACCDirectiveKind, llvm::ArrayRef<clang::OpenACCClause const*>) /home/thurston/llvm-project/clang/lib/Sema/TreeTransform.h:12502:57
    #18 0xc742691276d8 in clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformOpenACCLoopConstruct(clang::OpenACCLoopConstruct*) /home/thurston/llvm-project/clang/lib/Sema/TreeTransform.h:12542:20
    #19 0xc742690f1224 in clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) /home/thurston/llvm-project/clang/lib/Sema/TreeTransform.h:8028:38
    #20 0xc74269128a88 in clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformOpenACCComputeConstruct(clang::OpenACCComputeConstruct*) /home/thurston/llvm-project/clang/lib/Sema/TreeTransform.h:12526:38
    #21 0xc742690f1224 in clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) /home/thurston/llvm-project/clang/lib/Sema/TreeTransform.h:8028:38
    #22 0xc742690bb578 in clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) /home/thurston/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:4418:23
    #23 0xc7426919cef4 in clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) /home/thurston/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5892:14
    #24 0xc742691a6180 in clang::Sema::PerformPendingInstantiations(bool, bool) /home/thurston/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:7150:9
    #25 0xc74267e60b80 in clang::Sema::ActOnEndOfTranslationUnitFragment(clang::TUFragmentKind) /home/thurston/llvm-project/clang/lib/Sema/Sema.cpp:1221:5
    #26 0xc74267e618d8 in clang::Sema::ActOnEndOfTranslationUnit() /home/thurston/llvm-project/clang/lib/Sema/Sema.cpp:1245:5
    #27 0xc74267af9644 in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/thurston/llvm-project/clang/lib/Parse/Parser.cpp:712:13
    #28 0xc74267ad9ef8 in clang::ParseAST(clang::Sema&, bool, bool) /home/thurston/llvm-project/clang/lib/Parse/ParseAST.cpp:170:20
    #29 0xc742647cbef0 in clang::FrontendAction::Execute() /home/thurston/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1311:3
    #30 0xc74264687a18 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/thurston/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1008:33

Direct leak of 120 byte(s) in 1 object(s) allocated from:
    #0 0xc7425bb0c970 in malloc /home/thurston/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:147:3
    #1 0xc74262a23140 in safe_malloc /home/thurston/llvm-project/llvm/include/llvm/Support/MemAlloc.h:26:18
    #2 0xc74262a23140 in llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long) /home/thurston/llvm-project/llvm/lib/Support/SmallVector.cpp:151:15
    #3 0xc742681d4be0 in grow_pod /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:139:11
    #4 0xc742681d4be0 in grow /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:525:41
    #5 0xc742681d4be0 in llvm::SmallVectorImpl<clang::OpenACCReductionRecipe::CombinerRecipe>::operator=(llvm::SmallVectorImpl<clang::OpenACCReductionRecipe::CombinerRecipe> const&) /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1036:11
    #6 0xc7426a5ed960 in SmallVector /home/thurston/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1238:27
    #7 0xc7426a5ed960 in OpenACCReductionRecipe /home/thurston/llvm-project/clang/include/clang/AST/OpenACCClause.h:1281:8
    #8 0xc7426a5ed960 in __uninitialized_copy<clang::OpenACCReductionRecipe, const clang::OpenACCReductionRecipe *, const clang::OpenACCReductionRecipe *, clang::OpenACCReductionRecipe *, std::__1::__always_false> /home/thurston/buildbot_repro/libcxx_install_hwasan/include/c++/v1/__memory/uninitialized_algorithms.h:66:56
    #9 0xc7426a5ed960 in uninitialized_copy<const clang::OpenACCReductionRecipe *, clang::OpenACCReductionRecipe *> /home/thurston/buildbot_repro/libcxx_install_hwasan/include/c++/v1/__memory/uninitialized_algorithms.h:76:19
    #10 0xc7426a5ed960 in uninitialized_copy<llvm::ArrayRef<clang::OpenACCReductionRecipe> &, clang::OpenACCReductionRecipe *> /home/thurston/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2056:10
    #11 0xc7426a5ed960 in clang::OpenACCReductionClause::OpenACCReductionClause(clang::SourceLocation, clang::SourceLocation, clang::OpenACCReductionOperator, llvm::ArrayRef<clang::Expr*>, llvm::ArrayRef<clang::OpenACCReductionRecipe>, clang::SourceLocation) /home/thurston/llvm-project/clang/include/clang/AST/OpenACCClause.h:1328:5
    #12 0xc7426a5ed3f0 in clang::OpenACCReductionClause::Create(clang::ASTContext const&, clang::SourceLocation, clang::SourceLocation, clang::OpenACCReductionOperator, llvm::ArrayRef<clang::Expr*>, llvm::ArrayRef<clang::OpenACCReductionRecipe>, clang::SourceLocation) /home/thurston/llvm-project/clang/lib/AST/OpenACCClause.cpp:514:20
    #13 0xc742689f1254 in clang::SemaOpenACC::CheckReductionClause(llvm::ArrayRef<clang::OpenACCClause const*>, clang::OpenACCDirectiveKind, clang::SourceLocation, clang::SourceLocation, clang::OpenACCReductionOperator, llvm::ArrayRef<clang::Expr*>, llvm::ArrayRef<clang::OpenACCReductionRecipe>, clang::SourceLocation) /home/thurston/llvm-project/clang/lib/Sema/SemaOpenACCClause.cpp:2228:15
    #14 0xc74268a136ac in (anonymous namespace)::SemaOpenACCClauseVisitor::VisitReductionClause(clang::SemaOpenACC::OpenACCParsedClause&) /home/thurston/llvm-project/clang/lib/Sema/SemaOpenACCClause.cpp:1789:18
    #15 0xc742689eb0c8 in Visit /home/thurston/llvm-project/clang/include/clang/Basic/OpenACCClauses.def:65:1
    #16 0xc742689eb0c8 in clang::SemaOpenACC::ActOnClause(llvm::ArrayRef<clang::OpenACCClause const*>, clang::SemaOpenACC::OpenACCParsedClause&) /home/thurston/llvm-project/clang/lib/Sema/SemaOpenACCClause.cpp:1911:35
    #17 0xc74267d3ac80 in clang::Parser::ParseOpenACCClauseParams(llvm::ArrayRef<clang::OpenACCClause const*>, clang::OpenACCDirectiveKind, clang::OpenACCClauseKind, clang::SourceLocation) /home/thurston/llvm-project/clang/lib/Parse/ParseOpenACC.cpp:1266:25
    #18 0xc74267d35244 in clang::Parser::ParseOpenACCClauseList(clang::OpenACCDirectiveKind) /home/thurston/llvm-project/clang/lib/Parse/ParseOpenACC.cpp:747:39
    #19 0xc74267d436ac in clang::Parser::ParseOpenACCDirective() /home/thurston/llvm-project/clang/lib/Parse/ParseOpenACC.cpp:1576:23
    #20 0xc74267d44c58 in clang::Parser::ParseOpenACCDirectiveStmt() /home/thurston/llvm-project/clang/lib/Parse/ParseOpenACC.cpp:1671:39
    #21 0xc74267ca3ea8 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:466:12
    #22 0xc74267ca14e0 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:77:20
    #23 0xc74267cbb3c0 in clang::Parser::ParseCompoundStatementBody(bool) /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:1168:11
    #24 0xc74267cc1788 in operator() /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:968:9
    #25 0xc74267cc1788 in void llvm::function_ref<void ()>::callback_fn<clang::Parser::ParseCompoundStatement(bool, unsigned int)::$_0>(long) /home/thurston/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
    #26 0xc7426407ae58 in operator() /home/thurston/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
    #27 0xc7426407ae58 in runWithSufficientStackSpace /home/thurston/llvm-project/clang/include/clang/Basic/Stack.h:49:7
    #28 0xc7426407ae58 in clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) /home/thurston/llvm-project/clang/lib/Basic/StackExhaustionHandler.cpp:20:3
    #29 0xc74267ca5158 in ParseCompoundStatement /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:967:16
    #30 0xc74267ca5158 in ParseCompoundStatement /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:953:10
    #31 0xc74267ca5158 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:275:12
    #32 0xc74267ca14e0 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:77:20
    #33 0xc74267ca10ec in clang::Parser::ParseStatement(clang::SourceLocation*, clang::Parser::ParsedStmtContext, clang::LabelDecl*) /home/thurston/llvm-project/clang/lib/Parse/ParseStmt.cpp:48:11

SUMMARY: HWAddressSanitizer: 240 byte(s) leaked in 2 allocation(s).

(The x86 ASan bot [https://lab.llvm.org/buildbot/#/builders/52/builds/11843] is also able to reproduce the leaks.)

@erichkeane
Copy link
Collaborator Author

Hmm... those are strange leaks. I set up a sans build based on the script you sent before I quit for the day. I'll take a look monday. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants