Another update on this:

> On Jun 30, 2025, at 11:51, Qing Zhao <qing.z...@oracle.com> wrote:
>> 
>>>   For each single predecessor block, locate the conditional statement
>>>   in the end of the block. determine whether the STMT is on the taken
>>>   path of the condition. Add these two information to each event of
>>>   the path.  */
>>> 
>>> 
>>> The good news is:  With the above simple heuristic and a simple back 
>>> tracing of  the CFG, all the
>>> current testing cases for the following PRs passed without any issue:
>>> 
>>> PR109071
>>> PR88771
>>> PR85788
>>> PR108770
>>> PR106762
>>> PR115274
>>> PR117179
>> 
>> Nice.  An incremental improvement would be to instead of handling
>> single predecessors, skip to the immediate dominator - this way
>> uninteresting intermediate CFG is skipped.  This might be confusing
>> and the next "step" could be very far away, not sure how to best
>> handle this.  But it would handle intermediate conditional code, like
>> 
>> if (i < 10)
>>   {
>>      if (dollar)
>>        printf ("dollar");
>>      else
>>        printf ("euro");
>>      printf ("%d", amout[i]);
>>   }
>> 
>> where you'd not able to go up to if (i < 10).
> 
> Yes, immediate dominator should work for such cases. 
>> Maybe a simple heuristic
>> on number of line to not skip too far works, or simply ignore this
>> for now, or simply only use immediate dominators for the first
>> condition to be printed?
> 
> I will experiment a little bit on this.  Do you have any more complicate 
> testing cases? That will be very helpful.

  /* For the following code:

  if (i == -1)
    {
      if (is_dollar)
        printf ("dollar");
      else
        printf ("euro");
      a[i] = -1;
    }
  else
    a[i] = i;

  it has the following CFG:
         B2
        /  \
       V    \
      B3     \
      / \       \
     V   V     V
     B4  B5     B7
       \ /
        V
        B6

  the STMT is in B6, and the interesting condition for the diagnostic
  is in the edge B2->B3.
  We should locate the immediate dominator of B6, i.e., B3, then check
  whether it has a single predecessor.
  */

If the current block doesn’t have a single predecessor,  We can get the 
immediate dominator of the current block,
And then backtracing to its single predecessor to locate the interesting 
condition. 

With this improvement.  All the old testing cases and these new testing cases 
works well. 

Let me know if you have any more comments and suggestions.

Thanks a lot.

Qing


Reply via email to