<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/84180>84180</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [OMPT] Cancelled tasks schedules
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          rpereira-dev
      </td>
    </tr>
</table>

<pre>
    Something seems wrong with the OMPT `task_schedule` event on tasks whose taskgroup had been cancelled, please see minimal example bellow

LLVM version
```bash
$ clang --version
clang version 19.0.0git (https://github.com/rpereira-dev/llvm-project a64975f9660e02f5f6688f8bcc55daf9eaa99fda)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```

main.c
```C
# include <stdio.h>
# include <unistd.h>

# include <omp.h>

int main(void)
{
    # pragma omp parallel
    {
        # pragma omp single
        {
 # pragma omp taskgroup
            {
                # pragma omp task if(0) // A
                {
 puts("cancelling");
                    # pragma omp cancel taskgroup
                }

                # pragma omp task // B
                    puts("run");
            }
        }
 }
    return 0;
}
```

OMPT tool used
```bash
git clone -b llvm/untied-schedule https://github.com/rpereira-dev/ompt-dump.git
```

Compiled and run as
```
clang -Wall -Werror -Wextra -fopenmp main.c
OMP_CANCELLATION=1 OMP_NUM_THREADS=1 OMP_TOOL_LIBRARIES=path/to/libompt_dump.so ./a.out
```

Outputs
```
  1 [OMPT] [INFO] OMPT_DUMP: OpenMP 201611 and runtime LLVM OMP version: 5.0.20140926
  2 [OMPT] [INFO] Could not register callback 'ompt_callback_device_unload'
  3 [OMPT] [INFO] Could not register callback 'ompt_callback_target_map'
  4 [OMPT] [INFO] Could not register callback 'ompt_callback_target_map_emi'
  5 [OMPT] [INFO] ompt_callback_thread_begin
  6 [OMPT] [INFO] ompt_callback_implicit_task(task_data=0x55c84b0b1440)
  7 [OMPT] [INFO] ompt_callback_parallel_begin
  8 [OMPT] [INFO] ompt_callback_implicit_task(task_data=0x55c84b0b82c0)
  9 [OMPT] [INFO] ompt_callback_work
 10 [OMPT] [INFO] ompt_callback_sync_region
 11 [OMPT] [INFO] ompt_callback_task_create(encountering_task_data=0x55c84b0b82c0, new_task_data=0x55c84b1ba880)
 12 [OMPT] [INFO] ompt_callback_task_schedule(prior_task_data=0x55c84b0b82c0, prior_task_status=7, next_task_data=0x55c84b1ba880)
 13 cancelling
 14 [OMPT] [INFO] ompt_callback_cancel(task_data=0x55c84b1ba880, flags=24)
 15 [OMPT] [INFO] ompt_callback_task_schedule(prior_task_data=0x55c84b1ba880, prior_task_status=3, next_task_data=0x55c84b0b82c0)
 16 [OMPT] [INFO] ompt_callback_task_create(encountering_task_data=0x55c84b0b82c0, new_task_data=0x55c84b1ba880)
 17 [OMPT] [INFO] ompt_callback_cancel(task_data=0x55c84b1ba880, flags=72)
 18 [OMPT] [INFO] ompt_callback_task_schedule(prior_task_data=0x55c84b1ba880, prior_task_status=3, next_task_data=0x55c84b0b82c0)
 19 [OMPT] [INFO] ompt_callback_sync_region_wait
 20 [OMPT] [INFO] ompt_callback_sync_region_wait
 21 [OMPT] [INFO] ompt_callback_sync_region
 22 [OMPT] [INFO] ompt_callback_work
 23 [OMPT] [INFO] ompt_callback_sync_region
 24 [OMPT] [INFO] ompt_callback_sync_region_wait
 25 [OMPT] [INFO] ompt_callback_sync_region_wait
 26 [OMPT] [INFO] ompt_callback_sync_region
 27 [OMPT] [INFO] ompt_callback_implicit_task(task_data=0x55c84b0b82c0)
 28 [OMPT] [INFO] ompt_callback_parallel_end
 29 [OMPT] [INFO] ompt_callback_implicit_task(task_data=0x55c84b0b1440)
 30 [OMPT] [INFO] ompt_callback_thread_end
```

Event Line 12 - The thread switches from its implicit (parent) task `0x55a0067a5280` to the explicit task A `0x55a0068a7880`
Event Line 13-14 - The taskgroup is cancelled
Event Line 15 - The thread switches from the explicit task A `0x55a0068a7880` to its implicit (parent) task `0x55a0067a5280`
Event Line 16 - The thread create the task B `0x55a0068a7880`
Event Line 17 - The thread discards the task B `0x55a0068a7880`
Event Line 18 - The thread switches from the explicit task B `0x55a0068a7880` to its implicit (parent) task `0x55a0067a5280` - (**ERROR: the current task is `0x55a0067a5280`**) 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWFtv4zoO_jXKC5FAli9xHvKQJg12gHZS9PTseTRkm3G0I0uGJDc9_34h51K3TXI8g1ksUDQGxctHiqREcWtFpRDnJL4j8WrEW7fTZm4aNCgMH5f4Osp1-ff8D12j2wlVgUWsLeyNVhXshduB2yFsHp9egCTUcfsjs8UOy1YiSSjgKyoHWoFfsbDfaYvdd2V028COl5AjKii4KlBKLAlbQiORW_SWoBZK1FwCvvG6kQg5Sqn3hK4IXRz-Pzz8-xFe0Vih1ZGe0MNfzu3uSGIRFJKrCsbjD7wH4pEEwWxCJ7QSDghLd841loQLwtaErSvhdm0-KXRN2LofH8LWUr7W48bo_2DhgCfRbBpvZ0lCkbJtvE2SNN2meVHEccm3M-R8NtuWnLDZAcILNxU6Ei7gLU2yJBq36ofSezWWQrVv40q1R76dQV5CrUuUnrvRVrx98rgfmJoLNSk-MSxP8QhBqEK2JQIJl9aVQk92JLy_uNwqYV3ZX7_EpevmC4tQDjwOwtJXLcqzz2R6d_gAAPB6GsOrmoOuG2i44VKi7DH0uS9IWKEqiZ9YzjKfmM_J95H_op0r9rwKEFvCUkrYDA4JAosrsmelTessYSlh7JjtQlWEMR-U8IrhC8YPsrfcOFhd9fdhiENHN24geXfAtOoG8rPxr4QPSwZdaxTQs5J31JcSumsyTmsJrcXyaq378i2kVgjjHHxpErZulRNYjk-dCYbXtq4bNy7buplUwt0A59NfSCyBqxJMq4Dbi9zHLvQXlxLGf6Ex2vjfN2c4jLe6QVU30C_dzeNTtlx8X94_PCxevm2-k3AV-H6bff_zMXv51_P9YvXHmfay2TxkD9_unhfP3-49ueFuR9jaad-mRO69yTpvrIYJYWs-0e0ttzat63b9EgdAACS-89tC4pX__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