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

Assertion failure building code that uses blocks (qsort_b_test.c) #671

Open
bsdjhb opened this issue Dec 22, 2022 · 2 comments
Open

Assertion failure building code that uses blocks (qsort_b_test.c) #671

bsdjhb opened this issue Dec 22, 2022 · 2 comments

Comments

@bsdjhb
Copy link
Contributor

bsdjhb commented Dec 22, 2022

While merging in an upstream change from FreeBSD to add a test for qsort_b(3), I get the following crash:

Assertion failed: ((2 * CGM.getIntSize()).isMultipleOf(CGM.getPointerAlign())), function initializeForBlockHeader, file /home/john/work/cheri/git/llvm-project/clang/lib/CodeGen/CGBlocks.cpp, line 500.
 #0 0x000000000381b8f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/john/work/cheri/output/sdk/bin/clang+0x381b8f7)
 #1 0x000000000381bcd8 __assert (/home/john/work/cheri/output/sdk/bin/clang+0x381bcd8)
 #2 0x0000000003b352cb computeBlockInfo(clang::CodeGen::CodeGenModule&, clang::CodeGen::CodeGenFunction*, clang::CodeGen::CGBlockInfo&) CGBlocks.cpp:0:0
 #3 0x0000000003b33a80 clang::CodeGen::CodeGenFunction::EmitBlockLiteral(clang::BlockExpr const*) (/home/john/work/cheri/output/sdk/bin/clang+0x3b33a80)
 #4 0x0000000003b6e28b clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/john/work/cheri/output/sdk/bin/clang+0x3b6e28b)
 #5 0x0000000003b453f8 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/home/john/work/cheri/output/sdk/bin/clang+0x3b453f8)
 #6 0x0000000003b45e5b clang::CodeGen::CodeGenFunction::EmitAnyExprToTemp(clang::Expr const*) (/home/john/work/cheri/output/sdk/bin/clang+0x3b45e5b)
 #7 0x0000000003b231bc clang::CodeGen::CodeGenFunction::EmitCallArg(clang::CodeGen::CallArgList&, clang::Expr const*, clang::QualType) (/home/john/work/cheri/output/sdk/bin/clang+0x3b231bc)
 #8 0x0000000003b21ee6 clang::CodeGen::CodeGenFunction::EmitCallArgs(clang::CodeGen::CallArgList&, clang::CodeGen::CodeGenFunction::PrototypeWrapper, llvm::iterator_range<clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const> >, clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int, clang::CodeGen::CodeGenFunction::EvaluationOrder) (/home/john/work/cheri/output/sdk/bin/clang+0x3b21ee6)
 #9 0x0000000003b68200 clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*) (/home/john/work/cheri/output/sdk/bin/clang+0x3b68200)
#10 0x0000000003b67233 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/home/john/work/cheri/output/sdk/bin/clang+0x3b67233)
#11 0x0000000003b7ec33 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#12 0x0000000003b6e28b clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/john/work/cheri/output/sdk/bin/clang+0x3b6e28b)
#13 0x0000000003b453f8 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/home/john/work/cheri/output/sdk/bin/clang+0x3b453f8)
#14 0x0000000003b45399 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/home/john/work/cheri/output/sdk/bin/clang+0x3b45399)
#15 0x0000000003ba9082 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/john/work/cheri/output/sdk/bin/clang+0x3ba9082)
#16 0x0000000003ba9c01 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/john/work/cheri/output/sdk/bin/clang+0x3ba9c01)
#17 0x0000000003ba8f94 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/john/work/cheri/output/sdk/bin/clang+0x3ba8f94)
#18 0x0000000003bac913 clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) (/home/john/work/cheri/output/sdk/bin/clang+0x3bac913)
#19 0x0000000003bb59b0 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/john/work/cheri/output/sdk/bin/clang+0x3bb59b0)
#20 0x0000000003b9ac88 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/john/work/cheri/output/sdk/bin/clang+0x3b9ac88)
#21 0x0000000003ab88d2 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/john/work/cheri/output/sdk/bin/clang+0x3ab88d2)
#22 0x0000000003ab10cf clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/john/work/cheri/output/sdk/bin/clang+0x3ab10cf)
#23 0x0000000003aa4333 clang::CodeGen::CodeGenModule::EmitDeferred() (/home/john/work/cheri/output/sdk/bin/clang+0x3aa4333)
#24 0x0000000003aa4363 clang::CodeGen::CodeGenModule::EmitDeferred() (/home/john/work/cheri/output/sdk/bin/clang+0x3aa4363)
#25 0x0000000003aa4363 clang::CodeGen::CodeGenModule::EmitDeferred() (/home/john/work/cheri/output/sdk/bin/clang+0x3aa4363)
#26 0x0000000003aa290c clang::CodeGen::CodeGenModule::Release() (/home/john/work/cheri/output/sdk/bin/clang+0x3aa290c)
#27 0x0000000004375354 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#28 0x0000000004372a89 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) CodeGenAction.cpp:0:0
#29 0x0000000004b5cae4 clang::ParseAST(clang::Sema&, bool, bool) (/home/john/work/cheri/output/sdk/bin/clang+0x4b5cae4)
#30 0x00000000042a4083 clang::FrontendAction::Execute() (/home/john/work/cheri/output/sdk/bin/clang+0x42a4083)
#31 0x000000000422689f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/john/work/cheri/output/sdk/bin/clang+0x422689f)
#32 0x000000000436c37a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/john/work/cheri/output/sdk/bin/clang+0x436c37a)
#33 0x0000000001fe485a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/john/work/cheri/output/sdk/bin/clang+0x1fe485a)
#34 0x0000000001fe2147 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#35 0x00000000040e7b17 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, bool*) const::$_1>(long) Job.cpp:0:0
#36 0x0000000003791130 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/john/work/cheri/output/sdk/bin/clang+0x3791130)
#37 0x00000000040e762b clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, bool*) const (/home/john/work/cheri/output/sdk/bin/clang+0x40e762b)
#38 0x00000000040b7665 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/john/work/cheri/output/sdk/bin/clang+0x40b7665)
#39 0x00000000040b7a99 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) const (/home/john/work/cheri/output/sdk/bin/clang+0x40b7a99)
#40 0x00000000040cc17c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) (/home/john/work/cheri/output/sdk/bin/clang+0x40cc17c)
PLEASE submit a bug report to https://github.com/CTSRD-CHERI/llvm-project/issues and include the crash backtrace, preprocessed source, and associated run script.
If you built clang from source, please provide a reduced test case by running:
        $LLVM_BUILD_DIR/bin/creduce_crash_testcase.py <reproducer>.sh
Stack dump:
0.      Program arguments: /home/john/work/cheri/output/sdk/bin/clang -target riscv64-unknown-freebsd14.0 --sysroot=/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/tmp -B/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/tmp/usr/bin -O2 -pipe -fno-common -march=rv64imafdcxcheri -mabi=l64pc128d -D__LP64__=1 -D__HAVE_FENV -D__HAVE_LONG_DOUBLE -I/usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib -fPIE -mno-relax -g -gz=zlib -MD -MF.depend.qsort_b_test.qsort_b_test.o -MTqsort_b_test.o -std=gnu99 -Wno-format-zero-length -nobuiltininc -idirafter /usr/home/john/work/cheri/output/sdk/lib/clang/13.0.0/include -Werror=implicit-function-declaration -Wsystem-headers -Werror -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -Wno-error=pass-failed -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-variable -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-address-of-packed-member -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -Qunused-arguments -fblocks -c /usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib/qsort_b_test.c -o qsort_b_test.o
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      /usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib/qsort_b_test.c:38:1 <Spelling=<scratch space>:57:1>: Generating code for declaration 'atfu_qsort_b_test_body'
4.      /usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib/qsort_b_test.c:44:33: LLVM IR generation of compound statement ('{}')

I will see if I can get a smaller test case.

@bsdjhb
Copy link
Contributor Author

bsdjhb commented Dec 22, 2022

void atfu_qsort_b_test_body() {
  ^{
  };
}

@bsdjhb
Copy link
Contributor Author

bsdjhb commented Dec 22, 2022

The sh file:

# Crash reproducer for clang version 13.0.0 ([email protected]:CTSRD-CHERI/llvm-project.git f06202e95b8ba0ca0655ab5753f0fff070007e1f)
# Driver args: "--target=riscv64-unknown-freebsd14.0" "--sysroot=/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/tmp" "-B" "/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/tmp/usr/bin" "-O2" "-pipe" "-fno-common" "-march=rv64imafdcxcheri" "-mabi=l64pc128d" "-D" "__LP64__=1" "-D" "__HAVE_FENV" "-D" "__HAVE_LONG_DOUBLE" "-I" "/usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib" "-fPIE" "-mno-relax" "-g" "-gz=zlib" "-MD" "-MF" ".depend.qsort_b_test.qsort_b_test.o" "-MT" "qsort_b_test.o" "-std=gnu99" "-Wno-format-zero-length" "-nobuiltininc" "-idirafter" "/usr/home/john/work/cheri/output/sdk/lib/clang/13.0.0/include" "-Werror=implicit-function-declaration" "-Wsystem-headers" "-Werror" "-Wall" "-Wno-format-y2k" "-Wno-uninitialized" "-Wno-pointer-sign" "-Wno-error=pass-failed" "-Wno-empty-body" "-Wno-string-plus-int" "-Wno-unused-const-variable" "-Wno-error=unused-but-set-variable" "-Wno-tautological-compare" "-Wno-unused-value" "-Wno-parentheses-equality" "-Wno-unused-function" "-Wno-enum-conversion" "-Wno-unused-local-typedef" "-Wno-address-of-packed-member" "-Wno-switch" "-Wno-switch-enum" "-Wno-knr-promoted-parameter" "-Qunused-arguments" "-fblocks" "-c" "/usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib/qsort_b_test.c" "-o" "qsort_b_test.o"
# Original command:  "/usr/home/john/work/cheri/output/sdk/bin/clang-13" "-cc1" "-triple" "riscv64-unknown-freebsd14.0" "-emit-obj" "--mrelax-relocations" "-disable-free" "-main-file-name" "qsort_b_test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-munwind-tables" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+c" "-target-feature" "+xcheri" "-target-feature" "-relax" "-target-feature" "+cap-mode" "-target-feature" "-xcheri-rvc" "-target-feature" "-save-restore" "-target-abi" "l64pc128d" "-msmall-data-limit" "8" "-debug-info-kind=standalone" "-dwarf-version=4" "-debugger-tuning=gdb" "--compress-debug-sections=zlib" "-fcoverage-compilation-dir=/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/lib/libc/tests/stdlib" "-nobuiltininc" "-resource-dir" "/usr/home/john/work/cheri/output/sdk/lib/clang/13.0.0" "-dependency-file" ".depend.qsort_b_test.qsort_b_test.o" "-MT" "qsort_b_test.o" "-sys-header-deps" "-idirafter" "/usr/home/john/work/cheri/output/sdk/lib/clang/13.0.0/include" "-D" "__LP64__=1" "-D" "__HAVE_FENV" "-D" "__HAVE_LONG_DOUBLE" "-I" "/usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib" "-isysroot" "/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/tmp" "-O2" "-Wno-format-zero-length" "-Werror=implicit-function-declaration" "-Wsystem-headers" "-Werror" "-Wall" "-Wno-format-y2k" "-Wno-uninitialized" "-Wno-pointer-sign" "-Wno-error=pass-failed" "-Wno-empty-body" "-Wno-string-plus-int" "-Wno-unused-const-variable" "-Wno-error=unused-but-set-variable" "-Wno-tautological-compare" "-Wno-unused-value" "-Wno-parentheses-equality" "-Wno-unused-function" "-Wno-enum-conversion" "-Wno-unused-local-typedef" "-Wno-address-of-packed-member" "-Wno-switch" "-Wno-switch-enum" "-Wno-knr-promoted-parameter" "-std=gnu99" "-fdebug-compilation-dir=/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/lib/libc/tests/stdlib" "-ferror-limit" "19" "-fblocks" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "qsort_b_test.o" "-x" "c" "/usr/home/john/work/cheri/git/cheribsd/lib/libc/tests/stdlib/qsort_b_test.c"
 "/usr/home/john/work/cheri/output/sdk/bin/clang-13" "-cc1" "-triple" "riscv64-unknown-freebsd14.0" "-emit-obj" "--mrelax-relocations" "-disable-free" "-main-file-name" "qsort_b_test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-munwind-tables" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+c" "-target-feature" "+xcheri" "-target-feature" "-relax" "-target-feature" "+cap-mode" "-target-feature" "-xcheri-rvc" "-target-feature" "-save-restore" "-target-abi" "l64pc128d" "-msmall-data-limit" "8" "-debug-info-kind=standalone" "-dwarf-version=4" "-debugger-tuning=gdb" "--compress-debug-sections=zlib" "-fcoverage-compilation-dir=/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/lib/libc/tests/stdlib" "-nobuiltininc" "-sys-header-deps" "-D" "__LP64__=1" "-D" "__HAVE_FENV" "-D" "__HAVE_LONG_DOUBLE" "-O2" "-Wno-format-zero-length" "-Werror=implicit-function-declaration" "-Wsystem-headers" "-Werror" "-Wall" "-Wno-format-y2k" "-Wno-uninitialized" "-Wno-pointer-sign" "-Wno-error=pass-failed" "-Wno-empty-body" "-Wno-string-plus-int" "-Wno-unused-const-variable" "-Wno-error=unused-but-set-variable" "-Wno-tautological-compare" "-Wno-unused-value" "-Wno-parentheses-equality" "-Wno-unused-function" "-Wno-enum-conversion" "-Wno-unused-local-typedef" "-Wno-address-of-packed-member" "-Wno-switch" "-Wno-switch-enum" "-Wno-knr-promoted-parameter" "-std=gnu99" "-fdebug-compilation-dir=/usr/obj/cheri/cheribsd-riscv64-purecap-build/usr/home/john/work/cheri/git/cheribsd/riscv.riscv64c/lib/libc/tests/stdlib" "-ferror-limit" "19" "-fblocks" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "qsort_b_test-c48a10.c"

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

No branches or pull requests

1 participant