[clang] [llvm] [OpenMP][OMPIRBuilder] Handle non-failing calls properly (PR #115863)

Sergio Afonso via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 12 04:49:34 PST 2024


https://github.com/skatrak created https://github.com/llvm/llvm-project/pull/115863

The preprocessor definition used to enable asserts and the one that `llvm::Error` and `llvm::Expected` use to ensure all created instances are checked are not the same. By making these checks inside of an `assert` in cases where errors are not expected, certain build configurations would trigger runtime failures.

The `llvm::cantFail()` function, which was intended for this use case, is used by this patch in place of `assert` to prevent these runtime failures.

>From 7584acb9d88a2e778c6c35652225c4202acf8529 Mon Sep 17 00:00:00 2001
From: Sergio Afonso <safonsof at amd.com>
Date: Tue, 12 Nov 2024 12:41:15 +0000
Subject: [PATCH] [OpenMP][OMPIRBuilder] Handle non-failing calls properly

The macro used to enable asserts and the one that `llvm::Error` and
`llvm::Expected` use to ensure all created instances are checked are not the
same. By making these checks inside of an `assert` in cases where errors are
not expected, certain build configurations would trigger runtime failures.

The `llvm::cantFail()` function, which was intended for this use case, is used
by this patch in place of `assert` to prevent these runtime failures.
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp         |  32 +-
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp      |   9 +-
 clang/lib/CodeGen/CGStmtOpenMP.cpp            |  88 ++-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp     |  32 +-
 llvm/lib/Transforms/IPO/OpenMPOpt.cpp         |  32 +-
 .../Frontend/OpenMPIRBuilderTest.cpp          | 635 ++++++++----------
 6 files changed, 353 insertions(+), 475 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index d714af035d21a2..9c22103a1a75c6 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2332,11 +2332,10 @@ void CGOpenMPRuntime::emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
   auto *OMPRegionInfo =
       dyn_cast_or_null<CGOpenMPRegionInfo>(CGF.CapturedStmtInfo);
   if (CGF.CGM.getLangOpts().OpenMPIRBuilder) {
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPBuilder.createBarrier(CGF.Builder, Kind, ForceSimpleCall,
-                                 EmitChecks);
-    assert(AfterIP && "unexpected error creating barrier");
-    CGF.Builder.restoreIP(*AfterIP);
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+        cantFail(OMPBuilder.createBarrier(CGF.Builder, Kind, ForceSimpleCall,
+                                          EmitChecks));
+    CGF.Builder.restoreIP(AfterIP);
     return;
   }
 
@@ -5932,10 +5931,9 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
         return CGF.GenerateOpenMPCapturedStmtFunction(CS, D.getBeginLoc());
       };
 
-  llvm::Error Err = OMPBuilder.emitTargetRegionFunction(
+  cantFail(OMPBuilder.emitTargetRegionFunction(
       EntryInfo, GenerateOutlinedFunction, IsOffloadEntry, OutlinedFn,
-      OutlinedFnID);
-  assert(!Err && "unexpected error creating target region");
+      OutlinedFnID));
 
   if (!OutlinedFn)
     return;
@@ -9676,12 +9674,11 @@ static void emitTargetCallKernelLaunch(
         NumTargetItems, RTArgs, NumIterations, NumTeams, NumThreads,
         DynCGGroupMem, HasNoWait);
 
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPRuntime->getOMPBuilder().emitKernelLaunch(
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+        cantFail(OMPRuntime->getOMPBuilder().emitKernelLaunch(
             CGF.Builder, OutlinedFnID, EmitTargetCallFallbackCB, Args, DeviceID,
-            RTLoc, AllocaIP);
-    assert(AfterIP && "unexpected error creating kernel launch");
-    CGF.Builder.restoreIP(*AfterIP);
+            RTLoc, AllocaIP));
+    CGF.Builder.restoreIP(AfterIP);
   };
 
   if (RequiresOuterTask)
@@ -10358,12 +10355,11 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
                           CGF.Builder.GetInsertPoint());
   llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
-  llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createTargetData(
+  llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createTargetData(
           OmpLoc, AllocaIP, CodeGenIP, DeviceID, IfCondVal, Info, GenMapInfoCB,
-          /*MapperFunc=*/nullptr, BodyCB, DeviceAddrCB, CustomMapperCB, RTLoc);
-  assert(AfterIP && "unexpected error creating target data");
-  CGF.Builder.restoreIP(*AfterIP);
+          /*MapperFunc=*/nullptr, BodyCB, DeviceAddrCB, CustomMapperCB, RTLoc));
+  CGF.Builder.restoreIP(AfterIP);
 }
 
 void CGOpenMPRuntime::emitTargetDataStandAloneCall(
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 598b946ad88dbb..a794175060e41c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1753,14 +1753,13 @@ void CGOpenMPRuntimeGPU::emitReduction(
     Idx++;
   }
 
-  llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createReductionsGPU(
+  llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createReductionsGPU(
           OmpLoc, AllocaIP, CodeGenIP, ReductionInfos, false, TeamsReduction,
           DistributeReduction, llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
           CGF.getTarget().getGridValue(),
-          C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc);
-  assert(AfterIP && "unexpected error creating GPU reductions");
-  CGF.Builder.restoreIP(*AfterIP);
+          C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc));
+  CGF.Builder.restoreIP(AfterIP);
   return;
 }
 
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 390516fea38498..ad1453ddbaaec2 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1839,11 +1839,10 @@ void CodeGenFunction::EmitOMPParallelDirective(const OMPParallelDirective &S) {
     CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
     llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
         AllocaInsertPt->getParent(), AllocaInsertPt->getIterator());
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
         OMPBuilder.createParallel(Builder, AllocaIP, BodyGenCB, PrivCB, FiniCB,
-                                  IfCond, NumThreads, ProcBind, S.hasCancel());
-    assert(AfterIP && "unexpected error creating parallel");
-    Builder.restoreIP(*AfterIP);
+                                  IfCond, NumThreads, ProcBind, S.hasCancel()));
+    Builder.restoreIP(AfterIP);
     return;
   }
 
@@ -2135,10 +2134,8 @@ void CodeGenFunction::EmitOMPCanonicalLoop(const OMPCanonicalLoop *S) {
     return llvm::Error::success();
   };
 
-  llvm::Expected<llvm::CanonicalLoopInfo *> Result =
-      OMPBuilder.createCanonicalLoop(Builder, BodyGen, DistVal);
-  assert(Result && "unexpected error creating canonical loop");
-  llvm::CanonicalLoopInfo *CL = *Result;
+  llvm::CanonicalLoopInfo *CL =
+      cantFail(OMPBuilder.createCanonicalLoop(Builder, BodyGen, DistVal));
 
   // Finish up the loop.
   Builder.restoreIP(CL->getAfterIP());
@@ -4024,13 +4021,11 @@ static void emitOMPForDirective(const OMPLoopDirective &S, CodeGenFunction &CGF,
           CGM.getOpenMPRuntime().getOMPBuilder();
       llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
           CGF.AllocaInsertPt->getParent(), CGF.AllocaInsertPt->getIterator());
-      llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-          OMPBuilder.applyWorkshareLoop(
-              CGF.Builder.getCurrentDebugLocation(), CLI, AllocaIP,
-              NeedsBarrier, SchedKind, ChunkSize, /*HasSimdModifier=*/false,
-              /*HasMonotonicModifier=*/false, /*HasNonmonotonicModifier=*/false,
-              /*HasOrderedClause=*/false);
-      assert(AfterIP && "unexpected error creating workshare loop");
+      cantFail(OMPBuilder.applyWorkshareLoop(
+          CGF.Builder.getCurrentDebugLocation(), CLI, AllocaIP, NeedsBarrier,
+          SchedKind, ChunkSize, /*HasSimdModifier=*/false,
+          /*HasMonotonicModifier=*/false, /*HasNonmonotonicModifier=*/false,
+          /*HasOrderedClause=*/false));
       return;
     }
 
@@ -4311,12 +4306,11 @@ void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &S) {
     CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(*this, &CGSI);
     llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
         AllocaInsertPt->getParent(), AllocaInsertPt->getIterator());
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPBuilder.createSections(Builder, AllocaIP, SectionCBVector, PrivCB,
-                                  FiniCB, S.hasCancel(),
-                                  S.getSingleClause<OMPNowaitClause>());
-    assert(AfterIP && "unexpected error creating sections");
-    Builder.restoreIP(*AfterIP);
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+        cantFail(OMPBuilder.createSections(
+            Builder, AllocaIP, SectionCBVector, PrivCB, FiniCB, S.hasCancel(),
+            S.getSingleClause<OMPNowaitClause>()));
+    Builder.restoreIP(AfterIP);
     return;
   }
   {
@@ -4354,10 +4348,9 @@ void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &S) {
 
     LexicalScope Scope(*this, S.getSourceRange());
     EmitStopPoint(&S);
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPBuilder.createSection(Builder, BodyGenCB, FiniCB);
-    assert(AfterIP && "unexpected error creating section");
-    Builder.restoreIP(*AfterIP);
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+        cantFail(OMPBuilder.createSection(Builder, BodyGenCB, FiniCB));
+    Builder.restoreIP(AfterIP);
 
     return;
   }
@@ -4440,10 +4433,9 @@ void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) {
 
     LexicalScope Scope(*this, S.getSourceRange());
     EmitStopPoint(&S);
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPBuilder.createMaster(Builder, BodyGenCB, FiniCB);
-    assert(AfterIP && "unexpected error creating master");
-    Builder.restoreIP(*AfterIP);
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+        cantFail(OMPBuilder.createMaster(Builder, BodyGenCB, FiniCB));
+    Builder.restoreIP(AfterIP);
 
     return;
   }
@@ -4491,10 +4483,9 @@ void CodeGenFunction::EmitOMPMaskedDirective(const OMPMaskedDirective &S) {
 
     LexicalScope Scope(*this, S.getSourceRange());
     EmitStopPoint(&S);
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPBuilder.createMasked(Builder, BodyGenCB, FiniCB, FilterVal);
-    assert(AfterIP && "unexpected error creating masked");
-    Builder.restoreIP(*AfterIP);
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
+        OMPBuilder.createMasked(Builder, BodyGenCB, FiniCB, FilterVal));
+    Builder.restoreIP(AfterIP);
 
     return;
   }
@@ -4535,11 +4526,11 @@ void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) {
 
     LexicalScope Scope(*this, S.getSourceRange());
     EmitStopPoint(&S);
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPBuilder.createCritical(Builder, BodyGenCB, FiniCB,
-                                  S.getDirectiveName().getAsString(), HintInst);
-    assert(AfterIP && "unexpected error creating critical");
-    Builder.restoreIP(*AfterIP);
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+        cantFail(OMPBuilder.createCritical(Builder, BodyGenCB, FiniCB,
+                                           S.getDirectiveName().getAsString(),
+                                           HintInst));
+    Builder.restoreIP(AfterIP);
 
     return;
   }
@@ -5503,10 +5494,9 @@ void CodeGenFunction::EmitOMPTaskgroupDirective(
     CodeGenFunction::CGCapturedStmtInfo CapStmtInfo;
     if (!CapturedStmtInfo)
       CapturedStmtInfo = &CapStmtInfo;
-    llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-        OMPBuilder.createTaskgroup(Builder, AllocaIP, BodyGenCB);
-    assert(AfterIP && "unexpected error creating taskgroup");
-    Builder.restoreIP(*AfterIP);
+    llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
+        cantFail(OMPBuilder.createTaskgroup(Builder, AllocaIP, BodyGenCB));
+    Builder.restoreIP(AfterIP);
     return;
   }
   auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) {
@@ -6109,10 +6099,9 @@ void CodeGenFunction::EmitOMPOrderedDirective(const OMPOrderedDirective &S) {
       };
 
       OMPLexicalScope Scope(*this, S, OMPD_unknown);
-      llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-          OMPBuilder.createOrderedThreadsSimd(Builder, BodyGenCB, FiniCB, !C);
-      assert(AfterIP && "unexpected error creating ordered");
-      Builder.restoreIP(*AfterIP);
+      llvm::OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
+          OMPBuilder.createOrderedThreadsSimd(Builder, BodyGenCB, FiniCB, !C));
+      Builder.restoreIP(AfterIP);
     }
     return;
   }
@@ -7388,10 +7377,9 @@ void CodeGenFunction::EmitOMPCancelDirective(const OMPCancelDirective &S) {
       if (IfCond)
         IfCondition = EmitScalarExpr(IfCond,
                                      /*IgnoreResultAssign=*/true);
-      llvm::OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-          OMPBuilder.createCancel(Builder, IfCondition, S.getCancelRegion());
-      assert(AfterIP && "unexpected error creating cancel");
-      return Builder.restoreIP(*AfterIP);
+      llvm::OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
+          OMPBuilder.createCancel(Builder, IfCondition, S.getCancelRegion()));
+      return Builder.restoreIP(AfterIP);
     }
   }
 
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index d2e4dc1c85dfd2..5d9a7784d9e68c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4225,7 +4225,11 @@ OpenMPIRBuilder::applyStaticChunkedWorkshareLoop(DebugLoc DL,
   // Create outer "dispatch" loop for enumerating the chunks.
   BasicBlock *DispatchEnter = splitBB(Builder, true);
   Value *DispatchCounter;
-  Expected<CanonicalLoopInfo *> LoopResult = createCanonicalLoop(
+
+  // It is safe to assume this didn't return an error because the callback
+  // passed into createCanonicalLoop is the only possible error source, and it
+  // always returns success.
+  CanonicalLoopInfo *DispatchCLI = cantFail(createCanonicalLoop(
       {Builder.saveIP(), DL},
       [&](InsertPointTy BodyIP, Value *Counter) {
         DispatchCounter = Counter;
@@ -4233,15 +4237,7 @@ OpenMPIRBuilder::applyStaticChunkedWorkshareLoop(DebugLoc DL,
       },
       FirstChunkStart, CastedTripCount, NextChunkStride,
       /*IsSigned=*/false, /*InclusiveStop=*/false, /*ComputeIP=*/{},
-      "dispatch");
-  if (!LoopResult) {
-    // It is safe to assume this didn't return an error because the callback
-    // passed into createCanonicalLoop is the only possible error source, and it
-    // always returns success. Need to still cast the result into bool to avoid
-    // runtime errors.
-    llvm_unreachable("unexpected error creating canonical loop");
-  }
-  CanonicalLoopInfo *DispatchCLI = *LoopResult;
+      "dispatch"));
 
   // Remember the BasicBlocks of the dispatch loop we need, then invalidate to
   // not have to preserve the canonical invariant.
@@ -6542,16 +6538,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
       };
 
       bool RequiresOuterTargetTask = Info.HasNoWait;
-      if (!RequiresOuterTargetTask) {
-        Error Err = TaskBodyCB(/*DeviceID=*/nullptr, /*RTLoc=*/nullptr,
-                               /*TargetTaskAllocaIP=*/{});
-        assert(!Err && "TaskBodyCB expected to succeed");
-      } else {
-        InsertPointOrErrorTy AfterIP =
-            emitTargetTask(TaskBodyCB, DeviceID, SrcLocInfo, AllocaIP,
-                           /*Dependencies=*/{}, Info.HasNoWait);
-        assert(AfterIP && "TaskBodyCB expected to succeed");
-      }
+      if (!RequiresOuterTargetTask)
+        cantFail(TaskBodyCB(/*DeviceID=*/nullptr, /*RTLoc=*/nullptr,
+                            /*TargetTaskAllocaIP=*/{}));
+      else
+        cantFail(emitTargetTask(TaskBodyCB, DeviceID, SrcLocInfo, AllocaIP,
+                                /*Dependencies=*/{}, Info.HasNoWait));
     } else {
       Function *BeginMapperFunc = getOrCreateRuntimeFunctionPtr(
           omp::OMPRTL___tgt_target_data_begin_mapper);
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 9e25620710fc84..153f5c7510efae 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -1178,15 +1178,12 @@ struct OpenMPOpt {
 
       OpenMPIRBuilder::LocationDescription Loc(
           InsertPointTy(ParentBB, ParentBB->end()), DL);
-      OpenMPIRBuilder::InsertPointOrErrorTy SeqAfterIP =
-          OMPInfoCache.OMPBuilder.createMaster(Loc, BodyGenCB, FiniCB);
-      assert(SeqAfterIP && "Unexpected error creating master");
+      OpenMPIRBuilder::InsertPointTy SeqAfterIP = cantFail(
+          OMPInfoCache.OMPBuilder.createMaster(Loc, BodyGenCB, FiniCB));
+      cantFail(
+          OMPInfoCache.OMPBuilder.createBarrier(SeqAfterIP, OMPD_parallel));
 
-      OpenMPIRBuilder::InsertPointOrErrorTy BarrierAfterIP =
-          OMPInfoCache.OMPBuilder.createBarrier(*SeqAfterIP, OMPD_parallel);
-      assert(BarrierAfterIP && "Unexpected error creating barrier");
-
-      BranchInst::Create(SeqAfterBB, SeqAfterIP->getBlock());
+      BranchInst::Create(SeqAfterBB, SeqAfterIP.getBlock());
 
       LLVM_DEBUG(dbgs() << TAG << "After sequential inlining " << *OuterFn
                         << "\n");
@@ -1256,12 +1253,11 @@ struct OpenMPOpt {
           OriginalFn->getEntryBlock().getFirstInsertionPt());
       // Create the merged parallel region with default proc binding, to
       // avoid overriding binding settings, and without explicit cancellation.
-      OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-          OMPInfoCache.OMPBuilder.createParallel(
+      OpenMPIRBuilder::InsertPointTy AfterIP =
+          cantFail(OMPInfoCache.OMPBuilder.createParallel(
               Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB, nullptr, nullptr,
-              OMP_PROC_BIND_default, /* IsCancellable */ false);
-      assert(AfterIP && "Unexpected error creating parallel");
-      BranchInst::Create(AfterBB, AfterIP->getBlock());
+              OMP_PROC_BIND_default, /* IsCancellable */ false));
+      BranchInst::Create(AfterBB, AfterIP.getBlock());
 
       // Perform the actual outlining.
       OMPInfoCache.OMPBuilder.finalize(OriginalFn);
@@ -1297,12 +1293,10 @@ struct OpenMPOpt {
         if (CI != MergableCIs.back()) {
           // TODO: Remove barrier if the merged parallel region includes the
           // 'nowait' clause.
-          OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-              OMPInfoCache.OMPBuilder.createBarrier(
-                  InsertPointTy(NewCI->getParent(),
-                                NewCI->getNextNode()->getIterator()),
-                  OMPD_parallel);
-          assert(AfterIP && "Unexpected error creating barrier");
+          cantFail(OMPInfoCache.OMPBuilder.createBarrier(
+              InsertPointTy(NewCI->getParent(),
+                            NewCI->getNextNode()->getIterator()),
+              OMPD_parallel));
         }
 
         CI->eraseFromParent();
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index 630cd03c688012..dfdb5d69501ed4 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -235,10 +235,9 @@ class OpenMPIRBuilderTest : public testing::Test {
 
       return Error::success();
     };
-    Expected<CanonicalLoopInfo *> LoopResult =
-        OMPBuilder.createCanonicalLoop(Loc, LoopBodyGenCB, CastedTripCount);
-    assert(LoopResult && "unexpected error");
-    CanonicalLoopInfo *Loop = *LoopResult;
+
+    CanonicalLoopInfo *Loop = cantFail(
+        OMPBuilder.createCanonicalLoop(Loc, LoopBodyGenCB, CastedTripCount));
 
     // Finalize the function.
     Builder.restoreIP(Loop->getAfterIP());
@@ -345,18 +344,14 @@ TEST_F(OpenMPIRBuilderTest, CreateBarrier) {
 
   IRBuilder<> Builder(BB);
 
-  OpenMPIRBuilder::InsertPointOrErrorTy BarrierIP1 =
-      OMPBuilder.createBarrier({IRBuilder<>::InsertPoint()}, OMPD_for);
-  assert(BarrierIP1 && "unexpected error");
+  cantFail(OMPBuilder.createBarrier({IRBuilder<>::InsertPoint()}, OMPD_for));
   EXPECT_TRUE(M->global_empty());
   EXPECT_EQ(M->size(), 1U);
   EXPECT_EQ(F->size(), 1U);
   EXPECT_EQ(BB->size(), 0U);
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP()});
-  OpenMPIRBuilder::InsertPointOrErrorTy BarrierIP2 =
-      OMPBuilder.createBarrier(Loc, OMPD_for);
-  assert(BarrierIP2 && "unexpected error");
+  cantFail(OMPBuilder.createBarrier(Loc, OMPD_for));
   EXPECT_FALSE(M->global_empty());
   EXPECT_EQ(M->size(), 3U);
   EXPECT_EQ(F->size(), 1U);
@@ -399,10 +394,9 @@ TEST_F(OpenMPIRBuilderTest, CreateCancel) {
   IRBuilder<> Builder(BB);
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP()});
-  OpenMPIRBuilder::InsertPointOrErrorTy NewIP =
-      OMPBuilder.createCancel(Loc, nullptr, OMPD_parallel);
-  assert(NewIP && "unexpected error");
-  Builder.restoreIP(*NewIP);
+  OpenMPIRBuilder::InsertPointTy NewIP =
+      cantFail(OMPBuilder.createCancel(Loc, nullptr, OMPD_parallel));
+  Builder.restoreIP(NewIP);
   EXPECT_FALSE(M->global_empty());
   EXPECT_EQ(M->size(), 4U);
   EXPECT_EQ(F->size(), 4U);
@@ -424,7 +418,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancel) {
   EXPECT_EQ(Cancel->getNumUses(), 1U);
   Instruction *CancelBBTI = Cancel->getParent()->getTerminator();
   EXPECT_EQ(CancelBBTI->getNumSuccessors(), 2U);
-  EXPECT_EQ(CancelBBTI->getSuccessor(0), NewIP->getBlock());
+  EXPECT_EQ(CancelBBTI->getSuccessor(0), NewIP.getBlock());
   EXPECT_EQ(CancelBBTI->getSuccessor(1)->size(), 3U);
   CallInst *GTID1 = dyn_cast<CallInst>(&CancelBBTI->getSuccessor(1)->front());
   EXPECT_NE(GTID1, nullptr);
@@ -468,10 +462,9 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {
   IRBuilder<> Builder(BB);
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP()});
-  OpenMPIRBuilder::InsertPointOrErrorTy NewIP =
-      OMPBuilder.createCancel(Loc, Builder.getTrue(), OMPD_parallel);
-  assert(NewIP && "unexpected error");
-  Builder.restoreIP(*NewIP);
+  OpenMPIRBuilder::InsertPointTy NewIP =
+      cantFail(OMPBuilder.createCancel(Loc, Builder.getTrue(), OMPD_parallel));
+  Builder.restoreIP(NewIP);
   EXPECT_FALSE(M->global_empty());
   EXPECT_EQ(M->size(), 4U);
   EXPECT_EQ(F->size(), 7U);
@@ -499,7 +492,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {
   EXPECT_EQ(CancelBBTI->getNumSuccessors(), 2U);
   EXPECT_EQ(CancelBBTI->getSuccessor(0)->size(), 1U);
   EXPECT_EQ(CancelBBTI->getSuccessor(0)->getUniqueSuccessor(),
-            NewIP->getBlock());
+            NewIP.getBlock());
   EXPECT_EQ(CancelBBTI->getSuccessor(1)->size(), 3U);
   CallInst *GTID1 = dyn_cast<CallInst>(&CancelBBTI->getSuccessor(1)->front());
   EXPECT_NE(GTID1, nullptr);
@@ -543,10 +536,9 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelBarrier) {
   IRBuilder<> Builder(BB);
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP()});
-  OpenMPIRBuilder::InsertPointOrErrorTy NewIP =
-      OMPBuilder.createBarrier(Loc, OMPD_for);
-  assert(NewIP && "unexpected error");
-  Builder.restoreIP(*NewIP);
+  OpenMPIRBuilder::InsertPointTy NewIP =
+      cantFail(OMPBuilder.createBarrier(Loc, OMPD_for));
+  Builder.restoreIP(NewIP);
   EXPECT_FALSE(M->global_empty());
   EXPECT_EQ(M->size(), 3U);
   EXPECT_EQ(F->size(), 4U);
@@ -568,7 +560,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelBarrier) {
   EXPECT_EQ(Barrier->getNumUses(), 1U);
   Instruction *BarrierBBTI = Barrier->getParent()->getTerminator();
   EXPECT_EQ(BarrierBBTI->getNumSuccessors(), 2U);
-  EXPECT_EQ(BarrierBBTI->getSuccessor(0), NewIP->getBlock());
+  EXPECT_EQ(BarrierBBTI->getSuccessor(0), NewIP.getBlock());
   EXPECT_EQ(BarrierBBTI->getSuccessor(1)->size(), 1U);
   EXPECT_EQ(BarrierBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(),
             1U);
@@ -591,9 +583,7 @@ TEST_F(OpenMPIRBuilderTest, DbgLoc) {
   IRBuilder<> Builder(BB);
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createBarrier(Loc, OMPD_for);
-  assert(AfterIP && "unexpected error");
+  cantFail(OMPBuilder.createBarrier(Loc, OMPD_for));
   CallInst *GTID = dyn_cast<CallInst>(&BB->front());
   CallInst *Barrier = dyn_cast<CallInst>(GTID->getNextNode());
   EXPECT_EQ(GTID->getDebugLoc(), DL);
@@ -692,16 +682,15 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimpleGPU) {
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createParallel(Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB,
-                                nullptr, nullptr, OMP_PROC_BIND_default, false);
-  assert(AfterIP && "unexpected error");
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createParallel(
+      Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB, nullptr, nullptr,
+      OMP_PROC_BIND_default, false));
 
   EXPECT_EQ(NumBodiesGenerated, 1U);
   EXPECT_EQ(NumPrivatizedVars, 1U);
   EXPECT_EQ(NumFinalizationPoints, 1U);
 
-  Builder.restoreIP(*AfterIP);
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize();
@@ -805,15 +794,14 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createParallel(Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB,
-                                nullptr, nullptr, OMP_PROC_BIND_default, false);
-  assert(AfterIP && "unexpected error");
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createParallel(
+      Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB, nullptr, nullptr,
+      OMP_PROC_BIND_default, false));
   EXPECT_EQ(NumBodiesGenerated, 1U);
   EXPECT_EQ(NumPrivatizedVars, 1U);
   EXPECT_EQ(NumFinalizationPoints, 1U);
 
-  Builder.restoreIP(*AfterIP);
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize();
@@ -894,28 +882,26 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested) {
     BasicBlock *NewBB = SplitBlock(CGBB, &*CodeGenIP.getPoint());
     CGBB->getTerminator()->eraseFromParent();
 
-    OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createParallel(
+    OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createParallel(
         InsertPointTy(CGBB, CGBB->end()), AllocaIP, InnerBodyGenCB, PrivCB,
-        FiniCB, nullptr, nullptr, OMP_PROC_BIND_default, false);
-    assert(AfterIP && "unexpected error");
+        FiniCB, nullptr, nullptr, OMP_PROC_BIND_default, false));
 
-    Builder.restoreIP(*AfterIP);
+    Builder.restoreIP(AfterIP);
     Builder.CreateBr(NewBB);
     return Error::success();
   };
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createParallel(Loc, AllocaIP, OuterBodyGenCB, PrivCB, FiniCB,
-                                nullptr, nullptr, OMP_PROC_BIND_default, false);
-  assert(AfterIP && "unexpected error");
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createParallel(
+      Loc, AllocaIP, OuterBodyGenCB, PrivCB, FiniCB, nullptr, nullptr,
+      OMP_PROC_BIND_default, false));
 
   EXPECT_EQ(NumInnerBodiesGenerated, 1U);
   EXPECT_EQ(NumOuterBodiesGenerated, 1U);
   EXPECT_EQ(NumFinalizationPoints, 2U);
 
-  Builder.restoreIP(*AfterIP);
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize();
@@ -998,36 +984,35 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) {
     NewBB1->getTerminator()->eraseFromParent();
     ;
 
-    OpenMPIRBuilder::InsertPointOrErrorTy AfterIP1 = OMPBuilder.createParallel(
-        InsertPointTy(CGBB, CGBB->end()), AllocaIP, InnerBodyGenCB, PrivCB,
-        FiniCB, nullptr, nullptr, OMP_PROC_BIND_default, false);
-    assert(AfterIP1 && "unexpected error");
+    OpenMPIRBuilder::InsertPointTy AfterIP1 =
+        cantFail(OMPBuilder.createParallel(
+            InsertPointTy(CGBB, CGBB->end()), AllocaIP, InnerBodyGenCB, PrivCB,
+            FiniCB, nullptr, nullptr, OMP_PROC_BIND_default, false));
 
-    Builder.restoreIP(*AfterIP1);
+    Builder.restoreIP(AfterIP1);
     Builder.CreateBr(NewBB1);
 
-    OpenMPIRBuilder::InsertPointOrErrorTy AfterIP2 = OMPBuilder.createParallel(
-        InsertPointTy(NewBB1, NewBB1->end()), AllocaIP, InnerBodyGenCB, PrivCB,
-        FiniCB, nullptr, nullptr, OMP_PROC_BIND_default, false);
-    assert(AfterIP2 && "unexpected error");
+    OpenMPIRBuilder::InsertPointTy AfterIP2 =
+        cantFail(OMPBuilder.createParallel(
+            InsertPointTy(NewBB1, NewBB1->end()), AllocaIP, InnerBodyGenCB,
+            PrivCB, FiniCB, nullptr, nullptr, OMP_PROC_BIND_default, false));
 
-    Builder.restoreIP(*AfterIP2);
+    Builder.restoreIP(AfterIP2);
     Builder.CreateBr(NewBB2);
     return Error::success();
   };
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createParallel(Loc, AllocaIP, OuterBodyGenCB, PrivCB, FiniCB,
-                                nullptr, nullptr, OMP_PROC_BIND_default, false);
-  assert(AfterIP && "unexpected error");
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createParallel(
+      Loc, AllocaIP, OuterBodyGenCB, PrivCB, FiniCB, nullptr, nullptr,
+      OMP_PROC_BIND_default, false));
 
   EXPECT_EQ(NumInnerBodiesGenerated, 2U);
   EXPECT_EQ(NumOuterBodiesGenerated, 1U);
   EXPECT_EQ(NumFinalizationPoints, 3U);
 
-  Builder.restoreIP(*AfterIP);
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize();
@@ -1133,17 +1118,16 @@ TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createParallel(Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB,
                                 Builder.CreateIsNotNull(F->arg_begin()),
-                                nullptr, OMP_PROC_BIND_default, false);
-  assert(AfterIP && "unexpected error");
+                                nullptr, OMP_PROC_BIND_default, false));
 
   EXPECT_EQ(NumBodiesGenerated, 1U);
   EXPECT_EQ(NumPrivatizedVars, 1U);
   EXPECT_EQ(NumFinalizationPoints, 1U);
 
-  Builder.restoreIP(*AfterIP);
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
 
@@ -1198,10 +1182,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
     // Create three barriers, two cancel barriers but only one checked.
     Function *CBFn, *BFn;
 
-    OpenMPIRBuilder::InsertPointOrErrorTy BarrierIP1 =
-        OMPBuilder.createBarrier(Builder.saveIP(), OMPD_parallel);
-    assert(BarrierIP1 && "unexpected error");
-    Builder.restoreIP(*BarrierIP1);
+    OpenMPIRBuilder::InsertPointTy BarrierIP1 =
+        cantFail(OMPBuilder.createBarrier(Builder.saveIP(), OMPD_parallel));
+    Builder.restoreIP(BarrierIP1);
 
     CBFn = M->getFunction("__kmpc_cancel_barrier");
     BFn = M->getFunction("__kmpc_barrier");
@@ -1212,10 +1195,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
     ASSERT_EQ(CBFn->user_back()->getNumUses(), 1U);
     CheckedBarrier = cast<CallInst>(CBFn->user_back());
 
-    OpenMPIRBuilder::InsertPointOrErrorTy BarrierIP2 =
-        OMPBuilder.createBarrier(Builder.saveIP(), OMPD_parallel, true);
-    assert(BarrierIP2 && "unexpected error");
-    Builder.restoreIP(*BarrierIP2);
+    OpenMPIRBuilder::InsertPointTy BarrierIP2 = cantFail(
+        OMPBuilder.createBarrier(Builder.saveIP(), OMPD_parallel, true));
+    Builder.restoreIP(BarrierIP2);
     CBFn = M->getFunction("__kmpc_cancel_barrier");
     BFn = M->getFunction("__kmpc_barrier");
     ASSERT_NE(CBFn, nullptr);
@@ -1225,10 +1207,10 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
     ASSERT_TRUE(isa<CallInst>(BFn->user_back()));
     ASSERT_EQ(BFn->user_back()->getNumUses(), 0U);
 
-    OpenMPIRBuilder::InsertPointOrErrorTy BarrierIP3 =
-        OMPBuilder.createBarrier(Builder.saveIP(), OMPD_parallel, false, false);
-    assert(BarrierIP3 && "unexpected error");
-    Builder.restoreIP(*BarrierIP3);
+    OpenMPIRBuilder::InsertPointTy BarrierIP3 =
+        cantFail(OMPBuilder.createBarrier(Builder.saveIP(), OMPD_parallel,
+                                          false, false));
+    Builder.restoreIP(BarrierIP3);
     ASSERT_EQ(CBFn->getNumUses(), 2U);
     ASSERT_EQ(BFn->getNumUses(), 1U);
     ASSERT_TRUE(CBFn->user_back() != CheckedBarrier);
@@ -1258,18 +1240,17 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createParallel(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createParallel(
       Loc, AllocaIP, BODYGENCB_WRAPPER(BodyGenCB), PrivCB, FiniCB,
       Builder.CreateIsNotNull(F->arg_begin()), nullptr, OMP_PROC_BIND_default,
-      true);
-  assert(AfterIP && "unexpected error");
+      true));
 
   EXPECT_EQ(NumBodiesGenerated, 1U);
   EXPECT_EQ(NumPrivatizedVars, 0U);
   EXPECT_EQ(NumFinalizationPoints, 2U);
   EXPECT_EQ(FakeDestructor->getNumUses(), 2U);
 
-  Builder.restoreIP(*AfterIP);
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
 
@@ -1345,11 +1326,10 @@ TEST_F(OpenMPIRBuilderTest, ParallelForwardAsPointers) {
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createParallel(Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB,
-                                nullptr, nullptr, OMP_PROC_BIND_default, false);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createParallel(
+      Loc, AllocaIP, BodyGenCB, PrivCB, FiniCB, nullptr, nullptr,
+      OMP_PROC_BIND_default, false));
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize();
@@ -1382,10 +1362,8 @@ TEST_F(OpenMPIRBuilderTest, CanonicalLoopSimple) {
     return Error::success();
   };
 
-  Expected<CanonicalLoopInfo *> LoopResult =
-      OMPBuilder.createCanonicalLoop(Loc, LoopBodyGenCB, TripCount);
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *Loop = *LoopResult;
+  CanonicalLoopInfo *Loop =
+      cantFail(OMPBuilder.createCanonicalLoop(Loc, LoopBodyGenCB, TripCount));
 
   Builder.restoreIP(Loop->getAfterIP());
   ReturnInst *RetInst = Builder.CreateRetVoid();
@@ -1440,11 +1418,9 @@ TEST_F(OpenMPIRBuilderTest, CanonicalLoopBounds) {
     auto LoopBodyGenCB = [&](InsertPointTy CodeGenIP, llvm::Value *LC) {
       return Error::success();
     };
-    Expected<CanonicalLoopInfo *> LoopResult =
+    CanonicalLoopInfo *Loop = cantFail(
         OMPBuilder.createCanonicalLoop(Loc, LoopBodyGenCB, StartVal, StopVal,
-                                       StepVal, IsSigned, InclusiveStop);
-    assert(LoopResult && "unexpected error");
-    CanonicalLoopInfo *Loop = *LoopResult;
+                                       StepVal, IsSigned, InclusiveStop));
     Loop->assertOK();
     Builder.restoreIP(Loop->getAfterIP());
     Value *TripCount = Loop->getTripCount();
@@ -1539,20 +1515,16 @@ TEST_F(OpenMPIRBuilderTest, CollapseNestedLoops) {
       Call = createPrintfCall(Builder, "body i=%d j=%d\\n", {OuterLC, InnerLC});
       return Error::success();
     };
-    Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
-        Builder.saveIP(), InnerLoopBodyGenCB, InnerTripCount, "inner");
-    assert(LoopResult && "unexpected error");
-    InnerLoop = *LoopResult;
+    InnerLoop = cantFail(OMPBuilder.createCanonicalLoop(
+        Builder.saveIP(), InnerLoopBodyGenCB, InnerTripCount, "inner"));
 
     Builder.restoreIP(InnerLoop->getAfterIP());
     InbetweenTrail =
         createPrintfCall(Builder, "In-between trail i=%d\\n", {OuterLC});
     return Error::success();
   };
-  Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
-      OuterLoc, OuterLoopBodyGenCB, OuterTripCount, "outer");
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *OuterLoop = *LoopResult;
+  CanonicalLoopInfo *OuterLoop = cantFail(OMPBuilder.createCanonicalLoop(
+      OuterLoc, OuterLoopBodyGenCB, OuterTripCount, "outer"));
 
   // Finish the function.
   Builder.restoreIP(OuterLoop->getAfterIP());
@@ -1664,16 +1636,12 @@ TEST_F(OpenMPIRBuilderTest, TileNestedLoops) {
       createPrintfCall(Builder, "i=%d j=%d\\n", {OuterLC, InnerLC});
       return Error::success();
     };
-    Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
-        OuterCodeGenIP, InnerLoopBodyGenCB, TripCount, "inner");
-    assert(LoopResult && "unexpected error");
-    InnerLoop = *LoopResult;
+    InnerLoop = cantFail(OMPBuilder.createCanonicalLoop(
+        OuterCodeGenIP, InnerLoopBodyGenCB, TripCount, "inner"));
     return Error::success();
   };
-  Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
-      Loc, OuterLoopBodyGenCB, TripCount, "outer");
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *OuterLoop = *LoopResult;
+  CanonicalLoopInfo *OuterLoop = cantFail(OMPBuilder.createCanonicalLoop(
+      Loc, OuterLoopBodyGenCB, TripCount, "outer"));
 
   // Finalize the function.
   Builder.restoreIP(OuterLoop->getAfterIP());
@@ -1770,18 +1738,14 @@ TEST_F(OpenMPIRBuilderTest, TileNestedLoopsWithBounds) {
       Call = createPrintfCall(Builder, "i=%d j=%d\\n", {OuterLC, InnerLC});
       return Error::success();
     };
-    Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
+    InnerLoop = cantFail(OMPBuilder.createCanonicalLoop(
         OuterCodeGenIP, InnerLoopBodyGenCB, InnerStartVal, InnerStopVal,
-        InnerStep, false, false, ComputeIP, "inner");
-    assert(LoopResult && "unexpected error");
-    InnerLoop = *LoopResult;
+        InnerStep, false, false, ComputeIP, "inner"));
     return Error::success();
   };
-  Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
+  CanonicalLoopInfo *OuterLoop = cantFail(OMPBuilder.createCanonicalLoop(
       Loc, OuterLoopBodyGenCB, OuterStartVal, OuterStopVal, OuterStep, false,
-      false, ComputeIP, "outer");
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *OuterLoop = *LoopResult;
+      false, ComputeIP, "outer"));
 
   // Finalize the function
   Builder.restoreIP(OuterLoop->getAfterIP());
@@ -1888,11 +1852,9 @@ TEST_F(OpenMPIRBuilderTest, TileSingleLoopCounts) {
     auto LoopBodyGenCB = [&](InsertPointTy CodeGenIP, llvm::Value *LC) {
       return Error::success();
     };
-    Expected<CanonicalLoopInfo *> LoopResult =
+    CanonicalLoopInfo *Loop = cantFail(
         OMPBuilder.createCanonicalLoop(Loc, LoopBodyGenCB, StartVal, StopVal,
-                                       StepVal, IsSigned, InclusiveStop);
-    assert(LoopResult && "unexpected error");
-    CanonicalLoopInfo *Loop = *LoopResult;
+                                       StepVal, IsSigned, InclusiveStop));
     InsertPointTy AfterIP = Loop->getAfterIP();
 
     // Tile the loop.
@@ -2343,20 +2305,18 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkshareLoopTarget) {
   Value *StepVal = ConstantInt::get(LCTy, 2);
   auto LoopBodyGen = [&](InsertPointTy, Value *) { return Error::success(); };
 
-  Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
-      Loc, LoopBodyGen, StartVal, StopVal, StepVal, false, false);
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *CLI = *LoopResult;
+  CanonicalLoopInfo *CLI = cantFail(OMPBuilder.createCanonicalLoop(
+      Loc, LoopBodyGen, StartVal, StopVal, StepVal, false, false));
   BasicBlock *Preheader = CLI->getPreheader();
   Value *TripCount = CLI->getTripCount();
 
   Builder.SetInsertPoint(BB, BB->getFirstInsertionPt());
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.applyWorkshareLoop(
-      DL, CLI, AllocaIP, true, OMP_SCHEDULE_Static, nullptr, false, false,
-      false, false, WorksharingLoopType::ForStaticLoop);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.applyWorkshareLoop(
+          DL, CLI, AllocaIP, true, OMP_SCHEDULE_Static, nullptr, false, false,
+          false, false, WorksharingLoopType::ForStaticLoop));
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize();
@@ -2409,11 +2369,9 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {
     return Error::success();
   };
 
-  Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
+  CanonicalLoopInfo *CLI = cantFail(OMPBuilder.createCanonicalLoop(
       Loc, LoopBodyGen, StartVal, StopVal, StepVal,
-      /*IsSigned=*/false, /*InclusiveStop=*/false);
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *CLI = *LoopResult;
+      /*IsSigned=*/false, /*InclusiveStop=*/false));
   BasicBlock *Preheader = CLI->getPreheader();
   BasicBlock *Body = CLI->getBody();
   Value *IV = CLI->getIndVar();
@@ -2422,9 +2380,8 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {
   Builder.SetInsertPoint(BB, BB->getFirstInsertionPt());
   InsertPointTy AllocaIP = Builder.saveIP();
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.applyWorkshareLoop(
-      DL, CLI, AllocaIP, /*NeedsBarrier=*/true, OMP_SCHEDULE_Static);
-  assert(AfterIP && "unexpected error");
+  cantFail(OMPBuilder.applyWorkshareLoop(
+      DL, CLI, AllocaIP, /*NeedsBarrier=*/true, OMP_SCHEDULE_Static));
 
   BasicBlock *Cond = Body->getSinglePredecessor();
   Instruction *Cmp = &*Cond->begin();
@@ -2516,9 +2473,9 @@ TEST_P(OpenMPIRBuilderTestWithIVBits, StaticChunkedWorkshareLoop) {
   Value *ChunkSize = ConstantInt::get(LCTy, 5);
   InsertPointTy AllocaIP{&F->getEntryBlock(),
                          F->getEntryBlock().getFirstInsertionPt()};
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.applyWorkshareLoop(
-      DL, CLI, AllocaIP, /*NeedsBarrier=*/true, OMP_SCHEDULE_Static, ChunkSize);
-  assert(AfterIP && "unexpected error");
+  cantFail(OMPBuilder.applyWorkshareLoop(DL, CLI, AllocaIP,
+                                         /*NeedsBarrier=*/true,
+                                         OMP_SCHEDULE_Static, ChunkSize));
 
   OMPBuilder.finalize();
   EXPECT_FALSE(verifyModule(*M, &errs()));
@@ -2609,11 +2566,9 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
     return Error::success();
   };
 
-  Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
+  CanonicalLoopInfo *CLI = cantFail(OMPBuilder.createCanonicalLoop(
       Loc, LoopBodyGen, StartVal, StopVal, StepVal,
-      /*IsSigned=*/false, /*InclusiveStop=*/false);
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *CLI = *LoopResult;
+      /*IsSigned=*/false, /*InclusiveStop=*/false));
 
   Builder.SetInsertPoint(BB, BB->getFirstInsertionPt());
   InsertPointTy AllocaIP = Builder.saveIP();
@@ -2626,19 +2581,18 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
   BasicBlock *LatchBlock = CLI->getLatch();
   Value *IV = CLI->getIndVar();
 
-  OpenMPIRBuilder::InsertPointOrErrorTy EndIP = OMPBuilder.applyWorkshareLoop(
+  OpenMPIRBuilder::InsertPointTy EndIP = cantFail(OMPBuilder.applyWorkshareLoop(
       DL, CLI, AllocaIP, /*NeedsBarrier=*/true, getSchedKind(SchedType),
       ChunkVal, /*Simd=*/false,
       (SchedType & omp::OMPScheduleType::ModifierMonotonic) ==
           omp::OMPScheduleType::ModifierMonotonic,
       (SchedType & omp::OMPScheduleType::ModifierNonmonotonic) ==
           omp::OMPScheduleType::ModifierNonmonotonic,
-      /*Ordered=*/false);
-  assert(EndIP && "unexpected error");
+      /*Ordered=*/false));
 
   // The returned value should be the "after" point.
-  ASSERT_EQ(EndIP->getBlock(), AfterIP.getBlock());
-  ASSERT_EQ(EndIP->getPoint(), AfterIP.getPoint());
+  ASSERT_EQ(EndIP.getBlock(), AfterIP.getBlock());
+  ASSERT_EQ(EndIP.getPoint(), AfterIP.getPoint());
 
   auto AllocaIter = BB->begin();
   ASSERT_GE(std::distance(BB->begin(), BB->end()), 4);
@@ -2713,7 +2667,7 @@ TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {
   EXPECT_EQ(NumCallsInExitBlock, 2u);
 
   // Add a termination to our block and check that it is internally consistent.
-  Builder.restoreIP(*EndIP);
+  Builder.restoreIP(EndIP);
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
   EXPECT_FALSE(verifyModule(*M, &errs()));
@@ -2756,11 +2710,9 @@ TEST_F(OpenMPIRBuilderTest, DynamicWorkShareLoopOrdered) {
     return llvm::Error::success();
   };
 
-  Expected<CanonicalLoopInfo *> LoopResult = OMPBuilder.createCanonicalLoop(
+  CanonicalLoopInfo *CLI = cantFail(OMPBuilder.createCanonicalLoop(
       Loc, LoopBodyGen, StartVal, StopVal, StepVal,
-      /*IsSigned=*/false, /*InclusiveStop=*/false);
-  assert(LoopResult && "unexpected error");
-  CanonicalLoopInfo *CLI = *LoopResult;
+      /*IsSigned=*/false, /*InclusiveStop=*/false));
 
   Builder.SetInsertPoint(BB, BB->getFirstInsertionPt());
   InsertPointTy AllocaIP = Builder.saveIP();
@@ -2772,15 +2724,14 @@ TEST_F(OpenMPIRBuilderTest, DynamicWorkShareLoopOrdered) {
   BasicBlock *LatchBlock = CLI->getLatch();
   Value *IV = CLI->getIndVar();
 
-  OpenMPIRBuilder::InsertPointOrErrorTy EndIP = OMPBuilder.applyWorkshareLoop(
+  OpenMPIRBuilder::InsertPointTy EndIP = cantFail(OMPBuilder.applyWorkshareLoop(
       DL, CLI, AllocaIP, /*NeedsBarrier=*/true, OMP_SCHEDULE_Static, ChunkVal,
       /*HasSimdModifier=*/false, /*HasMonotonicModifier=*/false,
       /*HasNonmonotonicModifier=*/false,
-      /*HasOrderedClause=*/true);
-  assert(EndIP && "unexpected error");
+      /*HasOrderedClause=*/true));
 
   // Add a termination to our block and check that it is internally consistent.
-  Builder.restoreIP(*EndIP);
+  Builder.restoreIP(EndIP);
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
   EXPECT_FALSE(verifyModule(*M, &errs()));
@@ -2864,10 +2815,9 @@ TEST_F(OpenMPIRBuilderTest, MasterDirective) {
     EXPECT_NE(IPBB->end(), IP.getPoint());
   };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createMaster(
-      Builder, BODYGENCB_WRAPPER(BodyGenCB), FINICB_WRAPPER(FiniCB));
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createMaster(
+      Builder, BODYGENCB_WRAPPER(BodyGenCB), FINICB_WRAPPER(FiniCB)));
+  Builder.restoreIP(AfterIP);
   Value *EntryBBTI = EntryBB->getTerminator();
   EXPECT_NE(EntryBBTI, nullptr);
   EXPECT_TRUE(isa<BranchInst>(EntryBBTI));
@@ -2945,10 +2895,9 @@ TEST_F(OpenMPIRBuilderTest, MaskedDirective) {
   };
 
   Constant *Filter = ConstantInt::get(Type::getInt32Ty(M->getContext()), 0);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createMasked(
-      Builder, BODYGENCB_WRAPPER(BodyGenCB), FINICB_WRAPPER(FiniCB), Filter);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createMasked(
+      Builder, BODYGENCB_WRAPPER(BodyGenCB), FINICB_WRAPPER(FiniCB), Filter));
+  Builder.restoreIP(AfterIP);
   Value *EntryBBTI = EntryBB->getTerminator();
   EXPECT_NE(EntryBBTI, nullptr);
   EXPECT_TRUE(isa<BranchInst>(EntryBBTI));
@@ -3013,11 +2962,10 @@ TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
   };
   BasicBlock *EntryBB = Builder.GetInsertBlock();
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createCritical(Builder, BODYGENCB_WRAPPER(BodyGenCB),
-                                FINICB_WRAPPER(FiniCB), "testCRT", nullptr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                                FINICB_WRAPPER(FiniCB), "testCRT", nullptr));
+  Builder.restoreIP(AfterIP);
 
   CallInst *CriticalEntryCI = nullptr;
   for (auto &EI : *EntryBB) {
@@ -3264,11 +3212,10 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveThreads) {
 
   // Test for "#omp ordered [threads]"
   BasicBlock *EntryBB = Builder.GetInsertBlock();
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createOrderedThreadsSimd(Builder, BODYGENCB_WRAPPER(BodyGenCB),
-                                          FINICB_WRAPPER(FiniCB), true);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createOrderedThreadsSimd(
+          Builder, BODYGENCB_WRAPPER(BodyGenCB), FINICB_WRAPPER(FiniCB), true));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -3338,11 +3285,10 @@ TEST_F(OpenMPIRBuilderTest, OrderedDirectiveSimd) {
 
   // Test for "#omp ordered simd"
   BasicBlock *EntryBB = Builder.GetInsertBlock();
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createOrderedThreadsSimd(Builder, BODYGENCB_WRAPPER(BodyGenCB),
-                                          FINICB_WRAPPER(FiniCB), false);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                                          FINICB_WRAPPER(FiniCB), false));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -3455,11 +3401,10 @@ TEST_F(OpenMPIRBuilderTest, SingleDirective) {
     EXPECT_NE(IPBB->end(), IP.getPoint());
   };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createSingle(Builder, BODYGENCB_WRAPPER(BodyGenCB),
-                              FINICB_WRAPPER(FiniCB), /*IsNowait*/ false);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                              FINICB_WRAPPER(FiniCB), /*IsNowait*/ false));
+  Builder.restoreIP(AfterIP);
   Value *EntryBBTI = EntryBB->getTerminator();
   EXPECT_NE(EntryBBTI, nullptr);
   EXPECT_TRUE(isa<BranchInst>(EntryBBTI));
@@ -3548,11 +3493,10 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveNowait) {
     EXPECT_NE(IPBB->end(), IP.getPoint());
   };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createSingle(Builder, BODYGENCB_WRAPPER(BodyGenCB),
-                              FINICB_WRAPPER(FiniCB), /*IsNowait*/ true);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                              FINICB_WRAPPER(FiniCB), /*IsNowait*/ true));
+  Builder.restoreIP(AfterIP);
   Value *EntryBBTI = EntryBB->getTerminator();
   EXPECT_NE(EntryBBTI, nullptr);
   EXPECT_TRUE(isa<BranchInst>(EntryBBTI));
@@ -3670,11 +3614,10 @@ TEST_F(OpenMPIRBuilderTest, SingleDirectiveCopyPrivate) {
     EXPECT_NE(IPBB->end(), IP.getPoint());
   };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createSingle(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createSingle(
       Builder, BODYGENCB_WRAPPER(BodyGenCB), FINICB_WRAPPER(FiniCB),
-      /*IsNowait*/ false, {CPVar}, {CopyFunc});
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /*IsNowait*/ false, {CPVar}, {CopyFunc}));
+  Builder.restoreIP(AfterIP);
   Value *EntryBBTI = EntryBB->getTerminator();
   EXPECT_NE(EntryBBTI, nullptr);
   EXPECT_TRUE(isa<BranchInst>(EntryBBTI));
@@ -3935,10 +3878,10 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdate) {
     Sub = IRB.CreateSub(ConstVal, Atomic);
     return Sub;
   };
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createAtomicUpdate(
-      Builder, AllocaIP, X, Expr, AO, RMWOp, UpdateOp, IsXLHSInRHSPart);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createAtomicUpdate(Builder, AllocaIP, X, Expr, AO,
+                                             RMWOp, UpdateOp, IsXLHSInRHSPart));
+  Builder.restoreIP(AfterIP);
   BasicBlock *ContBB = EntryBB->getSingleSuccessor();
   BranchInst *ContTI = dyn_cast<BranchInst>(ContBB->getTerminator());
   EXPECT_NE(ContTI, nullptr);
@@ -4004,10 +3947,10 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateFloat) {
     Sub = IRB.CreateFSub(ConstVal, Atomic);
     return Sub;
   };
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createAtomicUpdate(
-      Builder, AllocaIP, X, Expr, AO, RMWOp, UpdateOp, IsXLHSInRHSPart);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createAtomicUpdate(Builder, AllocaIP, X, Expr, AO,
+                                             RMWOp, UpdateOp, IsXLHSInRHSPart));
+  Builder.restoreIP(AfterIP);
   BasicBlock *ContBB = EntryBB->getSingleSuccessor();
   BranchInst *ContTI = dyn_cast<BranchInst>(ContBB->getTerminator());
   EXPECT_NE(ContTI, nullptr);
@@ -4072,10 +4015,10 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateIntr) {
     Sub = IRB.CreateSub(ConstVal, Atomic);
     return Sub;
   };
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createAtomicUpdate(
-      Builder, AllocaIP, X, Expr, AO, RMWOp, UpdateOp, IsXLHSInRHSPart);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createAtomicUpdate(Builder, AllocaIP, X, Expr, AO,
+                                             RMWOp, UpdateOp, IsXLHSInRHSPart));
+  Builder.restoreIP(AfterIP);
   BasicBlock *ContBB = EntryBB->getSingleSuccessor();
   BranchInst *ContTI = dyn_cast<BranchInst>(ContBB->getTerminator());
   EXPECT_NE(ContTI, nullptr);
@@ -4146,12 +4089,11 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicCapture) {
   // integer update - not used
   auto UpdateOp = [&](Value *Atomic, IRBuilder<> &IRB) { return nullptr; };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createAtomicCapture(Builder, AllocaIP, X, V, Expr, AO, RMWOp,
-                                     UpdateOp, UpdateExpr, IsPostfixUpdate,
-                                     IsXLHSInRHSPart);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createAtomicCapture(
+          Builder, AllocaIP, X, V, Expr, AO, RMWOp, UpdateOp, UpdateExpr,
+          IsPostfixUpdate, IsXLHSInRHSPart));
+  Builder.restoreIP(AfterIP);
   EXPECT_EQ(EntryBB->getParent()->size(), 1U);
   AtomicRMWInst *ARWM = dyn_cast<AtomicRMWInst>(Init->getNextNode());
   EXPECT_NE(ARWM, nullptr);
@@ -4511,11 +4453,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTeams) {
   };
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTeams(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTeams(
       Builder, BodyGenCB, /*NumTeamsLower=*/nullptr, /*NumTeamsUpper=*/nullptr,
-      /*ThreadLimit=*/nullptr, /*IfExpr=*/nullptr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /*ThreadLimit=*/nullptr, /*IfExpr=*/nullptr));
+  Builder.restoreIP(AfterIP);
 
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
@@ -4576,12 +4517,11 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithThreadLimit) {
   };
 
   // `F` has an argument - an integer, so we use that as the thread limit.
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTeams(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTeams(
       /*=*/Builder, BodyGenCB, /*NumTeamsLower=*/nullptr,
       /*NumTeamsUpper=*/nullptr, /*ThreadLimit=*/F->arg_begin(),
-      /*IfExpr=*/nullptr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /*IfExpr=*/nullptr));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -4630,14 +4570,13 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsUpper) {
 
   // `F` already has an integer argument, so we use that as upper bound to
   // `num_teams`
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createTeams(Builder, BodyGenCB,
-                             /*NumTeamsLower=*/nullptr,
-                             /*NumTeamsUpper=*/F->arg_begin(),
-                             /*ThreadLimit=*/nullptr,
-                             /*IfExpr=*/nullptr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createTeams(Builder, BodyGenCB,
+                                      /*NumTeamsLower=*/nullptr,
+                                      /*NumTeamsUpper=*/F->arg_begin(),
+                                      /*ThreadLimit=*/nullptr,
+                                      /*IfExpr=*/nullptr));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -4691,11 +4630,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsBoth) {
 
   // `F` already has an integer argument, so we use that as upper bound to
   // `num_teams`
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createTeams(Builder, BodyGenCB, NumTeamsLower, NumTeamsUpper,
-                             /*ThreadLimit=*/nullptr, /*IfExpr=*/nullptr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                             /*ThreadLimit=*/nullptr, /*IfExpr=*/nullptr));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -4755,10 +4693,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsAndThreadLimit) {
   };
 
   OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTeams(
-      Builder, BodyGenCB, NumTeamsLower, NumTeamsUpper, ThreadLimit, nullptr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTeams(
+      Builder, BodyGenCB, NumTeamsLower, NumTeamsUpper, ThreadLimit, nullptr));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -4810,11 +4747,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithIfCondition) {
 
   // `F` already has an integer argument, so we use that as upper bound to
   // `num_teams`
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTeams(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTeams(
       Builder, BodyGenCB, /*NumTeamsLower=*/nullptr, /*NumTeamsUpper=*/nullptr,
-      /*ThreadLimit=*/nullptr, IfExpr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /*ThreadLimit=*/nullptr, IfExpr));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -4876,10 +4812,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithIfConditionAndNumTeams) {
 
   // `F` already has an integer argument, so we use that as upper bound to
   // `num_teams`
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTeams(
-      Builder, BodyGenCB, NumTeamsLower, NumTeamsUpper, ThreadLimit, IfExpr);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTeams(
+      Builder, BodyGenCB, NumTeamsLower, NumTeamsUpper, ThreadLimit, IfExpr));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -5139,13 +5074,12 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
   // Do nothing in finalization.
   auto FiniCB = [&](InsertPointTy CodeGenIP) { return Error::success(); };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createParallel(Loc, OuterAllocaIP, BodyGenCB, PrivCB, FiniCB,
                                 /* IfCondition */ nullptr,
                                 /* NumThreads */ nullptr, OMP_PROC_BIND_default,
-                                /* IsCancellable */ false);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                                /* IsCancellable */ false));
+  Builder.restoreIP(AfterIP);
 
   OpenMPIRBuilder::ReductionInfo ReductionInfos[] = {
       {SumType, SumReduced, SumPrivatized,
@@ -5157,13 +5091,10 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
   OMPBuilder.Config.setIsGPU(false);
 
   bool ReduceVariableByRef[] = {false, false};
+  cantFail(OMPBuilder.createReductions(BodyIP, BodyAllocaIP, ReductionInfos,
+                                       ReduceVariableByRef));
 
-  OpenMPIRBuilder::InsertPointOrErrorTy ReductionsIP =
-      OMPBuilder.createReductions(BodyIP, BodyAllocaIP, ReductionInfos,
-                                  ReduceVariableByRef);
-  assert(ReductionsIP && "unexpected error");
-
-  Builder.restoreIP(*AfterIP);
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize(F);
@@ -5399,42 +5330,36 @@ TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {
   // Do nothing in finalization.
   auto FiniCB = [&](InsertPointTy CodeGenIP) { return Error::success(); };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP1 =
+  OpenMPIRBuilder::InsertPointTy AfterIP1 = cantFail(
       OMPBuilder.createParallel(Loc, OuterAllocaIP, FirstBodyGenCB, PrivCB,
                                 FiniCB, /* IfCondition */ nullptr,
                                 /* NumThreads */ nullptr, OMP_PROC_BIND_default,
-                                /* IsCancellable */ false);
-  assert(AfterIP1 && "unexpected error");
-  Builder.restoreIP(*AfterIP1);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP2 = OMPBuilder.createParallel(
+                                /* IsCancellable */ false));
+  Builder.restoreIP(AfterIP1);
+  OpenMPIRBuilder::InsertPointTy AfterIP2 = cantFail(OMPBuilder.createParallel(
       {Builder.saveIP(), DL}, OuterAllocaIP, SecondBodyGenCB, PrivCB, FiniCB,
       /* IfCondition */ nullptr,
       /* NumThreads */ nullptr, OMP_PROC_BIND_default,
-      /* IsCancellable */ false);
-  assert(AfterIP2 && "unexpected error");
-  Builder.restoreIP(*AfterIP2);
+      /* IsCancellable */ false));
+  Builder.restoreIP(AfterIP2);
 
   OMPBuilder.Config.setIsGPU(false);
   bool ReduceVariableByRef[] = {false};
 
-  OpenMPIRBuilder::InsertPointOrErrorTy ReductionsIP1 =
-      OMPBuilder.createReductions(
-          FirstBodyIP, FirstBodyAllocaIP,
-          {{SumType, SumReduced, SumPrivatized,
-            /*EvaluationKind=*/OpenMPIRBuilder::EvalKind::Scalar, sumReduction,
-            /*ReductionGenClang=*/nullptr, sumAtomicReduction}},
-          ReduceVariableByRef);
-  assert(ReductionsIP1 && "unexpected error");
-  OpenMPIRBuilder::InsertPointOrErrorTy ReductionsIP2 =
-      OMPBuilder.createReductions(
-          SecondBodyIP, SecondBodyAllocaIP,
-          {{XorType, XorReduced, XorPrivatized,
-            /*EvaluationKind=*/OpenMPIRBuilder::EvalKind::Scalar, xorReduction,
-            /*ReductionGenClang=*/nullptr, xorAtomicReduction}},
-          ReduceVariableByRef);
-  assert(ReductionsIP2 && "unexpected error");
-
-  Builder.restoreIP(*AfterIP2);
+  cantFail(OMPBuilder.createReductions(
+      FirstBodyIP, FirstBodyAllocaIP,
+      {{SumType, SumReduced, SumPrivatized,
+        /*EvaluationKind=*/OpenMPIRBuilder::EvalKind::Scalar, sumReduction,
+        /*ReductionGenClang=*/nullptr, sumAtomicReduction}},
+      ReduceVariableByRef));
+  cantFail(OMPBuilder.createReductions(
+      SecondBodyIP, SecondBodyAllocaIP,
+      {{XorType, XorReduced, XorPrivatized,
+        /*EvaluationKind=*/OpenMPIRBuilder::EvalKind::Scalar, xorReduction,
+        /*ReductionGenClang=*/nullptr, xorAtomicReduction}},
+      ReduceVariableByRef));
+
+  Builder.restoreIP(AfterIP2);
   Builder.CreateRetVoid();
 
   OMPBuilder.finalize(F);
@@ -5512,10 +5437,9 @@ TEST_F(OpenMPIRBuilderTest, CreateSectionsSimple) {
                    llvm::Value *&ReplVal) { return CodeGenIP; };
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createSections(
-      Loc, AllocaIP, SectionCBVector, PrivCB, FiniCB, false, false);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createSections(
+      Loc, AllocaIP, SectionCBVector, PrivCB, FiniCB, false, false));
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid(); // Required at the end of the function
   EXPECT_NE(F->getEntryBlock().getTerminator(), nullptr);
   EXPECT_FALSE(verifyModule(*M, &errs()));
@@ -5569,11 +5493,10 @@ TEST_F(OpenMPIRBuilderTest, CreateSections) {
 
   IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
                                     F->getEntryBlock().getFirstInsertionPt());
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createSections(Loc, AllocaIP, SectionCBVector, PrivCB,
-                                FINICB_WRAPPER(FiniCB), false, false);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createSections(Loc, AllocaIP, SectionCBVector, PrivCB,
+                                         FINICB_WRAPPER(FiniCB), false, false));
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid(); // Required at the end of the function
 
   // Switch BB's predecessor is loop condition BB, whose successor at index 1 is
@@ -5659,10 +5582,9 @@ TEST_F(OpenMPIRBuilderTest, CreateSectionsNoWait) {
                    llvm::Value *&ReplVal) { return CodeGenIP; };
   auto FiniCB = [&](InsertPointTy IP) { return Error::success(); };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createSections(
-      Loc, AllocaIP, SectionCBVector, PrivCB, FiniCB, false, true);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createSections(
+      Loc, AllocaIP, SectionCBVector, PrivCB, FiniCB, false, true));
+  Builder.restoreIP(AfterIP);
   Builder.CreateRetVoid(); // Required at the end of the function
   for (auto &Inst : instructions(*F)) {
     EXPECT_FALSE(isa<CallInst>(Inst) &&
@@ -5883,11 +5805,10 @@ TEST_F(OpenMPIRBuilderTest, TargetEnterData) {
   OMPBuilder.Config.setIsGPU(true);
 
   llvm::omp::RuntimeFunction RTLFunc = OMPRTL___tgt_target_data_begin_mapper;
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTargetData(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTargetData(
       Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
-      /* IfCond= */ nullptr, Info, GenMapInfoCB, &RTLFunc);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /* IfCond= */ nullptr, Info, GenMapInfoCB, &RTLFunc));
+  Builder.restoreIP(AfterIP);
 
   CallInst *TargetDataCall = dyn_cast<CallInst>(&BB->back());
   EXPECT_NE(TargetDataCall, nullptr);
@@ -5944,11 +5865,10 @@ TEST_F(OpenMPIRBuilderTest, TargetExitData) {
   OMPBuilder.Config.setIsGPU(true);
 
   llvm::omp::RuntimeFunction RTLFunc = OMPRTL___tgt_target_data_end_mapper;
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTargetData(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTargetData(
       Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
-      /* IfCond= */ nullptr, Info, GenMapInfoCB, &RTLFunc);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /* IfCond= */ nullptr, Info, GenMapInfoCB, &RTLFunc));
+  Builder.restoreIP(AfterIP);
 
   CallInst *TargetDataCall = dyn_cast<CallInst>(&BB->back());
   EXPECT_NE(TargetDataCall, nullptr);
@@ -6054,12 +5974,11 @@ TEST_F(OpenMPIRBuilderTest, TargetDataRegion) {
     return Builder.saveIP();
   };
 
-  OpenMPIRBuilder::InsertPointOrErrorTy TargetDataIP1 =
-      OMPBuilder.createTargetData(
+  OpenMPIRBuilder::InsertPointTy TargetDataIP1 =
+      cantFail(OMPBuilder.createTargetData(
           Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
-          /* IfCond= */ nullptr, Info, GenMapInfoCB, nullptr, BodyCB);
-  assert(TargetDataIP1 && "unexpected error");
-  Builder.restoreIP(*TargetDataIP1);
+          /* IfCond= */ nullptr, Info, GenMapInfoCB, nullptr, BodyCB));
+  Builder.restoreIP(TargetDataIP1);
 
   CallInst *TargetDataCall = dyn_cast<CallInst>(&BB->back());
   EXPECT_NE(TargetDataCall, nullptr);
@@ -6082,12 +6001,11 @@ TEST_F(OpenMPIRBuilderTest, TargetDataRegion) {
     EXPECT_EQ(TargetDataCall, nullptr);
     return Builder.saveIP();
   };
-  OpenMPIRBuilder::InsertPointOrErrorTy TargetDataIP2 =
-      OMPBuilder.createTargetData(
+  OpenMPIRBuilder::InsertPointTy TargetDataIP2 =
+      cantFail(OMPBuilder.createTargetData(
           Loc, AllocaIP, Builder.saveIP(), Builder.getInt64(DeviceID),
-          /* IfCond= */ nullptr, Info, GenMapInfoCB, nullptr, BodyTargetCB);
-  assert(TargetDataIP2 && "unexpected error");
-  Builder.restoreIP(*TargetDataIP2);
+          /* IfCond= */ nullptr, Info, GenMapInfoCB, nullptr, BodyTargetCB));
+  Builder.restoreIP(TargetDataIP2);
   EXPECT_TRUE(CheckDevicePassBodyGen);
 
   Builder.CreateRetVoid();
@@ -6182,11 +6100,10 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
 
   TargetRegionEntryInfo EntryInfo("func", 42, 4711, 17);
   OpenMPIRBuilder::LocationDescription OmpLoc({Builder.saveIP(), DL});
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTarget(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTarget(
       OmpLoc, /*IsOffloadEntry=*/true, Builder.saveIP(), Builder.saveIP(),
-      EntryInfo, -1, 0, Inputs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      EntryInfo, -1, 0, Inputs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -6292,13 +6209,12 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
   TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
                                   /*Line=*/3, /*Count=*/0);
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createTarget(Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP,
                               EntryInfo, /*NumTeams=*/-1,
                               /*NumThreads=*/0, CapturedArgs, GenMapInfoCB,
-                              BodyGenCB, SimpleArgAccessorCB);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                              BodyGenCB, SimpleArgAccessorCB));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -6443,13 +6359,12 @@ TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {
   TargetRegionEntryInfo EntryInfo("parent", /*DeviceID=*/1, /*FileID=*/2,
                                   /*Line=*/3, /*Count=*/0);
 
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createTarget(Loc, /*IsOffloadEntry=*/true, EntryIP, EntryIP,
                               EntryInfo, /*NumTeams=*/-1,
                               /*NumThreads=*/0, CapturedArgs, GenMapInfoCB,
-                              BodyGenCB, SimpleArgAccessorCB);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                              BodyGenCB, SimpleArgAccessorCB));
+  Builder.restoreIP(AfterIP);
 
   Builder.CreateRetVoid();
   OMPBuilder.finalize();
@@ -6568,10 +6483,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTask) {
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
   OpenMPIRBuilder::LocationDescription Loc(
       InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTask(
-      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), BodyGenCB);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTask(
+      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
+      BodyGenCB));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -6677,10 +6592,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskNoArgs) {
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
   OpenMPIRBuilder::LocationDescription Loc(
       InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTask(
-      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), BodyGenCB);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTask(
+      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
+      BodyGenCB));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -6709,11 +6624,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskUntied) {
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
   OpenMPIRBuilder::LocationDescription Loc(
       InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTask(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTask(
       Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), BodyGenCB,
-      /*Tied=*/false);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /*Tied=*/false));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -6750,11 +6664,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskDepend) {
                                      Type::getInt32Ty(M->getContext()), InDep);
     DDS.push_back(DDIn);
   }
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTask(
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTask(
       Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), BodyGenCB,
-      /*Tied=*/false, /*Final*/ nullptr, /*IfCondition*/ nullptr, DDS);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+      /*Tied=*/false, /*Final*/ nullptr, /*IfCondition*/ nullptr, DDS));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -6824,11 +6737,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskFinal) {
       CmpInst::Predicate::ICMP_EQ, F->getArg(0),
       ConstantInt::get(Type::getInt32Ty(M->getContext()), 0U));
   OpenMPIRBuilder::LocationDescription Loc(Builder.saveIP(), DL);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
-      OMPBuilder.createTask(Loc, AllocaIP, BodyGenCB,
-                            /*Tied=*/false, Final);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP =
+      cantFail(OMPBuilder.createTask(Loc, AllocaIP, BodyGenCB,
+                                     /*Tied=*/false, Final));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -6883,11 +6795,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskIfCondition) {
       CmpInst::Predicate::ICMP_EQ, F->getArg(0),
       ConstantInt::get(Type::getInt32Ty(M->getContext()), 0U));
   OpenMPIRBuilder::LocationDescription Loc(Builder.saveIP(), DL);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP =
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(
       OMPBuilder.createTask(Loc, AllocaIP, BodyGenCB,
-                            /*Tied=*/false, /*Final=*/nullptr, IfCondition);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+                            /*Tied=*/false, /*Final=*/nullptr, IfCondition));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -6978,10 +6889,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroup) {
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
   OpenMPIRBuilder::LocationDescription Loc(
       InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTaskgroup(
-      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), BodyGenCB);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTaskgroup(
+      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
+      BodyGenCB));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 
@@ -7057,10 +6968,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {
       return Error::success();
     };
     OpenMPIRBuilder::LocationDescription Loc(Builder.saveIP(), DL);
-    OpenMPIRBuilder::InsertPointOrErrorTy TaskIP1 =
-        OMPBuilder.createTask(Loc, AllocaIP, TaskBodyGenCB1);
-    assert(TaskIP1 && "unexpected error");
-    Builder.restoreIP(*TaskIP1);
+    OpenMPIRBuilder::InsertPointTy TaskIP1 =
+        cantFail(OMPBuilder.createTask(Loc, AllocaIP, TaskBodyGenCB1));
+    Builder.restoreIP(TaskIP1);
 
     auto TaskBodyGenCB2 = [&](InsertPointTy AllocaIP, InsertPointTy CodeGenIP) {
       Builder.restoreIP(CodeGenIP);
@@ -7071,10 +6981,9 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {
       return Error::success();
     };
     OpenMPIRBuilder::LocationDescription Loc2(Builder.saveIP(), DL);
-    OpenMPIRBuilder::InsertPointOrErrorTy TaskIP2 =
-        OMPBuilder.createTask(Loc2, AllocaIP, TaskBodyGenCB2);
-    assert(TaskIP2 && "unexpected error");
-    Builder.restoreIP(*TaskIP2);
+    OpenMPIRBuilder::InsertPointTy TaskIP2 =
+        cantFail(OMPBuilder.createTask(Loc2, AllocaIP, TaskBodyGenCB2));
+    Builder.restoreIP(TaskIP2);
     return Error::success();
   };
 
@@ -7082,10 +6991,10 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {
   BasicBlock *BodyBB = splitBB(Builder, /*CreateBranch=*/true, "alloca.split");
   OpenMPIRBuilder::LocationDescription Loc(
       InsertPointTy(BodyBB, BodyBB->getFirstInsertionPt()), DL);
-  OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTaskgroup(
-      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()), BodyGenCB);
-  assert(AfterIP && "unexpected error");
-  Builder.restoreIP(*AfterIP);
+  OpenMPIRBuilder::InsertPointTy AfterIP = cantFail(OMPBuilder.createTaskgroup(
+      Loc, InsertPointTy(AllocaBB, AllocaBB->getFirstInsertionPt()),
+      BodyGenCB));
+  Builder.restoreIP(AfterIP);
   OMPBuilder.finalize();
   Builder.CreateRetVoid();
 



More information about the cfe-commits mailing list