<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 - LocalInstantiationScope::findInstantiationOf fails on template and lambda combination."
href="https://bugs.llvm.org/show_bug.cgi?id=35795">35795</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LocalInstantiationScope::findInstantiationOf fails on template and lambda combination.
</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>clang@siedentop.name
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=19618" name="attach_19618" title="Preprocessed CPP file.">attachment 19618</a> <a href="attachment.cgi?id=19618&action=edit" title="Preprocessed CPP file.">[details]</a></span>
Preprocessed CPP file.
The following is a reduced case which crashes the Clang frontend.
Specifically, the following assert() in
clang::LocalInstantiationScope::findInstantiationOf is triggered:
// If we didn't find the decl, then we either have a sema bug, or we have a
// forward reference to a label declaration. Return null to indicate that
// we have an uninstantiated label.
assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope");
return nullptr;
* Version: Git-Monorepo at 8b1b2746b79484e018206fa2505d0f8c3fad7401 Tue Jan 2
16:38:29 2018 +0000
* Reduced with CReduce. Skript used:
clang++ -std=c++1z -O0 -emit-llvm --compile preprocessed.cc 2>&1 | grep
"declaration not instantiated in this scope"
* Reducing the original preprocessed file found two other crashes in the
frontend, which I will report separately. I understand that separate bugs are
preferred? They have different stack traces.
* Command: /path/to/clang-6.0 -std=c++17 -O0 -emit-llvm -c filename.cpp
* Suggested duplicates are either too old or show a different error. But
obviously I might have missed something.
# Code:
Here is the original code. Initial credit goes to [Julian Becker][1].
#include <type_traits>
#include <functional>
#include <vector>
namespace detail {
template< class, class = std::void_t<> >
struct needs_unapply : std::true_type { };
template< class T >
struct needs_unapply<T, std::void_t<decltype(std::declval<T>()())>> :
std::false_type { }; }
template <typename F>
decltype(auto) curry(F&& f) {
if constexpr (detail::needs_unapply<decltype(f)>::value) {
return [f=f](auto&& x) {
return curry(
[x=x, f=f](auto&&...xs) -> decltype(f(x,xs...)) {
return f(x,xs...);
}
);
};
}
else return f();
}
struct Pt { int x; int y; };
int func(std::function<int(const Pt &)> f, const std::vector<Pt> &vec) {
int s = 0;
for (const auto &p : vec) { s += f(p); }
return s;
}
int main() {
const std::vector<Pt> vec = {{1, 2}, {3, 4}};
auto f = [](const Pt &pt) -> int { return pt.x; };
auto g = [](const Pt &pt) -> int { return pt.y; };
int sum = curry(func)(f)(vec);
int sum_y = curry(func)(g)(vec);
return sum + sum_y;
}
Here is the reduced code. I don't find it readable anymore.
struct a {}
template < b > using e = a;
template < class c > c __declval
template < class > using void_t = void;
template < class, class = void_t>
struct g :e< true >template < class h >
struct g< h, void_t< decltype(declval< h >() ) > >
template < typename i > auto curry(i f) {
g< decltype(f) >::d
return [f = f](auto ) {
curry([](auto ... ) -> decltype(f) {})}}
void func() {
int f;
curry(func)(f)
# Beginning of Backtrace in lldb:
[#0-8 Are related to assert handling.]
#9 0x00000000093dfa91
clang::LocalInstantiationScope::findInstantiationOf(clang::Decl const*)
/lhome/siedenc/src/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:2904:3
#10 0x000000000942940d clang::Sema::FindInstantiatedDecl(clang::SourceLocation,
clang::NamedDecl*, clang::MultiLevelTemplateArgumentList const&, bool)
/lhome/siedenc/src/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:4900:16
#11 0x00000000093e0c5f (anonymous
namespace)::TemplateInstantiator::TransformDecl(clang::SourceLocation,
clang::Decl*)
/lhome/siedenc/src/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:988:3
#12 0x00000000093f7d37 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformDeclRefExpr(clang::DeclRefExpr*)
/lhome/siedenc/src/llvm-project/clang/lib/Sema/TreeTransform.h:8862:7
#13 0x00000000093e7e34 (anonymous
namespace)::TemplateInstantiator::TransformDeclRefExpr(clang::DeclRefExpr*)
/lhome/siedenc/src/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:1398:47
#14 0x00000000093dc266 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
/lhome/siedenc/builds/llvm/tools/clang/include/clang/AST/StmtNodes.inc:477:1
#15 0x0000000009402230 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformDecltypeType(clang::TypeLocBuilder&,
clang::DecltypeTypeLoc)
/lhome/siedenc/src/llvm-project/clang/lib/Sema/TreeTransform.h:5512:31
#16 0x00000000093d304d clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&,
clang::TypeLoc)
/lhome/siedenc/src/llvm-project/clang/include/clang/AST/TypeNodes.def:89:1
# Detailed Command arguments:
# Crash reproducer for clang version 6.0.0
# Driver args: "-std=c++17" "-O0" "-emit-llvm" "-c" "preprocessed.cc"
# Original command: "/lhome/siedenc/builds/llvm/bin/clang-6.0" "-cc1"
"-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc" "-emit-llvm-uselists"
"-disable-free" "-main-file-name" "preprocessed.cc" "-mrelocation-model"
"static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno"
"-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array"
"-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb"
"-coverage-notes-file" "/lhome/siedenc/devel/clang-crash/preprocessed.gcno"
"-resource-dir" "/lhome/siedenc/builds/llvm/lib/clang/6.0.0"
"-I/lhome/siedenc/devel/athena/devel/include" "-I/opt/ros/jade/include"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8"
"-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/lhome/siedenc/builds/llvm/lib/clang/6.0.0/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-O0" "-std=c++17" "-fdeprecated-macro"
"-fdebug-compilation-dir" "/lhome/siedenc/devel/clang-crash" "-ferror-limit"
"19" "-fmessage-length" "241" "-fobjc-runtime=gcc" "-fcxx-exceptions"
"-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o"
"preprocessed.bc" "-x" "c++" "preprocessed.cc"
"/lhome/siedenc/builds/llvm/bin/clang-6.0" "-cc1" "-triple"
"x86_64-unknown-linux-gnu" "-emit-llvm-bc" "-emit-llvm-uselists"
"-disable-free" "-main-file-name" "preprocessed.cc" "-mrelocation-model"
"static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno"
"-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array"
"-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb"
"-coverage-notes-file" "/lhome/siedenc/devel/clang-crash/preprocessed.gcno"
"-O0" "-std=c++17" "-fdeprecated-macro" "-ferror-limit" "19" "-fmessage-length"
"241" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-x" "c++"
"preprocessed-ecd3c1.cpp"
[1]: <a href="https://twitter.com/awtem/status/804781466852950017">https://twitter.com/awtem/status/804781466852950017</a></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>