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

[Regression] clang 18 compiler crash involving auto return type, auto-conversion and source_location #92680

Closed
alexkaratarakis opened this issue May 19, 2024 · 5 comments · Fixed by #93383

Comments

@alexkaratarakis
Copy link

alexkaratarakis commented May 19, 2024

Min repro

#include <memory>
#include <source_location>

struct IntConstuctible
{
    IntConstuctible() = default;

    IntConstuctible(int,
                    const std::source_location& /*loc*/ = std::source_location::current()) noexcept
    {
    }
};

static auto construct_at_address_of(IntConstuctible& p, int a)
{
    //
    return std::construct_at(&p, a);
}

int main()
{
    IntConstuctible instance{};
    construct_at_address_of(instance, 1);
    return 0;
}

Godbolt Link

https://godbolt.org/z/a4TxoE9jv

Additional notes

  1. Repros in clang-18, including the currently-latest release 18.1.6.
  2. Does not repro with clang-17.
  3. Specifying the return type of construct_at_address_of() explicitly does not crash.
  4. Removing the return from construct_at_address_of() does not crash.
  5. Having no source_location parameter in the auto-converted type does not crash.
  6. Passing a std::source_location::current() instead of relying on the default parameter does not crash.

Stack dump

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-18.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -Wall -Wextra -pedantic-errors <source>
1.	<eof> parser at end of file
2.	<source>:20:5: LLVM IR generation of declaration 'main'
3.	<source>:20:5: Generating code for declaration 'main'
 #0 0x000000000351ae38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351ae38)
 #1 0x0000000003518f84 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3518f84)
 #2 0x0000000003467018 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000737126e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000000002f4b6fa llvm::FunctionType::get(llvm::Type*, llvm::ArrayRef<llvm::Type*>, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2f4b6fa)
 #5 0x0000000003b7623e clang::CodeGen::CodeGenTypes::GetFunctionType(clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3b7623e)
 #6 0x000000000392c7b3 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x392c7b3)
 #7 0x00000000038ec7aa clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38ec7aa)
 #8 0x0000000003bd9196 EmitFunctionDeclPointer(clang::CodeGen::CodeGenModule&, clang::GlobalDecl) CGExpr.cpp:0:0
 #9 0x0000000003be7db4 EmitDirectCallee(clang::CodeGen::CodeGenFunction&, clang::GlobalDecl) CGExpr.cpp:0:0
#10 0x0000000003c023fd clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c023fd)
#11 0x0000000003c027cd clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c027cd)
#12 0x0000000003c4bee5 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#13 0x0000000003c40612 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#14 0x0000000003c428c3 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c428c3)
#15 0x0000000003be5a1e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3be5a1e)
#16 0x0000000003bff3fb clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3bff3fb)
#17 0x0000000003821c9e clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3821c9e)
#18 0x0000000003827b39 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3827b39)
#19 0x0000000003885ec4 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3885ec4)
#20 0x0000000003891492 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3891492)
#21 0x00000000038ec95b clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38ec95b)
#22 0x00000000038e86d5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38e86d5)
#23 0x00000000038e9350 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38e9350)
#24 0x00000000038f13e7 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#25 0x0000000003d5cc96 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#26 0x0000000003d4e9b9 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d4e9b9)
#27 0x0000000005b963a4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x5b963a4)
#28 0x0000000003d5a725 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d5a725)
#29 0x0000000003fe2aa1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3fe2aa1)
#30 0x0000000003f6010b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3f6010b)
#31 0x00000000040c2473 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x40c2473)
#32 0x0000000000c19746 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc19746)
#33 0x0000000000c1211d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x0000000003da1979 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
#35 0x0000000003467443 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467443)
#36 0x0000000003da1b99 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
#37 0x0000000003d69d17 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d69d17)
#38 0x0000000003d6a6cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d6a6cd)
#39 0x0000000003d7445c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d7445c)
#40 0x0000000000c16a21 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc16a21)
#41 0x0000000000b0fa84 main (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xb0fa84)
#42 0x0000737126e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#43 0x0000737126e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#44 0x0000000000c1191e _start (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc1191e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
@github-actions github-actions bot added the clang Clang issues not falling into any other category label May 19, 2024
@dtcxzyw dtcxzyw added clang:codegen crash-on-valid and removed clang Clang issues not falling into any other category labels May 19, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 19, 2024

@llvm/issue-subscribers-clang-codegen

Author: Alexander Karatarakis (alexkaratarakis)

### Min repro ```C++ #include <memory> #include <source_location>

struct IntConstuctible
{
IntConstuctible() = default;

IntConstuctible(int,
                const std::source_location&amp; /*loc*/ = std::source_location::current()) noexcept
{
}

};

static auto construct_at_address_of(IntConstuctible& p, int a)
{
//
return std::construct_at(&p, a);
}

int main()
{
IntConstuctible instance{};
construct_at_address_of(instance, 1);
return 0;
}


### Godbolt Link
https://godbolt.org/z/a4TxoE9jv


### Additional notes
1) Repros in clang-18, including the currently-latest release 18.1.6. 
2) Does not repro with clang-17.
3) Specifying the return type of `construct_at_address_of()` explicitly does not crash. 
4) Removing the `return`  from `construct_at_address_of()` does not crash.
5) Having no `source_location` parameter in the auto-converted type does not crash. 
6) Passing a `std::source_location::current()` instead of relying on the default parameter does not crash.


### Stack dump

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-18.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -Wall -Wextra -pedantic-errors <source>

  1. <eof> parser at end of file
  2. <source>:20:5: LLVM IR generation of declaration 'main'
  3. <source>:20:5: Generating code for declaration 'main'
    #0 0x000000000351ae38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351ae38)
    #1 0x0000000003518f84 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3518f84)
    #2 0x0000000003467018 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
    #3 0x0000737126e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
    #4 0x0000000002f4b6fa llvm::FunctionType::get(llvm::Type*, llvm::ArrayRef<llvm::Type*>, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2f4b6fa)
    #5 0x0000000003b7623e clang::CodeGen::CodeGenTypes::GetFunctionType(clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3b7623e)
    #6 0x000000000392c7b3 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x392c7b3)
    #7 0x00000000038ec7aa clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38ec7aa)
    #8 0x0000000003bd9196 EmitFunctionDeclPointer(clang::CodeGen::CodeGenModule&, clang::GlobalDecl) CGExpr.cpp:0:0
    #9 0x0000000003be7db4 EmitDirectCallee(clang::CodeGen::CodeGenFunction&, clang::GlobalDecl) CGExpr.cpp:0:0
    #10 0x0000000003c023fd clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c023fd)
    #11 0x0000000003c027cd clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c027cd)
    #12 0x0000000003c4bee5 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
    #13 0x0000000003c40612 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
    #14 0x0000000003c428c3 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c428c3)
    #15 0x0000000003be5a1e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3be5a1e)
    #16 0x0000000003bff3fb clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3bff3fb)
    #17 0x0000000003821c9e clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3821c9e)
    #18 0x0000000003827b39 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3827b39)
    #19 0x0000000003885ec4 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3885ec4)
    #20 0x0000000003891492 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3891492)
    #21 0x00000000038ec95b clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38ec95b)
    #22 0x00000000038e86d5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38e86d5)
    #23 0x00000000038e9350 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38e9350)
    #24 0x00000000038f13e7 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
    #25 0x0000000003d5cc96 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
    #26 0x0000000003d4e9b9 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d4e9b9)
    #27 0x0000000005b963a4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x5b963a4)
    #28 0x0000000003d5a725 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d5a725)
    #29 0x0000000003fe2aa1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3fe2aa1)
    #30 0x0000000003f6010b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3f6010b)
    #31 0x00000000040c2473 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x40c2473)
    #32 0x0000000000c19746 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc19746)
    #33 0x0000000000c1211d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
    #34 0x0000000003da1979 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
    #35 0x0000000003467443 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467443)
    #36 0x0000000003da1b99 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
    #37 0x0000000003d69d17 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d69d17)
    #38 0x0000000003d6a6cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d6a6cd)
    #39 0x0000000003d7445c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d7445c)
    #40 0x0000000000c16a21 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc16a21)
    #41 0x0000000000b0fa84 main (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xb0fa84)
    #42 0x0000737126e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
    #43 0x0000737126e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
    #44 0x0000000000c1191e _start (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc1191e)
    clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
    Compiler returned: 139

</details>

@shafik
Copy link
Collaborator

shafik commented May 19, 2024

Looks like a regression from clang-17: https://godbolt.org/z/rMfh4n69j

Unreachable:

undeduced type in IR-generation

CC @cor3ntin

@shafik shafik added the confirmed Verified by a second party label May 19, 2024
@antoniofrighetto
Copy link
Contributor

@cor3ntin This started to appear after 8c2b0d4, if it can be of any help.

@Endilll
Copy link
Contributor

Endilll commented May 23, 2024

Confirmed on trunk.
Reduced by me and C-Reduce (https://godbolt.org/z/cvEG7bsvM):

namespace std {
struct source_location {
  struct __impl {
    const char *_M_file_name;
    const char *_M_function_name;
    int _M_line;
    int _M_column;
  };
  using __builtin_ret_type = decltype(__builtin_source_location());
  static source_location current(__builtin_ret_type = __builtin_source_location());
};
} // namespace std

struct IntConstuctible {
  IntConstuctible(std::source_location = std::source_location::current());
};

template <typename>
auto construct_at(IntConstuctible) -> decltype(IntConstuctible()) {
  return {};
}

int main() {
  construct_at<IntConstuctible>({});
}

Clang 19.0 crash:

clang++: /root/build/tools/clang/include/clang/AST/TypeNodes.inc:39: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type*) const: Assertion `!T->isDependentType() && "should not see dependent types here"' failed.
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.	Per-file LLVM IR generation
3.	<source>:19:6: Generating code for declaration 'construct_at'
 #0 0x00000000039c0fc8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39c0fc8)
 #1 0x00000000039becac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39becac)
 #2 0x000000000390fe78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f2f25242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f2f252969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f2f25242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f2f252287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f2f2522871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f2f25239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000007364433 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7364433)
#10 0x000000000734c1d7 clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x734c1d7)
#11 0x00000000073632a7 clang::ASTContext::getTypeAlignInChars(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73632a7)
#12 0x00000000040f737a clang::CodeGen::CodeGenFunction::CreateIRTemp(clang::QualType, llvm::Twine const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40f737a)
#13 0x0000000003d7860c clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d7860c)
#14 0x0000000003d7d287 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d7d287)
#15 0x0000000003dde0b2 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3dde0b2)
#16 0x0000000003dd8a95 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3dd8a95)
#17 0x0000000003de49cd clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3de49cd)
#18 0x0000000003de7273 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3de7273)
#19 0x0000000004290ffe (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#20 0x000000000428ec75 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x428ec75)
#21 0x00000000062ea94c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62ea94c)
#22 0x000000000428f418 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x428f418)
#23 0x0000000004513249 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4513249)
#24 0x000000000449a83e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x449a83e)
#25 0x00000000045fa0de clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45fa0de)
#26 0x0000000000c5451c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc5451c)
#27 0x0000000000c4d87a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x00000000042d2639 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
#29 0x0000000003910324 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3910324)
#30 0x00000000042d2c2f 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
#31 0x0000000004298ce5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4298ce5)
#32 0x000000000429974d 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+++0x429974d)
#33 0x00000000042a1445 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42a1445)
#34 0x0000000000c51a25 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc51a25)
#35 0x0000000000b33244 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb33244)
#36 0x00007f2f25229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#37 0x00007f2f25229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#38 0x0000000000c4d32e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc4d32e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

@Endilll Endilll added the c++20 label May 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 23, 2024

@llvm/issue-subscribers-c-20

Author: Alexander Karatarakis (alexkaratarakis)

### Min repro ```C++ #include <memory> #include <source_location>

struct IntConstuctible
{
IntConstuctible() = default;

IntConstuctible(int,
                const std::source_location&amp; /*loc*/ = std::source_location::current()) noexcept
{
}

};

static auto construct_at_address_of(IntConstuctible& p, int a)
{
//
return std::construct_at(&p, a);
}

int main()
{
IntConstuctible instance{};
construct_at_address_of(instance, 1);
return 0;
}


### Godbolt Link
https://godbolt.org/z/a4TxoE9jv


### Additional notes
1) Repros in clang-18, including the currently-latest release 18.1.6. 
2) Does not repro with clang-17.
3) Specifying the return type of `construct_at_address_of()` explicitly does not crash. 
4) Removing the `return`  from `construct_at_address_of()` does not crash.
5) Having no `source_location` parameter in the auto-converted type does not crash. 
6) Passing a `std::source_location::current()` instead of relying on the default parameter does not crash.


### Stack dump

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-18.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -Wall -Wextra -pedantic-errors <source>

  1. <eof> parser at end of file
  2. <source>:20:5: LLVM IR generation of declaration 'main'
  3. <source>:20:5: Generating code for declaration 'main'
    #0 0x000000000351ae38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351ae38)
    #1 0x0000000003518f84 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3518f84)
    #2 0x0000000003467018 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
    #3 0x0000737126e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
    #4 0x0000000002f4b6fa llvm::FunctionType::get(llvm::Type*, llvm::ArrayRef<llvm::Type*>, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2f4b6fa)
    #5 0x0000000003b7623e clang::CodeGen::CodeGenTypes::GetFunctionType(clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3b7623e)
    #6 0x000000000392c7b3 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x392c7b3)
    #7 0x00000000038ec7aa clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38ec7aa)
    #8 0x0000000003bd9196 EmitFunctionDeclPointer(clang::CodeGen::CodeGenModule&, clang::GlobalDecl) CGExpr.cpp:0:0
    #9 0x0000000003be7db4 EmitDirectCallee(clang::CodeGen::CodeGenFunction&, clang::GlobalDecl) CGExpr.cpp:0:0
    #10 0x0000000003c023fd clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c023fd)
    #11 0x0000000003c027cd clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c027cd)
    #12 0x0000000003c4bee5 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
    #13 0x0000000003c40612 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
    #14 0x0000000003c428c3 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3c428c3)
    #15 0x0000000003be5a1e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3be5a1e)
    #16 0x0000000003bff3fb clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3bff3fb)
    #17 0x0000000003821c9e clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3821c9e)
    #18 0x0000000003827b39 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3827b39)
    #19 0x0000000003885ec4 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3885ec4)
    #20 0x0000000003891492 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3891492)
    #21 0x00000000038ec95b clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38ec95b)
    #22 0x00000000038e86d5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38e86d5)
    #23 0x00000000038e9350 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x38e9350)
    #24 0x00000000038f13e7 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
    #25 0x0000000003d5cc96 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
    #26 0x0000000003d4e9b9 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d4e9b9)
    #27 0x0000000005b963a4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x5b963a4)
    #28 0x0000000003d5a725 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d5a725)
    #29 0x0000000003fe2aa1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3fe2aa1)
    #30 0x0000000003f6010b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3f6010b)
    #31 0x00000000040c2473 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x40c2473)
    #32 0x0000000000c19746 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc19746)
    #33 0x0000000000c1211d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
    #34 0x0000000003da1979 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
    #35 0x0000000003467443 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467443)
    #36 0x0000000003da1b99 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
    #37 0x0000000003d69d17 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d69d17)
    #38 0x0000000003d6a6cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d6a6cd)
    #39 0x0000000003d7445c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d7445c)
    #40 0x0000000000c16a21 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc16a21)
    #41 0x0000000000b0fa84 main (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xb0fa84)
    #42 0x0000737126e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
    #43 0x0000737126e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
    #44 0x0000000000c1191e _start (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc1191e)
    clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
    Compiler returned: 139

</details>

cor3ntin added a commit to cor3ntin/llvm-project that referenced this issue May 25, 2024
In order for their dependency to be computed correctly,
SourceLocExpr should refer to the context in which they are used.

Fixes llvm#92680
cor3ntin added a commit that referenced this issue May 26, 2024
In order for their dependency to be computed correctly, SourceLocExpr
should refer to the context in which they are used.

Fixes #92680
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants