<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - NULL pointer dereference in FillInEmptyInitForField"
   href="https://bugs.llvm.org/show_bug.cgi?id=50538">50538</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>NULL pointer dereference in FillInEmptyInitForField
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>radwanski.michal@outlook.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24901" name="attach_24901" title="Stack trace">attachment 24901</a> <a href="attachment.cgi?id=24901&action=edit" title="Stack trace">[details]</a></span>
Stack trace

Clang crashes when compiling. According to godbolt.org, this affects all
versions since 6.0.0. Tested on Fedora 34, with clang 12 from repositories.

POC:

template<typename Ti>
struct Wrap { Ti _; };
template<typename Ti, typename = decltype(Wrap<Ti> {0})>
using Void = void;
template<typename, typename = void>
struct variant;
template<typename Ti>
struct variant< Ti, Void<Ti> >;
struct S { int x; variant<S>& v; };
variant<S> v;

This code was hand-minimized from this one (using libstdc++):

#include <variant>
struct S;
using V = std::variant<int, S>;
struct S { int x; V& v; };
V l = 0;

After a bit of investigation, I come to conclusion, that there is a null
pointer dereference in FillInEmptyInitForField:

          InitListExpr *ILE 
/* some code */
          << ILE->getSyntacticForm()->getSourceRange();
Here, ILE->getSyntacticForm() evaluates to nullptr. I don't know enough
internals to know how to fix it.


I'm attaching the full stack trace I get. Top entries (excluding those from the
signal handler) are inline here:

 #4 0x00007f7e9edb80d6 clang::Stmt::getSourceRange() const
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/AST/Stmt.cpp:325:3
 #5 0x00007f7e9f436737 clang::Sema::SemaDiagnosticBuilder const&
clang::Sema::SemaDiagnosticBuilder::operator<<<clang::SourceRange,
void>(clang::SourceRange&&) const
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../include/clang/Sema/Sema.h:1683:7
 #6 0x00007f7e9f436737 FillInEmptyInitForField
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/Sema/SemaInit.cpp:697:54
 #7 0x00007f7e9f436d16 FillInEmptyInitializations
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/Sema/SemaInit.cpp:820:9
 #8 0x00007f7e9f4364b6 FillInEmptyInitForField
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/Sema/SemaInit.cpp:729:31
 #9 0x00007f7e9f436d16 FillInEmptyInitializations
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/Sema/SemaInit.cpp:820:9
#10 0x00007f7e9f439c5d InitListChecker
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/Sema/SemaInit.cpp:965:5
#11 0x00007f7e9f439f17 diagnoseListInit
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/Sema/SemaInit.cpp:8912:3
#12 0x00007f7e9f43aad7 clang::InitializationSequence::Diagnose(clang::Sema&,
clang::InitializedEntity const&, clang::InitializationKind const&,
llvm::ArrayRef<clang::Expr*>)
/usr/src/debug/clang-12.0.0-0.3.rc1.fc34.x86_64/x86_64-redhat-linux-gnu/../lib/Sema/SemaInit.cpp:9361:5</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>