CTSRD-CHERI/llvm-project

`addrspace` does not override default address space for `alloca`

gabi-250 opened this issue · 3 comments

The addrspace attribute doesn't change the address space of allocas. For example, compiling the following module using the morello toolchain triggers an assertion failure (AI->getType()->getPointerAddressSpace() == 200):

; bug.ll

define void @allocaTest() {
  %1 = alloca i32, addrspace(200)
  ret void
}

This is the command I've used to compile it: $CHERI/bin/llvm-as bug.ll -o bug.bc && $CHERI/bin/clang --config cheribsd-morello-purecap.cfg -shared -fPIC bug.bc -o bug.so.

This may or may not be a duplicate of #621.

(I managed to work around the issue by setting the datalayout string).

Full error
gabi@bencher15 /tmp > $CHERI/bin/llvm-as bug.ll -o bug.bc && $CHERI/bin/clang --config cheribsd-morello-purecap.cfg -c bug.bc -o bug.o
warning: overriding the module target triple with aarch64-unknown-freebsd13 [-Woverride-module]
clang: /home/gabi/cheri/morello-llvm-project/llvm/lib/Target/AArch64/AArch64Sandbox.cpp:436: virtual bool (anonymous namespace)::AArch64Sandbox::runOnFunction(llvm::Function &): Assertion `AI->getType()->getPointerAddressSpace() == 200' failed.
PLEASE submit a bug report to https://git.morello-project.org/morello/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/gabi/cheri/output/morello-sdk//bin/clang --config cheribsd-morello-purecap.cfg -c bug.bc -o bug.o
1.      Code generation
2.      Running pass 'Function Pass Manager' on module 'bug.bc'.
3.      Running pass 'AArch64 sandbox setup' on function '@accessPayload'
 #0 0x00007f015ffbfeb3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libLLVM-13git.so+0x2271eb3)
 #1 0x00007f015ffbdb8e llvm::sys::RunSignalHandlers() (/home/gabi/cheri/output/morello-sdk/bin/../lib/libLLVM-13git.so+0x226fb8e)
 #2 0x00007f015ffbf25d llvm::sys::CleanupOnSignal(unsigned long) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libLLVM-13git.so+0x227125d)
 #3 0x00007f015feec2c3 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #4 0x00007f015feec46e CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #5 0x00007f016610c140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140)
 #6 0x00007f015d884ce1 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #7 0x00007f015d86e537 abort ./stdlib/abort.c:81:7
 #8 0x00007f015d86e40f get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
 #9 0x00007f015d86e40f _nl_load_domain ./intl/loadmsgcat.c:970:34
#10 0x00007f015d87d662 (/lib/x86_64-linux-gnu/libc.so.6+0x31662)
#11 0x00007f01621c7b56 (anonymous namespace)::AArch64Sandbox::runOnFunction(llvm::Function&) AArch64Sandbox.cpp:0:0
#12 0x00007f016013c498 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libLLVM-13git.so+0x23ee498)
#13 0x00007f0160142cb8 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libLLVM-13git.so+0x23f4cb8)
#14 0x00007f016013cb47 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libLLVM-13git.so+0x23eeb47)
#15 0x00007f016515291f (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) BackendUtil.cpp:0:0
#16 0x00007f016514b6cc clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x26756cc)
#17 0x00007f01654b0423 clang::CodeGenAction::ExecuteAction() (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x29da423)
#18 0x00007f0165ab7563 clang::FrontendAction::Execute() (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x2fe1563)
#19 0x00007f0165a25698 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x2f4f698)
#20 0x00007f0165b38b5c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x3062b5c)
#21 0x0000000000215a96 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/gabi/cheri/output/morello-sdk//bin/clang+0x215a96)
#22 0x0000000000213a1d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#23 0x00007f01656da202 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::$_1>(long) Job.cpp:0:0
#24 0x00007f015feec1d7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libLLVM-13git.so+0x219e1d7)
#25 0x00007f01656d9c07 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x2c03c07)
#26 0x00007f01656a3024 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x2bcd024)
#27 0x00007f01656a3567 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x2bcd567)
#28 0x00007f01656bed7b clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/home/gabi/cheri/output/morello-sdk/bin/../lib/libclang-cpp.so.13git+0x2be8d7b)
#29 0x00000000002133af main (/home/gabi/cheri/output/morello-sdk//bin/clang+0x2133af)
#30 0x00007f015d86fd0a __libc_start_main ./csu/../csu/libc-start.c:308:16
#31 0x000000000021092a _start (/home/gabi/cheri/output/morello-sdk//bin/clang+0x21092a)
clang-13: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 13.0.0 (https://git.morello-project.org/morello/llvm-project.git c73b7d332e1b957a90303642882d8198858f2c17)
Target: aarch64-unknown-freebsd13
Thread model: posix
InstalledDir: /home/gabi/cheri/output/morello-sdk//bin
Configuration file: /home/gabi/cheri/output/morello-sdk/bin/cheribsd-morello-purecap.cfg
clang-13: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
gabi@bencher15 /tmp [134] > echo $CHERI
/home/gabi/cheri/output/morello-sdk/

This is an issue with upstream's BitcodeReader; filed as llvm/llvm-project#60127.

llvm/llvm-project@b190108, fixed in 15, but 13+ supports multiple alloca address spaces.

llvm/llvm-project@b190108, fixed in 15, but 13+ supports multiple alloca address spaces.

Got it, thank you! (I am indeed using clang 13, I just forgot to mention it in the bug report)