Issue 63884
Summary Assertion `!Call.isInvalid() && "Call to __builtin_memcpy cannot fail!"' on code with __restrict
Labels clang:frontend, crash
Assignees
Reporter wheatman
    The following code triggers an assertion and dump
https://gcc.godbolt.org/z/s8qj851hE on post 16 trunk(ba7cc56782dbf4a26c0a043dd33c7949366e2b0d) when compiling in c++ mode

```
struct Obj { int * __restrict myPtr[2]; };
int main() {
    Obj a, b;
    a = b;
    return 0;
}
```

the assertion is 
```
clang++: /root/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:14315: clang::StmtResult 
buildMemcpyForAssignmentOp(clang::Sema&, clang::SourceLocation, clang::QualType, const {anonymous}::ExprBuilder&, const {anonymous}::ExprBuilder&): 
Assertion `!Call.isInvalid() && "Call to __builtin_memcpy cannot fail!"' failed.
```

I found this when looking at https://github.com/llvm/llvm-project/issues/37979 but made a new issue since that issue was more about supporting restrict generally, and not about a crash

The full dump is 
```
<source>:1:8: error: cannot initialize a parameter of type 'void *' with an rvalue of type 'int *__restrict (*)[2]'
    1 | struct Obj { int * __restrict myPtr[2]; };
 |        ^~~
<source>:5:7: note: in implicit copy assignment operator for 'Obj' first required here
    5 |     a = b;
      | ^
clang++: /root/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:14315: clang::StmtResult buildMemcpyForAssignmentOp(clang::Sema&, clang::SourceLocation, clang::QualType, const {anonymous}::ExprBuilder&, const {anonymous}::ExprBuilder&): Assertion `!Call.isInvalid() && "Call to __builtin_memcpy cannot fail!"' 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 <source>
1.	<source>:5:10: current parser token ';'
2.	<source>:3:12: parsing function body 'main'
3.	<source>:3:12: in compound statement ('{}')
 #0 0x0000564d7c89ac1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9ac1a)
 #1 0x0000564d7c89884c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9884c)
 #2 0x0000564d7c7e7020 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fc4d836a420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fc4d7e3700b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fc4d7e16859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007fc4d7e16729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007fc4d7e27fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x0000564d7ef7d7c6 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x617d7c6)
 #9 0x0000564d7ef7d8cb buildSingleCopyAssign(clang::Sema&, clang::SourceLocation, clang::QualType, (anonymous namespace)::ExprBuilder const&, (anonymous namespace)::ExprBuilder const&, bool, bool) SemaDeclCXX.cpp:0:0
#10 0x0000564d7efa51bc clang::Sema::DefineImplicitCopyAssignment(clang::SourceLocation, clang::CXXMethodDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61a51bc)
#11 0x0000564d7f092230 void llvm::function_ref<void ()>::callback_fn<clang::Sema::MarkFunctionReferenced(clang::SourceLocation, clang::FunctionDecl*, bool)::'lambda'()>(long) SemaExpr.cpp:0:0
#12 0x0000564d7ed616ff clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f616ff)
#13 0x0000564d7f08fc0b clang::Sema::MarkFunctionReferenced(clang::SourceLocation, clang::FunctionDecl*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x628fc0b)
#14 0x0000564d7f0968cd MarkExprReferenced(clang::Sema&, clang::SourceLocation, clang::Decl*, clang::Expr*, bool, llvm::DenseMap<clang::VarDecl const*, int, llvm::DenseMapInfo<clang::VarDecl const*, void>, llvm::detail::DenseMapPair<clang::VarDecl const*, int>>&) SemaExpr.cpp:0:0
#15 0x0000564d7f3b789b CreateFunctionRefExpr(clang::Sema&, clang::FunctionDecl*, clang::NamedDecl*, clang::Expr const*, bool, clang::SourceLocation, clang::DeclarationNameLoc const&) SemaOverload.cpp:0:0
#16 0x0000564d7f3ed371 clang::Sema::CreateOverloadedBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, clang::Expr*, bool, bool, clang::FunctionDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65ed371)
#17 0x0000564d7f07e2fc BuildOverloadedBinOp(clang::Sema&, clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) SemaExpr.cpp:0:0
#18 0x0000564d7f0e1620 clang::Sema::BuildBinOp(clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62e1620)
#19 0x0000564d7f0e1a47 clang::Sema::ActOnBinOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62e1a47)
#20 0x0000564d7ec934f0 clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e934f0)
#21 0x0000564d7ec92d49 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e92d49)
#22 0x0000564d7ecfe56d clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5efe56d)
#23 0x0000564d7ecf67df clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ef67df)
#24 0x0000564d7ecf7597 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ef7597)
#25 0x0000564d7ecf84c9 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ef84c9)
#26 0x0000564d7ecf8a3b clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ef8a3b)
#27 0x0000564d7ec47ed8 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e47ed8)
#28 0x0000564d7ec72d31 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e72d31)
#29 0x0000564d7ec3e728 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3e728)
#30 0x0000564d7ec3f0a6 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.321) Parser.cpp:0:0
#31 0x0000564d7ec4394b clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e4394b)
#32 0x0000564d7ec45176 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e45176)
#33 0x0000564d7ec3a22b clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3a22b)
#34 0x0000564d7d967560 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b67560)
#35 0x0000564d7d2892e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44892e9)
#36 0x0000564d7d21dc42 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x441dc42)
#37 0x0000564d7d360c9f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4560c9f)
#38 0x0000564d7a022cc3 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1222cc3)
#39 0x0000564d7a01ade8 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#40 0x0000564d7d0912f9 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
#41 0x0000564d7c7e74a5 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39e74a5)
#42 0x0000564d7d093eee 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)
#43 0x0000564d7d06060b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x426060b)
#44 0x0000564d7d0611e3 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)
#45 0x0000564d7d069fd6 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)
#46 0x0000564d7a020a8e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1220a8e)
#47 0x0000564d79f51cb1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1151cb1)
#48 0x00007fc4d7e18083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#49 0x0000564d7a01a4da _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
```


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to