trailofbits / vast

VAST is an experimental compiler pipeline designed for program analysis of C and C++. It provides a tower of IRs as MLIR dialects to choose the best fit representations for a program analysis or further program abstraction.
https://trailofbits.github.io/vast/
Apache License 2.0
397 stars 25 forks source link

[Bug]: run examples failed #499

Open liuhycs opened 9 months ago

liuhycs commented 9 months ago

VAST version

clang version 17.0.2 Target: x86_64-unknown-linux-gnu Thread model: posix

LLVM version

17.0.2

Operating system

ubuntu 22.04 Linux e08865a10ab8 4.15.0-213-generic

Description

I compiled VAST using the following commands:

cmake --preset ninja-multi-default --toolchain ./cmake/lld.toolchain.cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_PREFIX_PATH=/usr1/llvm-17
cmake --build --preset ninja-rel

Then I run the examples in the repo. It got SEGV.

The callstack is:

/usr/include/x86_64-linux-gnu/bits/atomic_wide_counter.h:25:9: error: failed to legalize operation 'hl.union' that was explicitly marked illegal
typedef union
        ^
/usr/include/x86_64-linux-gnu/bits/atomic_wide_counter.h:25:9: note: see current operation:
"hl.union"() ({
  "hl.field"() {name = "__value64", type = ui64} : () -> ()
  "hl.struct"() ({
    "hl.field"() {name = "__low", type = ui32} : () -> ()
    "hl.field"() {name = "__high", type = ui32} : () -> ()
  }) {name = "anonymous[6681]::anonymous[6715]"} : () -> ()
  "hl.field"() {name = "__value32", type = !hl.elaborated<!hl.record<"anonymous[6681]::anonymous[6715]">>} : () -> ()
}) {name = "anonymous[6681]"} : () -> ()
// -----// IR Dump After IRsToLLVM Failed (vast-irs-to-llvm) //----- //
PLEASE submit a bug report to https://github.com/trailofbits/vast/issues and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: ./vast-front -vast-emit-mlir=llvm ../../../../../test/vast/Compile/SingleSource/var-a.c -o ./a.o
1.      <eof> parser at end of file
 #0 0x000055bd4cf48bf0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./vast-front+0xa701bf0)
 #1 0x000055bd4cf4650f llvm::sys::RunSignalHandlers() (./vast-front+0xa6ff50f)
 #2 0x000055bd4ce6a3d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007efe56513520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000055bd468821f6 (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
 #5 0x000055bd46881e90 (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
 #6 0x000055bd468823df (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
 #7 0x000055bd46881e90 (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
 #8 0x000055bd468823df (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
 #9 0x000055bd46881e90 (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
#10 0x000055bd468823df (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
#11 0x000055bd46881e90 (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
#12 0x000055bd468823df (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
#13 0x000055bd46881e90 (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
#14 0x000055bd468823df (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
#15 0x000055bd46881e90 (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
#16 0x000055bd468823df (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
#17 0x000055bd46881e90 (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
#18 0x000055bd468823df (anonymous namespace)::DummyAliasOperationPrinter::printGenericOp(mlir::Operation*, bool) AsmPrinter.cpp:0:0
#19 0x000055bd4688cd6a mlir::Operation::print(llvm::raw_ostream&, mlir::AsmState&) (./vast-front+0x4045d6a)
#20 0x000055bd4688e384 mlir::Operation::print(llvm::raw_ostream&, mlir::OpPrintingFlags const&) (./vast-front+0x4047384)
#21 0x000055bd469c04bb printIR(mlir::Operation*, bool, llvm::raw_ostream&, mlir::OpPrintingFlags) IRPrinting.cpp:0:0
#22 0x000055bd469c0896 void llvm::function_ref<void (llvm::raw_ostream&)>::callback_fn<(anonymous namespace)::IRPrinterInstrumentation::runAfterPassFailed(mlir::Pass*, mlir::Operation*)::'lambda'(llvm::raw_ostream&)>(long, llvm::raw_ostream&) IRPrinting.cpp:0:0
#23 0x000055bd469c0eaa (anonymous namespace)::IRPrinterInstrumentation::runAfterPassFailed(mlir::Pass*, mlir::Operation*) IRPrinting.cpp:0:0
#24 0x000055bd469c401d mlir::PassInstrumentor::runAfterPassFailed(mlir::Pass*, mlir::Operation*) (./vast-front+0x417d01d)
#25 0x000055bd469cd4b9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./vast-front+0x41864b9)
#26 0x000055bd469cd961 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./vast-front+0x4186961)
#27 0x000055bd469ce1c5 mlir::PassManager::run(mlir::Operation*) (./vast-front+0x41871c5)
#28 0x000055bd46792aa6 vast::target::llvmir::lower_hl_module(mlir::Operation*, vast::target::llvmir::pipeline) (./vast-front+0x3f4baa6)
#29 0x000055bd4660e369 vast::cc::vast_stream_consumer::emit_mlir_output(vast::cc::target_dialect, mlir::OwningOpRef<mlir::ModuleOp>, mlir::MLIRContext*)::$_0::operator()() const Consumer.cpp:0:0
#30 0x000055bd4660df04 vast::cc::vast_stream_consumer::emit_mlir_output(vast::cc::target_dialect, mlir::OwningOpRef<mlir::ModuleOp>, mlir::MLIRContext*) (./vast-front+0x3dc6f04)
#31 0x000055bd4660d81c vast::cc::vast_stream_consumer::HandleTranslationUnit(clang::ASTContext&) (./vast-front+0x3dc681c)
#32 0x000055bd4adfff69 clang::ParseAST(clang::Sema&, bool, bool) (./vast-front+0x85b8f69)
#33 0x000055bd497aba09 clang::FrontendAction::Execute() (./vast-front+0x6f64a09)
#34 0x000055bd4972bdde clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (./vast-front+0x6ee4dde)
#35 0x000055bd46606a31 vast::cc::execute_compiler_invocation(clang::CompilerInstance*, vast::cc::vast_args const&) (./vast-front+0x3dbfa31)
#36 0x000055bd4660afb6 vast::cc::cc1(vast::cc::vast_args const&, llvm::ArrayRef<char const*>, char const*, void*) (./vast-front+0x3dc3fb6)
#37 0x000055bd466079c4 execute_cc1_tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#38 0x000055bd4957102d 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
#39 0x000055bd4ce6a8a0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (./vast-front+0xa6238a0)
#40 0x000055bd495718ae 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
#41 0x000055bd49531dfa clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (./vast-front+0x6ceadfa)
#42 0x000055bd495328cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (./vast-front+0x6ceb8cd)
#43 0x000055bd4953e25c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (./vast-front+0x6cf725c)
#44 0x000055bd46607f41 vast::cc::driver::execute() driver.cpp:0:0
#45 0x000055bd46607465 main (./vast-front+0x3dc0465)
#46 0x00007efe564fad90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#47 0x00007efe564fae40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#48 0x000055bd466064a5 _start (./vast-front+0x3dbf4a5)
vast-front: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 17.0.2
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/vast/builds/ninja-multi-default/tools/vast-front/Release/.
vast-front: error: unable to execute command: Segmentation fault (core dumped)
vast-front: note: diagnostic msg: Error generating preprocessed source(s).

Is there any thing I made some mistakes? Thanks!

Steps to Reproduce

./vast-front -vast-emit-mlir=llvm ../../../../../test/vast/Compile/SingleSource/var-a.c -o ./a.mlir
lkorenc commented 9 months ago

Hi, thanks for the report!

If you open source of var-a.c you will notice the // REQUIRES: union_lowering. This means we do not yet fully support this. Adding support should not be super compilcated, but we yet did not find the time (it is however on the todo).

When you try some other test from the directory that does not have this clause does it work for you?

lkorenc commented 9 months ago

In any case #500 is what is blocking this test-case.

liuhycs commented 8 months ago

Got it! Thanks. I tried other test cases. They work fine.

lkorenc commented 8 months ago

In the meantime I merged #500 and the test case now dies a little further into the conversion pipeline (sadly std imports a lot of more complicated/edge case constructs).

I am keeping this open to keep track of the test case, hopefully we won't take that long to get it working.