[llvm-bugs] [Bug 47637] New: Assertion failure in SelectionDAG with -fsanitize=cfi

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 24 08:25:45 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47637

            Bug ID: 47637
           Summary: Assertion failure in SelectionDAG with -fsanitize=cfi
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: sunil_srivastava at playstation.sony.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 23998
  --> https://bugs.llvm.org/attachment.cgi?id=23998&action=edit
IR Reproducer

As shown below, an attempt to compile a thin-lto bitcode file with
-fsanitize=cfi fails :

$ cat m.cpp
int abcd(int (*x)())
{
  return x();
}

$ clang -flto=thin -fsanitize=cfi -fvisibility=hidden -c -o m.o m.cpp -O2
$ llvm-modextract -n=0 m.o -o m0.bc
$ clang -c m0.bc 
clang: /home/sunil/CLG/llvm-project/llvm/include/llvm/Support/Casting.h:269:
typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X =
llvm::MDNode; Y = llvm::Metadata; typename llvm::cast_retty<X, Y*>::ret_type =
llvm::MDNode*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible
type!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.            Program arguments: clang -c m0.bc -w 
1.            Code generation
2.            Running pass 'Function Pass Manager' on module 'm0.bc'.
3.            Running pass 'X86 DAG->DAG Instruction Selection' on function
'@_Z4abcdPFivE'
#0 0x000055e2f408e63e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
/home/sunil/CLG/llvm-project/llvm/lib/Support/Unix/Signals.inc:563:0
#1 0x000055e2f408e6e2 PrintStackTraceSignalHandler(void*)
/home/sunil/CLG/llvm-project/llvm/lib/Support/Unix/Signals.inc:627:0
#2 0x000055e2f408c487 llvm::sys::RunSignalHandlers()
/home/sunil/CLG/llvm-project/llvm/lib/Support/Signals.cpp:70:0
#3 0x000055e2f408deb8 llvm::sys::CleanupOnSignal(unsigned long)
/home/sunil/CLG/llvm-project/llvm/lib/Support/Unix/Signals.inc:361:0
#4 0x000055e2f3f88cb6 (anonymous
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long)
/home/sunil/CLG/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:77:0
#5 0x000055e2f3f8918e CrashRecoverySignalHandler(int)
/home/sunil/CLG/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:383:0
#6 0x00007fab58b418a0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
#7 0x00007fab577f2f47 raise
/build/glibc-2ORdQG/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#8 0x00007fab577f48b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0
#9 0x00007fab577e442a __assert_fail_base
/build/glibc-2ORdQG/glibc-2.27/assert/assert.c:89:0
#10 0x00007fab577e44a2 (/lib/x86_64-linux-gnu/libc.so.6+0x304a2)
#11 0x000055e2f2c8e41c llvm::cast_retty<llvm::MDNode,
llvm::Metadata*>::ret_type llvm::cast<llvm::MDNode,
llvm::Metadata>(llvm::Metadata*)
/home/sunil/CLG/llvm-project/llvm/include/llvm/Support/Casting.h:269:0
#12 0x000055e2f541a394 llvm::SelectionDAGBuilder::getValueImpl(llvm::Value
const*)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1613:0
#13 0x000055e2f5418a4b llvm::SelectionDAGBuilder::getValue(llvm::Value const*)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1437:0
#14 0x000055e2f542fc1a
llvm::SelectionDAGBuilder::visitTargetIntrinsic(llvm::CallInst const&, unsigned
int)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:4676:0
#15 0x000055e2f54373e4
llvm::SelectionDAGBuilder::visitIntrinsicCall(llvm::CallInst const&, unsigned
int)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:5645:0
#16 0x000055e2f5445081 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst
const&)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:7573:0
#17 0x000055e2f5416e3e llvm::SelectionDAGBuilder::visit(unsigned int,
llvm::User const&)
/home/sunil/CLG/llvm-project/llvm/include/llvm/IR/Instruction.def:209:0
#18 0x000055e2f5416744 llvm::SelectionDAGBuilder::visit(llvm::Instruction
const&)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1123:0
#19 0x000055e2f54cefa0
llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction,
true, false, void>, false, true>,
llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true,
false, void>, false, true>, bool&)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:697:0
#20 0x000055e2f54d3794
llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1524:0
#21 0x000055e2f54cdc03
llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:505:0
#22 0x000055e2f275cb4d (anonymous
namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&)
/home/sunil/CLG/llvm-project/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:190:0
#23 0x000055e2f306d739
llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
/home/sunil/CLG/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:0
#24 0x000055e2f3633744 llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/sunil/CLG/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1587:0
#25 0x000055e2f36339ed llvm::FPPassManager::runOnModule(llvm::Module&)
/home/sunil/CLG/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1633:0
#26 0x000055e2f3633e15 (anonymous
namespace)::MPPassManager::runOnModule(llvm::Module&)
/home/sunil/CLG/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1702:0
#27 0x000055e2f362ee2d llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/sunil/CLG/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:614:0
#28 0x000055e2f36346a1 llvm::legacy::PassManager::run(llvm::Module&)
/home/sunil/CLG/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1830:0
#29 0x000055e2f44224dc (anonymous
namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
/home/sunil/CLG/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:971:0
#30 0x000055e2f4427423 clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout
const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
/home/sunil/CLG/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1689:0
#31 0x000055e2f55ead5c clang::CodeGenAction::ExecuteAction()
/home/sunil/CLG/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1171:0
#32 0x000055e2f4c9a3c8 clang::FrontendAction::Execute()
/home/sunil/CLG/llvm-project/clang/lib/Frontend/FrontendAction.cpp:954:0
#33 0x000055e2f4c2eed1
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/home/sunil/CLG/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:984:0
#34 0x000055e2f4e26b46
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/home/sunil/CLG/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:278:0
#35 0x000055e2f1353937 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) /home/sunil/CLG/llvm-project/clang/tools/driver/cc1_main.cpp:240:0
#36 0x000055e2f1348ea6 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
/home/sunil/CLG/llvm-project/clang/tools/driver/driver.cpp:330:0
#37 0x000055e2f4b27569
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
>, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >*, bool*) const::'lambda'()::operator()() const
/home/sunil/CLG/llvm-project/clang/lib/Driver/Job.cpp:400:0
#38 0x000055e2f4b27e14 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::'lambda'()>(long)
/home/sunil/CLG/llvm-project/llvm/include/llvm/ADT/STLExtras.h:186:0
#39 0x000055e2f3f7d5d4 llvm::function_ref<void ()>::operator()() const
/home/sunil/CLG/llvm-project/llvm/include/llvm/ADT/STLExtras.h:203:0
#40 0x000055e2f3f8938d
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
/home/sunil/CLG/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:419:0
#41 0x000055e2f4b2778d
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/sunil/CLG/llvm-project/clang/lib/Driver/Job.cpp:400:0
#42 0x000055e2f4addee2
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const
/home/sunil/CLG/llvm-project/clang/lib/Driver/Compilation.cpp:195:0
#43 0x000055e2f4ade23a
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
/home/sunil/CLG/llvm-project/clang/lib/Driver/Compilation.cpp:246:0
#44 0x000055e2f4aedb16
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
/home/sunil/CLG/llvm-project/clang/lib/Driver/Driver.cpp:1512:0
#45 0x000055e2f1349e86 main
/home/sunil/CLG/llvm-project/clang/tools/driver/driver.cpp:502:0
#46 0x00007fab577d5b97 __libc_start_main
/build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:344:0
#47 0x000055e2f134752a _start
(/home/sunil/CLG/llvm-project/BD/bin/clang-12+0x2ac052a)
clang-12: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 12.0.0 (https://github.com/llvm/llvm-project.git
60db26a66d5346b2feae279f6c928bde48078893)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/sunil/CLG/llvm-project/BD/bin
clang-12: note: diagnostic msg: Error generating preprocessed source(s) - no
preprocessable inputs.


$ llvm-dis m0.bc
$ cat m0.ll
; ModuleID = 'm0.bc'
source_filename = "m.cpp"
target datalayout =
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: uwtable
define hidden i32 @_Z4abcdPFivE(i32 ()* %x) local_unnamed_addr #0 !type !4
!type !5 {
entry:
  %0 = bitcast i32 ()* %x to i8*, !nosanitize !6
  %1 = tail call i1 @llvm.type.test(i8* %0, metadata !"_ZTSFivE"), !nosanitize
!6
  br i1 %1, label %cont, label %trap, !nosanitize !6

trap:                                             ; preds = %entry
  tail call void @llvm.trap() #3, !nosanitize !6
  unreachable, !nosanitize !6

cont:                                             ; preds = %entry
  %call = tail call i32 %x()
  ret i32 %call
}

; Function Attrs: nounwind readnone willreturn
declare i1 @llvm.type.test(i8*, metadata) #1

; Function Attrs: cold noreturn nounwind
declare void @llvm.trap() #2

attributes #0 = { uwtable "correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "frame-pointer"="none"
"less-precise-fpmad"="false" "min-legal-vector-width"="0"
"no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="true"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { nounwind readnone willreturn }
attributes #2 = { cold noreturn nounwind }
attributes #3 = { noreturn nounwind }

!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 4, !"CFI Canonical Jump Tables", i32 1}
!2 = !{i32 1, !"EnableSplitLTOUnit", i32 1}
!3 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git
60db26a66d5346b2feae279f6c928bde48078893)"}
!4 = !{i64 0, !"_ZTSFiPFivEE"}
!5 = !{i64 0, !"_ZTSFiPvE.generalized"}
!6 = !{}

$
======================================================================
cfi_blacklist.txt file is empty.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200924/01cd474a/attachment-0001.html>


More information about the llvm-bugs mailing list