__ompt_get_task_info_internal now recognizes if the task at the
requested ancestor_level doesn’t exist. This is done by recognizing
whether all tasks have been exhausted (“taskdata” doesn’t exist) during
the iteration over the hierarchy of active tasks. If so, there’s no need
to continue executing the while loop. Break the loop and return 0 code
instead.
This patch prevents the SEGFAULT that may arise if the the loop unnecessarily
continues instead (the code before the patch). Assume that the
__ompt_get_task_info_internal is called with the argument “ancestor_level == 2”,
while the initial master thread is executing the initial task.
After the while loop finishes, both “prev_lwt” and “prev_team” are equal to NULL.
If the called function should determine the “thread_num”, it will do that by
executing the assignment “*thread_num = prev_team->t.t_master_tid”.
Since “prev_team” is NULL, dereferencing it leads to a SEGFAULT.
Also, this patch may be considered as a simple performance optimization.
Assume that the hierarchy of active tasks contains two tasks.
If the __ompt_get_task_info_internal is called with the argument
“ancestor_level==1000”, there’s no need to execute more that two iterations
of the while before detecting that the task at the requested “ancestor_level”
doesn’t exist.
This patch provides the simple test cases that validates the behaviour of
the __ompt_get_task_info_internal function in case when the task doesn’t exist
at the requested “ancestor_level”.