Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
llvmbot opened this issue Oct 1, 2014 · 9 comments
Labels
bugzilla Issues migrated from bugzilla c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 1, 2014

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
Copy link
Collaborator Author

llvmbot commented Jan 26, 2015

No description provided.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@Endilll
Copy link
Contributor

Endilll commented Sep 13, 2023

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)

@Endilll Endilll added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash-on-invalid confirmed Verified by a second party labels Sep 13, 2023
@llvmbot
Copy link
Collaborator Author

llvmbot commented Sep 13, 2023

@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.  <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

@shafik
Copy link
Collaborator

shafik commented Sep 13, 2023

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
Copy link
Collaborator

shafik commented Sep 13, 2023

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
Copy link
Collaborator

shafik commented Sep 13, 2023

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

// Transform the first part of the nested-name-specifier that qualifies
// the member name.
NamedDecl *FirstQualifierInScope
= getDerived().TransformFirstQualifierInScope(
E->getFirstQualifierFoundInScope(),
E->getQualifierLoc().getBeginLoc());

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

@shafik
Copy link
Collaborator

shafik commented Sep 14, 2023

I think the unreachable here:

// We should have found something, but didn't.
llvm_unreachable("Unable to find instantiation of declaration!");

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
Copy link
Collaborator

shafik commented Oct 26, 2023

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

@HerrCai0907
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants