<html>
    <head>
      <base href="http://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 --- - Clang assertion failure when issuing a diagnostic while compiling from an AST file"
   href="http://llvm.org/bugs/show_bug.cgi?id=15377">15377</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang assertion failure when issuing a diagnostic while compiling from an AST file
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>thonermann@coverity.com
          </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>Created <span class=""><a href="attachment.cgi?id=10100" name="attach_10100" title="Gdb backtrace for the assertion failure">attachment 10100</a> <a href="attachment.cgi?id=10100&action=edit" title="Gdb backtrace for the assertion failure">[details]</a></span>
Gdb backtrace for the assertion failure

This assertion failure reproduces with Clang 3.2 and Clang trunk as of
26-Feb-2013.

The following code is ill-formed:

$ cat t.cpp
template<typename T>
T tf() {
    static const T i;
    return i;
}

void f() {
    tf<int>();
}


Compiling it directly to object file results in an appropriate diagnostic:

$ clang -c t.cpp
t.cpp:5:20: error: default initialization of an object of const type 'const
int'
    static const T i;
                   ^
t.cpp:10:5: note: in instantiation of function template specialization
'tf<int>'
      requested here
    tf<int>();
    ^
1 error generated.


Emitting to an AST file and then compiling from it results in an assertion
failure when constructing the diagnostic:

$ clang -emit-ast t.cpp
$ clang -v -c t.ast 
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
 "/nfs/thonermann/clang-3.2/installs/linux64-debug/bin/clang" -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
t.ast -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version
2.22 -momit-leaf-frame-pointer -v -coverage-file
/nfs/thonermann/prevent-clang/clang/testcases/emit/globals/psf-useval-template-function-local-static-const-int/t.o
-resource-dir
/nfs/thonermann/clang-3.2/installs/linux64-debug/bin/../lib/clang/3.2
-fdebug-compilation-dir
/nfs/thonermann/prevent-clang/clang/testcases/emit/globals/psf-useval-template-function-local-static-const-int
-ferror-limit 19 -fmessage-length 197 -mstackrealign -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -o t.o -x ast t.ast
clang -cc1 version 3.2 based upon LLVM 3.2svn default target
x86_64-unknown-linux-gnu
clang:
/nfs/thonermann/clang-3.2/llvm-3.2/tools/clang/lib/Frontend/TextDiagnosticPrinter.cpp:148:
virtual void
clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level,
const clang::Diagnostic&): Assertion `TextDiag && "Unexpected diagnostic
outside source file processing"' failed.
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to
<a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a> and include the crash backtrace, preprocessed source, and
associated run script.
clang: note: diagnostic msg: Error generating preprocessed source(s) - no
preprocessable inputs.

A backtrace is attached.</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>