Skip to content

Assertion failed in CodeGen #861

Closed
@dopelsunce

Description

@dopelsunce

File crash.c:

_Checked unsigned ns_get16(const unsigned char *cp : count(1))
{
	return cp[0];
}

Command to trigger the assertion failure:

clang -c crash.c

Note: clang is built with assertion enabled.

Error message:

clang-9: /home/yahui/work/checkedc-clang/clang/lib/CodeGen/CGExprScalar.cpp:2171: llvm::Value* {anonymous}::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*): Assertion `CGF.getContext().hasSameUnqualifiedType(E->getType(), DestTy)' failed.
Stack dump:
0.      Program arguments: /usr/local/bin/clang-9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name crash.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /home/yahui/work/checkedc-musl/crash.gcno -resource-dir /usr/local/lib/clang/9.0.0 -c-isystem /home/yahui/work/checkedc/include -internal-isystem /usr/local/include -internal-isystem /usr/local/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/yahui/work/checkedc-musl -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o crash.o -x c crash.c 
1.      <eof> parser at end of file
2.      crash.c:1:19: LLVM IR generation of declaration 'ns_get16'
3.      crash.c:1:19: Generating code for declaration 'ns_get16'
 #0 0x00007f221e42e6c5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/bin/clang-9+0x53a26c5)
 #1 0x00007f221e42e75c PrintStackTraceSignalHandler(void*) (/usr/local/bin/clang-9+0x53a275c)
 #2 0x00007f221e42c5f6 llvm::sys::RunSignalHandlers() (/usr/local/bin/clang-9+0x53a05f6)
 #3 0x00007f221e42e04f SignalHandler(int) (/usr/local/bin/clang-9+0x53a204f)
 #4 0x00007f22190423c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #5 0x00007f2218b0618b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #6 0x00007f2218ae5859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #7 0x00007f2218ae5729 (/lib/x86_64-linux-gnu/libc.so.6+0x25729)
 #8 0x00007f2218af6f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
 #9 0x00007f221ebd1a4e (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) (/usr/local/bin/clang-9+0x5b45a4e)
#10 0x00007f221ebe24bd clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*) (/usr/local/bin/clang-9+0x5b564bd)
#11 0x00007f221ebe0c0b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/usr/local/bin/clang-9+0x5b54c0b)
#12 0x00007f221ebc8b55 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) (/usr/local/bin/clang-9+0x5b3cb55)
#13 0x00007f221ebde405 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/usr/local/bin/clang-9+0x5b52405)
#14 0x00007f221eb7b895 clang::CodeGen::CodeGenFunction::EmitPointerWithAlignment(clang::Expr const*, clang::CodeGen::LValueBaseInfo*, clang::CodeGen::TBAAAccessInfo*) (.localalias) (/usr/local/bin/clang-9+0x5aef895)
#15 0x00007f221eb6225f clang::CodeGen::CodeGenFunction::EmitDynamicBoundsCheck(clang::CodeGen::Address, clang::BoundsExpr const*, clang::BoundsCheckKind, llvm::Value*) (/usr/local/bin/clang-9+0x5ad625f)
#16 0x00007f221eb8a0f4 clang::CodeGen::CodeGenFunction::EmitArraySubscriptExpr(clang::ArraySubscriptExpr const*, bool) (.localalias) (/usr/local/bin/clang-9+0x5afe0f4)
#17 0x00007f221eb7c98f clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*) (.localalias) (/usr/local/bin/clang-9+0x5af098f)
#18 0x00007f221eb7be18 clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) (/usr/local/bin/clang-9+0x5aefe18)
#19 0x00007f221ebc84b2 (anonymous namespace)::ScalarExprEmitter::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) (/usr/local/bin/clang-9+0x5b3c4b2)
#20 0x00007f221ebc87c7 (anonymous namespace)::ScalarExprEmitter::EmitLoadOfLValue(clang::Expr const*) (/usr/local/bin/clang-9+0x5b3c7c7)
#21 0x00007f221ebcfa82 (anonymous namespace)::ScalarExprEmitter::VisitArraySubscriptExpr(clang::ArraySubscriptExpr*) (/usr/local/bin/clang-9+0x5b43a82)
#22 0x00007f221ebe07a3 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/usr/local/bin/clang-9+0x5b547a3)
#23 0x00007f221ebc8b55 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) (/usr/local/bin/clang-9+0x5b3cb55)
#24 0x00007f221ebd1a9a (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) (/usr/local/bin/clang-9+0x5b45a9a)
#25 0x00007f221ebe24bd clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*) (/usr/local/bin/clang-9+0x5b564bd)
#26 0x00007f221ebe0c0b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/usr/local/bin/clang-9+0x5b54c0b)
#27 0x00007f221ebc8b55 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) (/usr/local/bin/clang-9+0x5b3cb55)
#28 0x00007f221ebd22b2 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) (/usr/local/bin/clang-9+0x5b462b2)
#29 0x00007f221ebe24bd clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*) (/usr/local/bin/clang-9+0x5b564bd)
#30 0x00007f221ebe0c0b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) (/usr/local/bin/clang-9+0x5b54c0b)
#31 0x00007f221ebc8b55 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) (/usr/local/bin/clang-9+0x5b3cb55)
#32 0x00007f221ebde405 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/usr/local/bin/clang-9+0x5b52405)
#33 0x00007f221e81dd0b clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/usr/local/bin/clang-9+0x5791d0b)
#34 0x00007f221e819986 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/local/bin/clang-9+0x578d986)
#35 0x00007f221e81a802 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/local/bin/clang-9+0x578e802)
#36 0x00007f221e8a1a25 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/usr/local/bin/clang-9+0x5815a25)
#37 0x00007f221e8a26a7 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/local/bin/clang-9+0x58166a7)
#38 0x00007f221e8cb7d7 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/local/bin/clang-9+0x583f7d7)
#39 0x00007f221e8c4a79 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/local/bin/clang-9+0x5838a79)
#40 0x00007f221e8c3a2e clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/local/bin/clang-9+0x5837a2e)
#41 0x00007f221e8cf7be clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.localalias) (/usr/local/bin/clang-9+0x58437be)
#42 0x00007f221f77f827 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/local/bin/clang-9+0x66f3827)
#43 0x00007f221f77863a clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/local/bin/clang-9+0x66ec63a)
#44 0x00007f2220d89572 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/bin/clang-9+0x7cfd572)
#45 0x00007f221eebf0a9 clang::ASTFrontendAction::ExecuteAction() (/usr/local/bin/clang-9+0x5e330a9)
#46 0x00007f221f776fab clang::CodeGenAction::ExecuteAction() (/usr/local/bin/clang-9+0x66eafab)
#47 0x00007f221eebea00 clang::FrontendAction::Execute() (/usr/local/bin/clang-9+0x5e32a00)
#48 0x00007f221ee57362 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/bin/clang-9+0x5dcb362)
#49 0x00007f221f029d9c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/bin/clang-9+0x5f9dd9c)
#50 0x00007f221bb9ba1d cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/bin/clang-9+0x2b0fa1d)
#51 0x00007f221bb9067d ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) (/usr/local/bin/clang-9+0x2b0467d)
#52 0x00007f221bb90d6b main (/usr/local/bin/clang-9+0x2b04d6b)
#53 0x00007f2218ae70b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#54 0x00007f221bb8ee3e _start (/usr/local/bin/clang-9+0x2b02e3e)
clang-9: error: unable to execute command: Aborted (core dumped)
clang-9: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 9.0.0 (https://github.com/microsoft/checkedc-clang.git f87e07701e72f606be3587a10e3080951f3665aa)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
clang-9: note: diagnostic msg: PLEASE submit a bug report to https://github.com/Microsoft/checkedc-clang/issues and include the crash backtrace, preprocessed source, and associated run script.
clang-9: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-9: note: diagnostic msg: /tmp/crash-3bab16.c
clang-9: note: diagnostic msg: /tmp/crash-3bab16.sh
clang-9: note: diagnostic msg: 
********************

clang version: current master branch

I encountered this crash while trying to convert src/network/ns_parse.c in musl to Checked C.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions