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

    <tr>
        <th>Summary</th>
        <td>
            Clang coverage crash due to invalid source location in AST nodes.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Repro example:
```
namespace std { template <typename> class initializer_list {}; }

template <typename> struct T {
 T(std::initializer_list<int>, int = int());
  bool b;
};

template <typename> struct S1 {
  static void foo() {
 class C;
    0 ? T<C>{} : T<C>{};
    0 ? 1 : 2;
 }
};

void bar() {
 S1<int>::foo();
}
```
Command:
`clang++  -fprofile-instr-generate -fcoverage-mapping -std=c++20 -c -o a.o a.cpp`

It's due to the visited expression not having valid source locations, which is dropped intentionally here: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536

https://reviews.llvm.org/D147073 added a workaround for that so clang only crash on assertion build. The real is to make sure the expression has valid source locations.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlMFu4zYQhp-GugwkSKRs2QcdYjkGCvTUGOiil2JEji12KVIlKSfp0xeUncS7mz0sIIswyZn55-MvYgj6bIlattqx1T7DOQ7Ot3_RvzPaP-esd-q1_YMm74BecJwMMfHAyj0rH9i6vD3LX4sjhQklQYgKWLODSONkMBIw0cXXidIOJh5BGgwBtNVRo9H_kf_b6BBTCGv2TOwgDdcSy_tneUL0s4xwXCKXnXBkfBOiShrFw_cVmOi0jUw8Mt6BthGY2KeR8Q3j2_SItzzQO2egf5-4CvsFUU_VnSoIEaOWcHFawcm5a8G7DVci3V19gBKYOMCRia5Lkhc4wMTDd1OfxFTLNv6x8sHzhzYWST36HyQ9VR-4Fprvur-B8pkTOjeOaNW9UaRBe2Z8x_gOID9N3p20oVzbEH1-Jks-ocxP0l3I45nyEadJ2zPky2nu5TWWl5BLyB1gkX5ymt6LXt-_RcabAGomiA7iQHDRQUdSQC-TpxC0s2BdhAEvKf0FjVYQ3OwlgXESo3Y2JH88D1oOoAMo76aJVDIK2bSMxrzCQD59CTDEOIXUKT8wfjjrOMx9Id3I-MGYy9uQT979QzIyfuiN62-zzp_zal2URcX44UboYHRafqIRb8Pjy-S7L1-WZrn4vVqJ9X3H3wrwdNH0HIqUvnA-JdxXdVM2AlApUoDw7PxX9G62yYoe4oARgoOlPjhrXkF6DAM4CxgC-dQy9LM2qoDjQOAJTeISHYz4lSDMnhbSd4QHDD9BW2SqFWortphRW603lRC83lTZ0Io1kepX25VqlFzVNZ02TY2nSuC6buSJZ7rlJRdlXXFe1puyKuRm22xPYr2pqVJyvWJ1SSNq8959pkOYqV3zqlxlBnsyYbnnOL_R5unK8-1yRP18Dqwu00XxwS-LOhpquwXOmzlvgG4m0_bTTkFbeHg6gnWKQpHN3rS_7JVFfmD8sHTwfwAAAP__aua5bA">