[llvm-bugs] [Bug 35795] New: LocalInstantiationScope::findInstantiationOf fails on template and lambda combination.
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jan 2 09:57:10 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=35795
Bug ID: 35795
Summary: LocalInstantiationScope::findInstantiationOf fails on
template and lambda combination.
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: clang at siedentop.name
CC: llvm-bugs at lists.llvm.org
Created attachment 19618
--> https://bugs.llvm.org/attachment.cgi?id=19618&action=edit
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]: https://twitter.com/awtem/status/804781466852950017
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180102/4cf99df4/attachment-0001.html>
More information about the llvm-bugs
mailing list