Closed arichardson closed 6 years ago
This happens with latest CheriBSD master branch (after userspace_ccall merge)
I wonder whether we should make this comparison an error or at least and Werror by default warning?
Reduced test case:
// RUN: %cheri_cc1 -target-abi n64 -O2 -std=gnu99 -fconst-strings -vectorize-loops -vectorize-slp -o - -O0 -emit-llvm %s struct a { void *__capability b; } * c; _Bool cheritest_libcheri_userfn_getstack(struct a *csfp) { return csfp->b != c; }
Stack trace:
wrong cast for pointers in different address spaces(must be an address space cast)! UNREACHABLE executed at /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:1761! #0 0x00007f6ef49e8d29 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /local/scratch/alr48/cheri/llvm/lib/Support/Unix/Signals.inc:398:11 #1 0x00007f6ef49e8ed9 PrintStackTraceSignalHandler(void*) /local/scratch/alr48/cheri/llvm/lib/Support/Unix/Signals.inc:494:1 #2 0x00007f6ef49e7483 llvm::sys::RunSignalHandlers() /local/scratch/alr48/cheri/llvm/lib/Support/Signals.cpp:0:5 #3 0x00007f6ef49e9234 SignalHandler(int) /local/scratch/alr48/cheri/llvm/lib/Support/Unix/Signals.inc:252:1 #4 0x00007f6ef3f13390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #5 0x00007f6ef1c43428 gsignal /build/glibc-bfm8X4/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0 #6 0x00007f6ef1c4502a abort /build/glibc-bfm8X4/glibc-2.23/stdlib/abort.c:91:0 #7 0x00007f6ef4900450 LLVMInstallFatalErrorHandler /local/scratch/alr48/cheri/llvm/lib/Support/ErrorHandling.cpp:209:0 #8 0x00007f6ef364b553 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:0:7 #9 0x00007f6ef36438b8 clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*) /local/scratch/alr48/cheri/llvm/cmake-build-debug/tools/clang/include/clang/AST/StmtNodes.inc:423:1 #10 0x00007f6ef363e44b clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /local/scratch/alr48/cheri/llvm/cmake-build-debug/tools/clang/include/clang/AST/StmtNodes.inc:423:1 #11 0x00007f6ef36366e9 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:359:52 #12 0x00007f6ef3648d60 (anonymous namespace)::ScalarExprEmitter::EmitCompare(clang::BinaryOperator const*, llvm::CmpInst::Predicate, llvm::CmpInst::Predicate, llvm::CmpInst::Predicate) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:3426:18 #13 0x00007f6ef363f9ec (anonymous namespace)::ScalarExprEmitter::VisitBinNE(clang::BinaryOperator const*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:802:3 #14 0x00007f6ef363d97f clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /local/scratch/alr48/cheri/llvm/tools/clang/include/clang/AST/StmtVisitor.h:64:26 #15 0x00007f6ef36366e9 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:359:52 #16 0x00007f6ef364ccaf (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:2010:12 #17 0x00007f6ef36438b8 clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*) /local/scratch/alr48/cheri/llvm/cmake-build-debug/tools/clang/include/clang/AST/StmtNodes.inc:423:1 #18 0x00007f6ef363e44b clang::StmtVisitorBase<clang::make_ptr, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) /local/scratch/alr48/cheri/llvm/cmake-build-debug/tools/clang/include/clang/AST/StmtNodes.inc:423:1 #19 0x00007f6ef36366e9 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:359:52 #20 0x00007f6ef3636633 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGExprScalar.cpp:4102:3 #21 0x00007f6ef375644f clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGStmt.cpp:1068:18 #22 0x00007f6ef3753850 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGStmt.cpp:139:75 #23 0x00007f6ef375c4ec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CGStmt.cpp:380:42 #24 0x00007f6ef37d7692 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&, clang::Stmt const*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:1156:5 #25 0x00007f6ef37d80f3 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:1322:3 #26 0x00007f6ef37f7648 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:3315:26 #27 0x00007f6ef37f19b8 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:2052:12 #28 0x00007f6ef37f5b16 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:1829:5 #29 0x00007f6ef37fa541 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:4063:38 #30 0x00007f6ef39f0b52 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/ModuleBuilder.cpp:159:73 #31 0x00007f6ef37c64a3 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:168:12 #32 0x00007f6eef0e2393 clang::ParseAST(clang::Sema&, bool, bool) /local/scratch/alr48/cheri/llvm/tools/clang/lib/Parse/ParseAST.cpp:151:18 #33 0x00007f6ef2c7f20c clang::ASTFrontendAction::ExecuteAction() /local/scratch/alr48/cheri/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:1000:1 #34 0x00007f6ef37c3003 clang::CodeGenAction::ExecuteAction() /local/scratch/alr48/cheri/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:1033:1 #35 0x00007f6ef2c7ec80 clang::FrontendAction::Execute() /local/scratch/alr48/cheri/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:901:7 #36 0x00007f6ef2bf73ca clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /local/scratch/alr48/cheri/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:992:7 #37 0x00007f6ef28a7846 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /local/scratch/alr48/cheri/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:252:8 #38 0x000000000023b609 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /local/scratch/alr48/cheri/llvm/tools/clang/tools/driver/cc1_main.cpp:221:11 #39 0x000000000022e519 ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) /local/scratch/alr48/cheri/llvm/tools/clang/tools/driver/driver.cpp:309:5 #40 0x000000000022d21d main /local/scratch/alr48/cheri/llvm/tools/clang/tools/driver/driver.cpp:388:5 #41 0x00007f6ef1c2e830 __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:325:0 #42 0x000000000022c029 _start (/local/scratch/alr48/cheri/llvm/cmake-build-debug/bin/clang+0x22c029)
This should be inserting an implicit cast from integer pointer to capability, and erroring because the implicit cast is not allowed.
This happens with latest CheriBSD master branch (after userspace_ccall merge)
I wonder whether we should make this comparison an error or at least and Werror by default warning?
Reduced test case:
Stack trace: