checkedc / checkedc-llvm-project

This was a fork of Checked C clang used from 2021-2024. The changes have been merged into the original Checked C clang repo, which is now at https://github.com/checkedc/checkedc-clang.
https://www.checkedc.org
13 stars 19 forks source link

Assertion failure when compiling openssh-portable source code #1204

Closed arunkumarbhattar closed 1 month ago

arunkumarbhattar commented 1 year ago

Description: I encountered an assertion failure while compiling openssh-portable. The crash is happening when the LLVM IR is being generated, specifically in StoreInst::AssertOK() This indicates that a StoreInst (an instruction to store a value to memory) is being created with an invalid type. Specifically, the value being stored does not match the type of the value pointed to by the pointer operand.

The crash seems to happen when processing the int16_negative_mask declaration in sntrup761.c.

Backtrace make (base) Makefile:690: warning: ignoring prerequisites on suffix rule definition (cd openbsd-compat && make) make[1]: Entering directory '/home/arun/ptrsplitEval/typeflex-openssh-portable/openbsd-compat' make[1]: Nothing to be done for 'all'. make[1]: Leaving directory '/home/arun/ptrsplitEval/typeflex-openssh-portable/openbsd-compat' /home/arun/Desktop/macro/checkedc-llvm-project/llvm/cmake-build-debug/bin/clang -g -O2 -pipe -Wunknown-warning-option -Qunused-arguments -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-result -Wmisleading-indentation -fno-strict-aliasing -mretpoline -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-strong -fPIE -I. -I. -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -DOPENSSL_API_COMPAT=0x10100000L -DSSHDIR=\"/usr/local/etc\" -D_PATH_SSH_PROGRAM=\"/usr/local/bin/ssh\" -D_PATH_SSH_ASKPASS_DEFAULT=\"/usr/local/libexec/ssh-askpass\" -D_PATH_SFTP_SERVER=\"/usr/local/libexec/sftp-server\" -D_PATH_SSH_KEY_SIGN=\"/usr/local/libexec/ssh-keysign\" -D_PATH_SSH_PKCS11_HELPER=\"/usr/local/libexec/ssh-pkcs11-helper\" -D_PATH_SSH_SK_HELPER=\"/usr/local/libexec/ssh-sk-helper\" -D_PATH_SSH_PIDDIR=\"/var/run\" -D_PATH_PRIVSEP_CHROOT_DIR=\"/var/empty\" -DHAVE_CONFIG_H -c sntrup761.c -o sntrup761.o clang: /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/IR/Instructions.cpp:1437: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed. PLEASE submit a bug report to https://github.com/Microsoft/checkedc-clang/issues and include the crash backtrace, preprocessed source, and associated run script. Stack dump:

  1. Program arguments: /home/arun/Desktop/macro/checkedc-llvm-project/llvm/cmake-build-debug/bin/clang -g -O2 -pipe -Wunknown-warning-option -Qunused-arguments -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-result -Wmisleading-indentation -fno-strict-aliasing -mretpoline -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-strong -fPIE -I. -I. -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -DOPENSSL_API_COMPAT=0x10100000L -DSSHDIR=\"/usr/local/etc\" -D_PATH_SSH_PROGRAM=\"/usr/local/bin/ssh\" -D_PATH_SSH_ASKPASS_DEFAULT=\"/usr/local/libexec/ssh-askpass\" -D_PATH_SFTP_SERVER=\"/usr/local/libexec/sftp-server\" -D_PATH_SSH_KEY_SIGN=\"/usr/local/libexec/ssh-keysign\" -D_PATH_SSH_PKCS11_HELPER=\"/usr/local/libexec/ssh-pkcs11-helper\" -D_PATH_SSH_SK_HELPER=\"/usr/local/libexec/ssh-sk-helper\" -D_PATH_SSH_PIDDIR=\"/var/run\" -D_PATH_PRIVSEP_CHROOT_DIR=\"/var/empty\" -DHAVE_CONFIG_H -c sntrup761.c -o sntrup761.o
  2. parser at end of file
  3. Per-file LLVM IR generation
  4. sntrup761.c:412:12: Generating code for declaration 'int16_negative_mask'

    0 0x000055b38c15a768 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/Support/Unix/Signals.inc:565:22

    1 0x000055b38c15a82f PrintStackTraceSignalHandler(void*) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1

    2 0x000055b38c1583f1 llvm::sys::RunSignalHandlers() /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/Support/Signals.cpp:71:20

    3 0x000055b38c159f61 llvm::sys::CleanupOnSignal(unsigned long) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/Support/Unix/Signals.inc:361:31

    4 0x000055b38c08871f (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:75:5

    5 0x000055b38c088c6e CrashRecoverySignalHandler(int) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:389:1

    6 0x00007fa08cc42520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)

    7 0x00007fa08cc96a7c __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76

    8 0x00007fa08cc96a7c __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10

    9 0x00007fa08cc96a7c pthread_kill ./nptl/./nptl/pthread_kill.c:89:10

    10 0x00007fa08cc42476 raise ./signal/../sysdeps/posix/raise.c:27:6

    11 0x00007fa08cc287f3 abort ./stdlib/./stdlib/abort.c:81:7

    12 0x00007fa08cc2871b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9

    13 0x00007fa08cc39e96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)

    14 0x000055b38b580d80 llvm::StoreInst::AssertOK() /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/IR/Instructions.cpp:1440:3

    15 0x000055b38b5810d0 llvm::StoreInst::StoreInst(llvm::Value, llvm::Value, bool, llvm::Align, llvm::AtomicOrdering, unsigned char, llvm::Instruction*) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/IR/Instructions.cpp:1484:1

    16 0x000055b38b580f6d llvm::StoreInst::StoreInst(llvm::Value, llvm::Value, bool, llvm::Align, llvm::Instruction*) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/IR/Instructions.cpp:1465:48

    17 0x000055b3897484bc llvm::IRBuilderBase::CreateAlignedStore(llvm::Value, llvm::Value, llvm::MaybeAlign, bool) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/include/llvm/IR/IRBuilder.h:1834:18

    18 0x000055b38c5e9935 clang::CodeGen::CGBuilderTy::CreateStore(llvm::Value*, clang::CodeGen::Address, bool) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGBuilder.h:106:3

    19 0x000055b38ca8a61d clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::Address, bool, clang::QualType, clang::CodeGen::LValueBaseInfo, clang::CodeGen::TBAAAccessInfo, bool, bool) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGExpr.cpp:1865:47

    20 0x000055b38ca8a884 clang::CodeGen::CodeGenFunction::EmitStoreOfScalar(llvm::Value*, clang::CodeGen::LValue, bool) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGExpr.cpp:1883:20

    21 0x000055b38ca8c2b3 clang::CodeGen::CodeGenFunction::EmitStoreThroughLValue(clang::CodeGen::RValue, clang::CodeGen::LValue, bool) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGExpr.cpp:2170:20

    22 0x000055b38ca549b3 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const, clang::ValueDecl const, clang::CodeGen::LValue, bool) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGDecl.cpp:763:27

    23 0x000055b38ca5a8b8 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const, clang::ValueDecl const, clang::CodeGen::LValue, bool) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGDecl.cpp:1927:19

    24 0x000055b38ca5a544 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGDecl.cpp:1888:26

    25 0x000055b38ca574cf clang::CodeGen::CodeGenFunction::EmitAutoVarDecl(clang::VarDecl const&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGDecl.cpp:1310:22

    26 0x000055b38ca51e69 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGDecl.cpp:208:27

    27 0x000055b38ca51b1d clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (.localalias) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGDecl.cpp:154:47

    28 0x000055b38c6008a2 clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGStmt.cpp:1249:3

    29 0x000055b38c5fc48c clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const, llvm::ArrayRef<clang::Attr const>) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGStmt.cpp:387:5

    30 0x000055b38c5fb6a0 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const, llvm::ArrayRef<clang::Attr const>) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGStmt.cpp:55:3

    31 0x000055b38c5fc9d1 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CGStmt.cpp:441:3

    32 0x000055b38c6ad6e8 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1189:33

    33 0x000055b38c6ae397 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1359:21

    34 0x000055b38c6dc379 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4769:3

    35 0x000055b38c6d4d31 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3118:47

    36 0x000055b38c6d0f37 clang::CodeGen::CodeGenModule::EmitDeferred() (.localalias) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2351:31

    37 0x000055b38c6d0f8e clang::CodeGen::CodeGenModule::EmitDeferred() (.localalias) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2353:7

    38 0x000055b38c6d0f8e clang::CodeGen::CodeGenModule::EmitDeferred() (.localalias) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2353:7

    39 0x000055b38c6d0f8e clang::CodeGen::CodeGenModule::EmitDeferred() (.localalias) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2353:7

    40 0x000055b38c6d0f8e clang::CodeGen::CodeGenModule::EmitDeferred() (.localalias) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2353:7

    41 0x000055b38c6c6fdb clang::CodeGen::CodeGenModule::Release() /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:450:31

    42 0x000055b38d88e651 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:271:11

    43 0x000055b38d886d1d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:294:13

    44 0x000055b38f3c2975 clang::ParseAST(clang::Sema&, bool, bool) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Parse/ParseAST.cpp:178:14

    45 0x000055b38ce88c63 clang::ASTFrontendAction::ExecuteAction() /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Frontend/FrontendAction.cpp:1056:11

    46 0x000055b38d883b22 clang::CodeGenAction::ExecuteAction() /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1083:5

    47 0x000055b38ce88512 clang::FrontendAction::Execute() /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Frontend/FrontendAction.cpp:953:38

    48 0x000055b38cddcc9c clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Frontend/CompilerInstance.cpp:949:42

    49 0x000055b38d0291de clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:278:38

    50 0x000055b388f82b1a cc1_main(llvm::ArrayRef<char const>, char const, void*) /home/arun/Desktop/macro/checkedc-llvm-project/clang/tools/driver/cc1_main.cpp:240:40

    51 0x000055b388f76997 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/tools/driver/driver.cpp:330:20

    52 0x000055b38ccc3901 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const::'lambda'()::operator()() const /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Driver/Job.cpp:404:32

    53 0x000055b38ccc41a7 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const::'lambda'()>(long) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/include/llvm/ADT/STLExtras.h:186:40

    54 0x000055b38c07b988 llvm::function_ref<void ()>::operator()() const /home/arun/Desktop/macro/checkedc-llvm-project/llvm/include/llvm/ADT/STLExtras.h:209:62

    55 0x000055b38c088e8b llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/arun/Desktop/macro/checkedc-llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:425:10

    56 0x000055b38ccc3b0e clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Driver/Job.cpp:404:7

    57 0x000055b38cc74391 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Driver/Compilation.cpp:195:22

    58 0x000055b38cc7470c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Driver/Compilation.cpp:248:53

    59 0x000055b38cc84745 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) /home/arun/Desktop/macro/checkedc-llvm-project/clang/lib/Driver/Driver.cpp:1517:28

    60 0x000055b388f779f7 main /home/arun/Desktop/macro/checkedc-llvm-project/clang/tools/driver/driver.cpp:502:39

    61 0x00007fa08cc29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16

    62 0x00007fa08cc29e40 call_init ./csu/../csu/libc-start.c:128:20

    63 0x00007fa08cc29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5

    64 0x000055b388f74fb5 _start (/home/arun/Desktop/macro/checkedc-llvm-project/llvm/cmake-build-debug/bin/clang+0x148dfb5)

    clang-12: error: clang frontend command failed with exit code 134 (use -v to see invocation) clang version 12.0.0 (https://github.com/checkedc-purdue/checkedc-llvm-project.git aa9b74b2169eb250ccccb8d1f65a6082377b795a) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/arun/Desktop/macro/checkedc-llvm-project/llvm/cmake-build-debug/bin clang-12: note: diagnostic msg:


PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-12: note: diagnostic msg: /tmp/sntrup761-7ed827.c clang-12: note: diagnostic msg: /tmp/sntrup761-7ed827.sh clang-12: note: diagnostic msg:


make: *** [Makefile:195: sntrup761.o] Error 134 crash.tar.gz