<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 - Clang crashes in CodeGen on invalid code in a template instantiation"
href="https://bugs.llvm.org/show_bug.cgi?id=39031">39031</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang crashes in CodeGen on invalid code in a template instantiation
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>enhancement
</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>rtrieu@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Expected:
Clang generates an error that an int can not be called. T() is an int in the
instantation.
Actual:
Clang crashes
$ cat test.cc
template <typename>
struct S {
template <typename>
struct Wrapper;
template <>
struct Wrapper<int> {
template <typename T>
void operator()(T) {
T()();
}
};
};
void Run() {
S<int>::Wrapper<int>()(1);
}
$ clang test.cc
...
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. test.cc:9:10: Generating code for declaration
'S<int>::Wrapper<int>::operator()'
...
#4 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr
const*)
#5 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool)
#6 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*)
#7 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*,
llvm::ArrayRef<clang::Attr const*>)
#8
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot)
#9
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&,
clang::Stmt const*)
#10 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
#11
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
#12 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
#13 clang::CodeGen::CodeGenModule::EmitDeferred()
#14 clang::CodeGen::CodeGenModule::Release()
#15 (anonymous
namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&)
Making struct S not a template gives a better error message:
test.cc:10:7: error: called object type 'int' is not a function or function
pointer
T()();
^~~
test.cc:16:20: note: in instantiation of function template specialization
'S::Wrapper<int>::operator()<int>' requested here
S::Wrapper<int>()(1);
^
1 error generated.</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>