Skip to content

crash after hiding of class-scope using shadow declaration in a template #47028

Open
@zygoloid

Description

@zygoloid
Bugzilla Link 47684
Version unspecified
OS All
CC @DougGregor,@zygoloid

Extended Description

Testcase causes a broken AST and a crash in IR generation:

struct A {
    void f();
};
template<typename T> struct B : A {
    using A::f;
    static constexpr auto p = &B::f;
    void f();
};
auto v = B<int>::p;

The problem is that we inject a using shadow declaration for 'using A::f', and then try to retroactively remove it (after it was already used) when we see the later declaration of the member 'void f()'. Then during template instantiation, we don't instantiate the using-shadow declaration (it was already removed), so the '&B::f' has nothing to refer to.

Perhaps the best thing to do would be to reject any case where the UsingShadowDecl is referenced before being hidden (on the basis that this is a "reordering the declarations changes the meaning of the class" case).

Activity

wheatman

wheatman commented on Jul 15, 2023

@wheatman
Contributor

This still crashes on post 16 trunk(ba7cc56)
https://godbolt.org/z/nTGdTG3o1

It compiles fine with gcc 13.1

The crash gives the message

Unexpected undeduced type!
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:545!

The full dump is

Unexpected undeduced type!
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:545!
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 -std=c++20 <source>
1.	<eof> parser at end of file
2.	<source>:9:6: LLVM IR generation of declaration 'v'
3.	<source>:9:6: Generating code for declaration 'v'
 #0 0x0000555bbd69ac1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9ac1a)
 #1 0x0000555bbd69884c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9884c)
 #2 0x0000555bbd5e7020 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fa861f10420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fa8619dd00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fa8619bc859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x0000555bbd5f2dba (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39f2dba)
 #7 0x0000555bbda7775c clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e7775c)
 #8 0x0000555bbda78976 clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e78976)
 #9 0x0000555bbd949085 clang::CodeGen::CodeGenModule::EmitNullConstant(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d49085)
#10 0x0000555bbda13b31 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e13b31)
#11 0x0000555bbda33211 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e33211)
#12 0x0000555bbda33863 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e33863)
#13 0x0000555bbda3ad84 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.8518) CodeGenModule.cpp:0:0
#14 0x0000555bbe76a260 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#15 0x0000555bbe75daee clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b5daee)
#16 0x0000555bbfa3a214 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3a214)
#17 0x0000555bbe767560 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b67560)
#18 0x0000555bbe0892e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44892e9)
#19 0x0000555bbe01dc42 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441dc42)
#20 0x0000555bbe160c9f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4560c9f)
#21 0x0000555bbae22cc3 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1222cc3)
#22 0x0000555bbae1ade8 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#23 0x0000555bbde912f9 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
#24 0x0000555bbd5e74a5 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39e74a5)
#25 0x0000555bbde93eee clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4293eee)
#26 0x0000555bbde6060b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x426060b)
#27 0x0000555bbde611e3 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+++0x42611e3)
#28 0x0000555bbde69fd6 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4269fd6)
#29 0x0000555bbae20a8e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1220a8e)
#30 0x0000555bbad51cb1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1151cb1)
#31 0x00007fa8619be083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#32 0x0000555bbae1a4da _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x121a4da)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot

llvmbot commented on Jul 15, 2023

@llvmbot
Member

@llvm/issue-subscribers-clang-codegen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:codegenIR generation bugs: mangling, exceptions, etc.confirmedVerified by a second partycrash-on-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wheatman@EugeneZelenko@llvmbot

        Issue actions

          crash after hiding of class-scope using shadow declaration in a template · Issue #47028 · llvm/llvm-project