[PATCH] D110979: Re-apply the fix on DwarfEHPrepare and add a test

Takafumi Arakaki via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 1 16:23:10 PDT 2021


tkf created this revision.
Herald added subscribers: ctetreau, pengfei, hiraditya.
tkf requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch re-introduces the fix in the commit https://github.com/llvm/llvm-project/commit/66b0cebf7f736 by @yrnkrn

> In DwarfEHPrepare, after all passes are run, RewindFunction may be a dangling
>
> pointer to a dead function. To make sure it's valid, doFinalization nullptrs
> RewindFunction just like the constructor and so it will be found on next run.
>
> llvm-svn: 217737

It seems that the fix was not migrated to `DwarfEHPrepareLegacyPass`.

This patch also updates `llvm/test/CodeGen/X86/dwarf-eh-prepare.ll` to include `-run-twice` to exercise the cleanup. Without this patch `llvm-lit -v llvm/test/CodeGen/X86/dwarf-eh-prepare.ll` fails with

  -- Testing: 1 tests, 1 workers --
  FAIL: LLVM :: CodeGen/X86/dwarf-eh-prepare.ll (1 of 1)
  ******************** TEST 'LLVM :: CodeGen/X86/dwarf-eh-prepare.ll' FAILED ********************
  Script:
  --
  : 'RUN: at line 1';   /home/arakaki/build/llvm-project/main/bin/opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 -run-twice < /home/arakaki/repos/watch/llvm-project/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll -S | /home/arakaki/build/llvm-project/main/bin/FileCheck /home/arakaki/repos/watch/llvm-project/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
  --
  Exit Code: 2
  
  Command Output (stderr):
  --
  Referencing function in another module!
    call void @_Unwind_Resume(i8* %ehptr) #1
  ; ModuleID = '<stdin>'
  void (i8*)* @_Unwind_Resume
  ; ModuleID = '<stdin>'
  in function simple_cleanup_catch
  LLVM ERROR: Broken function found, compilation aborted!
  PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
  Stack dump:
  0.      Program arguments: /home/arakaki/build/llvm-project/main/bin/opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 -run-twice -S
  1.      Running pass 'Function Pass Manager' on module '<stdin>'.
  2.      Running pass 'Module Verifier' on function '@simple_cleanup_catch'
   #0 0x000056121b570a2c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:0
   #1 0x000056121b56eb64 llvm::sys::RunSignalHandlers() /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/Signals.cpp:97:0
   #2 0x000056121b56f28e SignalHandler(int) /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/Unix/Signals.inc:397:0
   #3 0x00007fc7e9b22980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
   #4 0x00007fc7e87d3fb7 raise /build/glibc-S7xCS9/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
   #5 0x00007fc7e87d5921 abort /build/glibc-S7xCS9/glibc-2.27/stdlib/abort.c:81:0
   #6 0x000056121b4e1386 llvm::raw_svector_ostream::raw_svector_ostream(llvm::SmallVectorImpl<char>&) /home/arakaki/repos/watch/llvm-project/llvm/include/llvm/Support/raw_ostream.h:674:0
   #7 0x000056121b4e1386 llvm::report_fatal_error(llvm::Twine const&, bool) /home/arakaki/repos/watch/llvm-project/llvm/lib/Support/ErrorHandling.cpp:114:0
   #8 0x000056121b4e1528 (/home/arakaki/build/llvm-project/main/bin/opt+0x29e3528)
   #9 0x000056121adfd03f llvm::raw_ostream::operator<<(llvm::StringRef) /home/arakaki/repos/watch/llvm-project/llvm/include/llvm/Support/raw_ostream.h:218:0
  #10 0x000056121adfd03f (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) /home/arakaki/repos/watch/llvm-project/llvm/lib/IR/Verifier.cpp:5869:0
  #11 0x000056121ad6ff96 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/arakaki/repos/watch/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1449:0
  #12 0x000056121ad701a3 llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::Function, false, false, void> >::getNext() /home/arakaki/repos/watch/llvm-project/llvm/include/llvm/ADT/ilist_node.h:66:0
  #13 0x000056121ad701a3 llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Function, false, false, void>, false, false>::operator++() /home/arakaki/repos/watch/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:157:0
  #14 0x000056121ad701a3 llvm::FPPassManager::runOnModule(llvm::Module&) /home/arakaki/repos/watch/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1484:0
  #15 0x000056121ad7125c runOnModule /home/arakaki/repos/watch/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1561:0
  #16 0x000056121ad7125c llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/arakaki/repos/watch/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:542:0
  #17 0x00005612193270ca main /home/arakaki/repos/watch/llvm-project/llvm/tools/opt/opt.cpp:1044:0
  #18 0x00007fc7e87b6bf7 __libc_start_main /build/glibc-S7xCS9/glibc-2.27/csu/../csu/libc-start.c:344:0
  #19 0x00005612193f2c5a _start (/home/arakaki/build/llvm-project/main/bin/opt+0x8f4c5a)
  FileCheck error: '<stdin>' is empty.
  FileCheck command line:  /home/arakaki/build/llvm-project/main/bin/FileCheck /home/arakaki/repos/watch/llvm-project/llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
  
  --
  
  ********************
  ********************
  Failed Tests (1):
    LLVM :: CodeGen/X86/dwarf-eh-prepare.ll
  
  
  Testing Time: 0.22s
    Failed: 1


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110979

Files:
  llvm/lib/CodeGen/DwarfEHPrepare.cpp
  llvm/test/CodeGen/X86/dwarf-eh-prepare.ll


Index: llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
===================================================================
--- llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
+++ llvm/test/CodeGen/X86/dwarf-eh-prepare.ll
@@ -1,4 +1,4 @@
-; RUN: opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 < %s -S | FileCheck %s
+; RUN: opt -mtriple=x86_64-linux-gnu -dwarfehprepare -simplifycfg-require-and-preserve-domtree=1 -run-twice < %s -S | FileCheck %s
 
 ; Check basic functionality of IR-to-IR DWARF EH preparation. This should
 ; eliminate resumes. This pass requires a TargetMachine, so we put it under X86
Index: llvm/lib/CodeGen/DwarfEHPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/DwarfEHPrepare.cpp
+++ llvm/lib/CodeGen/DwarfEHPrepare.cpp
@@ -318,6 +318,11 @@
     return prepareDwarfEH(OptLevel, RewindFunction, F, TLI, DT, TTI);
   }
 
+  bool doFinalization(Module &M) override {
+    RewindFunction = nullptr;
+    return false;
+  }
+
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<TargetPassConfig>();
     AU.addRequired<TargetTransformInfoWrapperPass>();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110979.376648.patch
Type: text/x-patch
Size: 1185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211001/ad953728/attachment.bin>


More information about the llvm-commits mailing list