[llvm] r331635 - Add option -verify-cfiinstrs to run verifier in CFIInstrInserter

Petar Jovanovic via llvm-commits llvm-commits at lists.llvm.org
Mon May 7 07:09:33 PDT 2018


Author: petarj
Date: Mon May  7 07:09:33 2018
New Revision: 331635

URL: http://llvm.org/viewvc/llvm-project?rev=331635&view=rev
Log:
Add option -verify-cfiinstrs to run verifier in CFIInstrInserter

Instead of enabling it for non NDEBUG builds, use -verify-cfiinstrs to
run verifier in CFIInstrInserter. It defaults to false.

Differential Revision: https://reviews.llvm.org/D46444

Added:
    llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-offset.mir
    llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-register.mir
Modified:
    llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp

Modified: llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp?rev=331635&r1=331634&r2=331635&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp (original)
+++ llvm/trunk/lib/CodeGen/CFIInstrInserter.cpp Mon May  7 07:09:33 2018
@@ -29,6 +29,11 @@
 #include "llvm/Target/TargetMachine.h"
 using namespace llvm;
 
+static cl::opt<bool> VerifyCFI("verify-cfiinstrs",
+    cl::desc("Verify Call Frame Information instructions"),
+    cl::init(false),
+    cl::Hidden);
+
 namespace {
 class CFIInstrInserter : public MachineFunctionPass {
  public:
@@ -50,11 +55,12 @@ class CFIInstrInserter : public MachineF
 
     MBBVector.resize(MF.getNumBlockIDs());
     calculateCFAInfo(MF);
-#ifndef NDEBUG
-    if (unsigned ErrorNum = verify(MF))
-      report_fatal_error("Found " + Twine(ErrorNum) +
-                         " in/out CFI information errors.");
-#endif
+
+    if (VerifyCFI) {
+      if (unsigned ErrorNum = verify(MF))
+        report_fatal_error("Found " + Twine(ErrorNum) +
+                           " in/out CFI information errors.");
+    }
     bool insertedCFI = insertCFIInstrs(MF);
     MBBVector.clear();
     return insertedCFI;

Added: llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-offset.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-offset.mir?rev=331635&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-offset.mir (added)
+++ llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-offset.mir Mon May  7 07:09:33 2018
@@ -0,0 +1,26 @@
+# RUN: not llc -o - %s -mtriple=x86_64-- -verify-cfiinstrs \
+# RUN:     -run-pass=cfi-instr-inserter 2>&1 | FileCheck %s
+# Test that CFI verifier finds inconsistent offset between bb.end and one of
+# its precedessors.
+--- |
+  define void @inconsistentOffset() {
+    bb.end:
+      ret void
+  }
+...
+---
+# CHECK: *** Inconsistent CFA register and/or offset between pred and succ ***
+# CHECK: Succ: bb.end
+# CHECK: LLVM ERROR: Found 1 in/out CFI information errors.
+name: inconsistentOffset
+body: |
+  bb.0:
+    CFI_INSTRUCTION def_cfa_offset 24
+    JNE_1 %bb.2, implicit undef $eflags
+
+  bb.1:
+    CFI_INSTRUCTION def_cfa_offset 32
+
+  bb.2.bb.end:
+    RET 0
+...

Added: llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-register.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-register.mir?rev=331635&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-register.mir (added)
+++ llvm/trunk/test/CodeGen/X86/cfi-inserter-verify-inconsistent-register.mir Mon May  7 07:09:33 2018
@@ -0,0 +1,26 @@
+# RUN: not llc -o - %s -mtriple=x86_64-- -verify-cfiinstrs \
+# RUN:     -run-pass=cfi-instr-inserter 2>&1 | FileCheck %s
+# Test that CFI verifier finds inconsistent register between bb.end and one of
+# its precedessors.
+--- |
+  define void @inconsistentRegister() {
+    bb.end:
+      ret void
+  }
+...
+---
+# CHECK: *** Inconsistent CFA register and/or offset between pred and succ ***
+# CHECK: Succ: bb.end
+# CHECK: LLVM ERROR: Found 1 in/out CFI information errors.
+name: inconsistentRegister
+body: |
+  bb.0:
+    CFI_INSTRUCTION def_cfa_register $rbp
+    JNE_1 %bb.2, implicit undef $eflags
+
+  bb.1:
+    CFI_INSTRUCTION def_cfa $rsp, 8
+
+  bb.2.bb.end:
+    RET 0
+...




More information about the llvm-commits mailing list