llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.4k stars 12.15k forks source link

"Unable to find instantiation of declaration!", UNREACHABLE executed at SemaTemplateInstantiateDecl.cpp:4616 #21483

Open llvmbot opened 10 years ago

llvmbot commented 10 years ago
Bugzilla Link 21109
Version trunk
OS Windows NT
Attachments auto-generated repro
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

Stack dump:

0.      Program arguments: /usr/local/clang-trunk/bin/clang -cc1 -triple i386-pc-windows-cygnus -emit-obj -disable-free -main-file-name search.cpp -mrelocation-model static -mdisable-fp-elim -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -ffp-contract=fast -ffast-math -masm-verbose -mconstructor-aliases -target-cpu core-avx-i -target-linker-version 2.24.51.20140703 -dwarf-column-info -coverage-file /cygdrive/c/Users/eric/Code/range-build-clang/test/algorithm/CMakeFiles/alg.search.dir/search.cpp.o -resource-dir /usr/local/clang-trunk/bin/../lib/clang/3.6.0 -D NDEBUG -I /cygdrive/c/Users/eric/Code/range-v3/include -Ofast -Wall -Wno-unused-function -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /cygdrive/c/Users/eric/Code/range-build-clang/test/algorithm -ferror-limit 19 -fmessage-length 120 -mstackrealign -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o CMakeFiles/alg.search.dir/search.cpp.o -x c++ /cygdrive/c/Users/eric/Code/range-v3/test/algorithm/search.cpp
1.      <eof> parser at end of file
2.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/range_algorithm.hpp:44:18: instantiating function definition 'operator()'
3.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/algorithm/search.hpp:185:16: instantiating function definition 'operator()'
4.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/algorithm/search.hpp:88:23: instantiating function definition 'sized_impl'
5.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:144:15: instantiating function definition 'operator()'
6.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:63:18: instantiating function definition 'operator()'
7.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:52:25: instantiating function definition 'impl'
8.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:31:18: instantiating function definition 'operator()'
9.      /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/counted_iterator.hpp:69:33: instantiating function definition 'advance'
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.6.0 (trunk 218741)
Target: i386-pc-windows-cygnus
Thread model: posix
llvmbot commented 9 years ago
Endilll commented 1 year ago

Still crashing as of post-17 trunk: https://godbolt.org/z/9dfzWd8qh Reduced by me and C-Reduce:

struct bidirectional_iterator {};

template <typename I>
struct counted_cursor {
  struct mixin {
    friend void advance(counted_cursor<I>::mixin it) {
      it.mixin::type;
    }
  };
};

int main() {
  advance(counted_cursor<bidirectional_iterator>::mixin{});
}

Trunk crash:

Unable to find instantiation of declaration!
UNREACHABLE executed at /root/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6344!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.  <eof> parser at end of file
2.  <source>:6:17: instantiating function definition 'advance'
 #0 0x00000000036b2ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36b2ff8)
 #1 0x00000000036b0cbc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36b0cbc)
 #2 0x00000000035fa0e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f2b27bec420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f2b276af00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f2b2768e859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x000000000360538a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x360538a)
 #7 0x00000000069a0dfd clang::Sema::FindInstantiatedDecl(clang::SourceLocation, clang::NamedDecl*, clang::MultiLevelTemplateArgumentList const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69a0dfd)
 #8 0x0000000006906661 (anonymous namespace)::TemplateInstantiator::TransformDecl(clang::SourceLocation, clang::Decl*) SemaTemplateInstantiate.cpp:0:0
 #9 0x000000000694b1ab clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXDependentScopeMemberExpr(clang::CXXDependentScopeMemberExpr*) SemaTemplateInstantiate.cpp:0:0
#10 0x000000000691bdc9 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#11 0x00000000069513ef clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#12 0x0000000006952614 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#13 0x000000000695822a clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x695822a)
#14 0x00000000069a783b clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69a783b)
#15 0x00000000069a5c9f clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69a5c9f)
#16 0x0000000005f7f7e9 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (.part.0) Sema.cpp:0:0
#17 0x0000000005f7ffc2 clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f7ffc2)
#18 0x0000000005e158a8 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e158a8)
#19 0x0000000005e09a2a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e09a2a)
#20 0x0000000004912a28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4912a28)
#21 0x000000000417b4a9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x417b4a9)
#22 0x00000000040fb69e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40fb69e)
#23 0x000000000425977e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x425977e)
#24 0x0000000000bd90ae cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd90ae)
#25 0x0000000000bd0c3a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x0000000003f5c9d9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#27 0x00000000035fa594 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35fa594)
#28 0x0000000003f5cfcf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#29 0x0000000003f25345 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f25345)
#30 0x0000000003f25dad clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f25dad)
#31 0x0000000003f2dcd5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f2dcd5)
#32 0x0000000000bd681c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd681c)
#33 0x0000000000ad2dd1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xad2dd1)
#34 0x00007f2b27690083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#35 0x0000000000bd071e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd071e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

| | | | --- | --- | | Bugzilla Link | [21109](https://llvm.org/bz21109) | | Version | trunk | | OS | Windows NT | | Attachments | [auto-generated repro](https://user-images.githubusercontent.com/60944935/143750119-75c271ab-c954-4a3b-b696-5c80dee9c0d1.gz) | | Reporter | LLVM Bugzilla Contributor | | CC | @DougGregor | ## Extended Description Stack dump: 0. Program arguments: /usr/local/clang-trunk/bin/clang -cc1 -triple i386-pc-windows-cygnus -emit-obj -disable-free -main-file-name search.cpp -mrelocation-model static -mdisable-fp-elim -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -ffp-contract=fast -ffast-math -masm-verbose -mconstructor-aliases -target-cpu core-avx-i -target-linker-version 2.24.51.20140703 -dwarf-column-info -coverage-file /cygdrive/c/Users/eric/Code/range-build-clang/test/algorithm/CMakeFiles/alg.search.dir/search.cpp.o -resource-dir /usr/local/clang-trunk/bin/../lib/clang/3.6.0 -D NDEBUG -I /cygdrive/c/Users/eric/Code/range-v3/include -Ofast -Wall -Wno-unused-function -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /cygdrive/c/Users/eric/Code/range-build-clang/test/algorithm -ferror-limit 19 -fmessage-length 120 -mstackrealign -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o CMakeFiles/alg.search.dir/search.cpp.o -x c++ /cygdrive/c/Users/eric/Code/range-v3/test/algorithm/search.cpp 1. parser at end of file 2. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/range_algorithm.hpp:44:18: instantiating function definition 'operator()' 3. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/algorithm/search.hpp:185:16: instantiating function definition 'operator()' 4. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/algorithm/search.hpp:88:23: instantiating function definition 'sized_impl' 5. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:144:15: instantiating function definition 'operator()' 6. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:63:18: instantiating function definition 'operator()' 7. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:52:25: instantiating function definition 'impl' 8. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/iterator.hpp:31:18: instantiating function definition 'operator()' 9. /cygdrive/c/Users/eric/Code/range-v3/include/range/v3/utility/counted_iterator.hpp:69:33: instantiating function definition 'advance' clang: error: unable to execute command: Aborted clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.6.0 (trunk 218741) Target: i386-pc-windows-cygnus Thread model: posix
shafik commented 1 year ago

So in this case: https://godbolt.org/z/7Pra5jG1E

struct bidirectional_iterator {};

template <typename I>
struct counted_cursor {
  struct mixin {
    friend void advance(mixin it) {
      it.type;
    }
  };
};

int main() {
  advance(counted_cursor<bidirectional_iterator>::mixin{});
}

we obtain a diagnostic, so something about the qualified name is preventing us from diagnosing this, I think.

There are a bunch of places we diagnose err_no_member.

shafik commented 1 year ago

Actually this may be a better example: https://godbolt.org/z/TxnWYfozr

because it looks like we are crashing in the lookup for mixin

struct bidirectional_iterator {};

template <typename I>
struct counted_cursor {
  struct mixin {
    friend void advance(mixin it) {
      it.mixin;
    }
  };
};

int main() {
  advance(counted_cursor<bidirectional_iterator>::mixin{});
}

but it looks like that diagnostic is also happening in Sema::BuildMemberReferenceExpr(...) which happens after the crash.

shafik commented 1 year ago

In the case with just it.mixin on this section:

https://github.com/llvm/llvm-project/blob/a866ce789eb99da4d7a486eeb60a53be6c75f4fd/clang/lib/Sema/TreeTransform.h#L13766-L13771

E->getFirstQualifierFoundInScope() gives us a nullptr so we don't progress any further and we eventually hit the diagnostic.

shafik commented 1 year ago

I think the unreachable here:

https://github.com/llvm/llvm-project/blob/347b3f120903fcdc255b78177cb584e4c0aa4b54/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L6343-L6344

is not correct. If we let the control flow through then we get a reasonable diagnostic:

qualLookNotExist2.cpp:7:17: error: no member named 'type' in 'counted_cursor<bidirectional_iterator>::mixin'
    7 |       it.mixin::type;
      |       ~~        ^
qualLookNotExist2.cpp:13:3: note: in instantiation of member function 'advance' requested here
   13 |   advance(counted_cursor<bidirectional_iterator>::mixin{});
      |   ^

CC @zygoloid wdyt?

shafik commented 1 year ago

My last two examples no longer crash on trunk but the original one does.

HerrCai0907 commented 1 year ago

Still crashing as of post-17 trunk: https://godbolt.org/z/9dfzWd8qh Reduced by me and C-Reduce:

struct bidirectional_iterator {};

template <typename I>
struct counted_cursor {
  struct mixin {
    friend void advance(counted_cursor<I>::mixin it) {
      it.mixin::type;
    }
  };
};

int main() {
  advance(counted_cursor<bidirectional_iterator>::mixin{});
}

It is not only a assert crash issue.

This code is valid in gcc but invalid in clang

struct bidirectional_iterator {};

template <typename I>
struct counted_cursor {
  struct mixin {
    int type;
    friend void advance(counted_cursor<I>::mixin it) {
      it.mixin::type;
    }
  };
};

int main() {
  advance(counted_cursor<bidirectional_iterator>::mixin{});
}

https://godbolt.org/z/M5Eshsdfr