@@ -1905,7 +1905,8 @@ LogicalResult TargetOp::verifyRegions() {
19051905 return emitError (" target containing multiple 'omp.teams' nested ops" );
19061906
19071907 // Check that host_eval values are only used in legal ways.
1908- llvm::omp::OMPTgtExecModeFlags execFlags = getKernelExecFlags ();
1908+ llvm::omp::OMPTgtExecModeFlags execFlags =
1909+ getKernelExecFlags (getInnermostCapturedOmpOp ());
19091910 for (Value hostEvalArg :
19101911 cast<BlockArgOpenMPOpInterface>(getOperation ()).getHostEvalBlockArgs ()) {
19111912 for (Operation *user : hostEvalArg.getUsers ()) {
@@ -2026,23 +2027,26 @@ Operation *TargetOp::getInnermostCapturedOmpOp() {
20262027}
20272028
20282029llvm::omp::OMPTgtExecModeFlags
2029- TargetOp::getKernelExecFlags (std::optional< Operation *> capturedOp) {
2030+ TargetOp::getKernelExecFlags (Operation *capturedOp) {
20302031 using namespace llvm ::omp;
20312032
2032- // Use a cached operation, if passed in. Otherwise, find the innermost
2033- // captured operation.
2034- if (!capturedOp)
2035- capturedOp = getInnermostCapturedOmpOp ();
2036- assert (*capturedOp == getInnermostCapturedOmpOp () &&
2037- " unexpected captured op" );
2033+ #ifndef NDEBUG
2034+ if (capturedOp) {
2035+ // A non-null captured op is only valid if it resides inside of a TargetOp
2036+ // and is the result of calling getInnermostCapturedOmpOp() on it.
2037+ TargetOp targetOp = capturedOp->getParentOfType <TargetOp>();
2038+ assert (targetOp && targetOp.getInnermostCapturedOmpOp () &&
2039+ " unexpected captured op" );
2040+ }
2041+ #endif
20382042
20392043 // Make sure this region is capturing a loop. Otherwise, it's a generic
20402044 // kernel.
2041- if (!isa_and_present<LoopNestOp>(* capturedOp))
2045+ if (!isa_and_present<LoopNestOp>(capturedOp))
20422046 return OMP_TGT_EXEC_MODE_GENERIC;
20432047
20442048 SmallVector<LoopWrapperInterface> wrappers;
2045- cast<LoopNestOp>(* capturedOp).gatherWrappers (wrappers);
2049+ cast<LoopNestOp>(capturedOp).gatherWrappers (wrappers);
20462050 assert (!wrappers.empty ());
20472051
20482052 // Ignore optional SIMD leaf construct.
0 commit comments