<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Frontend crash trying to evaluate constexpr (valid code)" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23861&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=gSsz6nP6aIPLWdE0llIg7jDBQko5G5NlNYv6oeA8DyM&s=z6iAQDbSc2FnR1qkhxPXkx2Hif3uDlf_bL4ENMVxkVk&e=">23861</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Frontend crash trying to evaluate constexpr (valid code)
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </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>C++14
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>davide@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>[davide@rabbit1 /exps/llvm2/build/bin]$ ./clang -std=c++14 crash.cc
Assertion failed: (Result && "missing value for local variable"), function
evaluateVarDeclInit, file ../tools/clang/lib/AST/ExprConstant.cpp, line 1964.
clang-3.7: error: unable to execute command: Abort trap (core dumped)

######################

#include <iostream>

int main() {
    constexpr int i = 1;
    struct A {
        constexpr int a() { return i; }
    };
}

######################

evalValDeclInit() tries to get the value of 'VD' as temporary based on the
frame, which turns out to be null, triggering the assert.
In fact, we have the value for that VarDecl, and the following (probably wrong)
patch forces the evaluation.
I'll try to investigate further, but let's keep track this on bugzilla so I
won't forget. Ideas welcome.

(gdb) p VD->dump() 
VarDecl 0x807cc7e38 <crash2.cc:4:5, col:23> col:19 referenced i 'const int'
cinit
`-IntegerLiteral 0x807cc7e98 <col:23> 'int' 1 

Index: AST/ExprConstant.cpp
===================================================================
--- AST/ExprConstant.cpp        (revision 239766)
+++ AST/ExprConstant.cpp        (working copy)
@@ -1961,6 +1961,13 @@
   // If this is a local variable, dig out its value.
   if (Frame) {
     Result = Frame->getTemporary(VD);
+    // Try to evaluate the hard way.
+#if 1
+    if (!Result) {
+      VD->evaluateValue();
+      Result = VD->getEvaluatedValue();
+    }
+#endif
     assert(Result && "missing value for local variable");
     return true;
   }</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>