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

    <tr>
        <th>Summary</th>
        <td>
            ftime-trace: ParseDeclarationOrFunctionDefinition ends after its Source event
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          zammisget45
      </td>
    </tr>
</table>

<pre>
    Given a 1.cpp
```
#include <string.h>
```
executing `clang -c -ftime-trace 1.cpp` sometimes produce a json file with contents like the following:
(first few traceEvents, pid and tid were identical and cut for readability)

```
{"ts":1352,"cat":"Source","ph":"b","id":0,"name":"Source","args":{"detail":"/usr/include/features.h"}},
{"ts":1950,"cat":"Source","ph":"e","id":0,"name":"Source"},
{"ts":1307,"cat":"Source","ph":"b","id":0,"name":"Source","args":{"detail":"/usr/include/bits/libc-header-start.h"}},
{"ts":1967,"cat":"Source","ph":"e","id":0,"name":"Source"},
{"ts":1269,"cat":"Source","ph":"b","id":0,"name":"Source","args":{"detail":"/usr/include/string.h"}},
{"ts":4405,"cat":"Source","ph":"e","id":0,"name":"Source"},
{"ts":1982,"ph":"X","dur":2424,"name":"ParseDeclarationOrFunctionDefinition","args":{"detail":"/usr/include/string.h:28:1 <Spelling=/usr/include/sys/cdefs.h:140:24>"}},
{"ts":927,"ph":"X","dur":3503,"name":"Frontend"},
{"ts":4471,"ph":"X","dur":554,"name":"Backend"},
{"ts":10,"ph":"X","dur":5050,"name":"ExecuteCompiler"},
```

Note that *ParseDeclarationOrFunctionDefinition* ends at 4406, i.e. after the end of the Source event for *string.h* at 4405. Running this a few times will also produce reports where *ParseDeclarationOrFunctionDefinition* ends in the same millisecond as its Source event (which is ok).
Replacing 'string.h' with something bigger like 'list' will reliably produce *ParseDeclarationOrFunctionDefinition* events ending (10+ ms) after their Source events.

AFAICT the problem was introduced with the fixes for #56554.

I was able to reproduce it with
d6e714b10e102eb32e64e04bf177226dbe16d0e7 (Oct 2024)
83eb8aee4bf9d518b3a2b485640207e7717805b4 (Mar 2024, fix for #56554)

I could not reproduce the problem with
71b69dd21becdfbf8922674ce6ca4129926660ab (Mar 2024, before the fixes for #56554)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk1v2zgT_jX0hbBBjT4oHXxw7PpFD-920e5hr_wYWWxp0SCpuNlfvyDlOk3W3SRAgS1gJBLJmXnm4WieESGYw4i4JvUdqXcLMcXB-fVf4ng04YCxqhfS6Yf1_8w9jlTQYqVOJ8J2hG1Iwy6_-RVKMyo7aaSk3IbozXhYDaR8d_M0fkU1RTMeKGmYsmI80KWiyz6aIy6jFwovoRpGgztiWg_05J2eFFJBPwc30t5YpGcTB6rcGHGMgVrzBWkckPbOWnc244GUm28A2974EGmPZ5pDvLtPNgS29GQ0FaOm0Wh6Ro_UaByjUcLmZTVF2jtPPQotpLEmPhDoLm5vksHvCEDyDaTcFGUNBLYEQIk4LxGAT27yCtNr3joN1x15XTR6XmTz6yiO-CN74Q-XcHNwjVEYez1NYD8FT2B_uSQC-x5FnDyGVY7Md-kH25sJdDV7SwL4xgR-HLhk_BdkTpoEcG-NVMsBhUa_DFH4-Bommzcl9POYhKb7BZm89okXeKsqVv83vHXtP73_efWuJz-vQgXVjQi_Cx9wh8oKL6Jx4we_n0aVnnbYm9Gkp59BX7mBNqFNvffTCa3NnW93y-Qhla7S2IdsV1Qsw0-d-oVL6IC_hoqyZuUNKvY-N2n9r3RXFS9eE6Oub7F9J9SXlyIU7FX-WX2rYN5l2cKtO56MRf880DMRyH9_czEpkoiUwOZ15bChOOpARaRVxZqkT2aFKyr6iD6LG46auj4_ziVMMUlZ1igCm8ePanNxUq_ox2kck97GwQQqZhHMono21lJhg7vKq8eT8zHQ85Ck8K2wzZiBBXFEejTWmoDKjZqKQE0MTwETaM-DUQM1gbovBLrVTNpHPFmh8ngA_DEdPqt9H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