[llvm] llvm-extract: Fix not verifying input file (PR #225378)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 04:52:01 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/225378

Copy the behavior from opt, and add a -disable-verify flag.

>From f7b5b432e7e523e5cc5c65a841e26b0677572f03 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 9 Apr 2025 14:59:29 +0800
Subject: [PATCH] llvm-extract: Fix not verifying input file

Copy the behavior from opt, and add a -disable-verify flag.
---
 llvm/test/tools/llvm-extract/recursive.ll    | 12 +++++++---
 llvm/test/tools/llvm-extract/verify-input.ll | 24 ++++++++++++++++++++
 llvm/tools/llvm-extract/llvm-extract.cpp     | 11 +++++++++
 3 files changed, 44 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/tools/llvm-extract/verify-input.ll

diff --git a/llvm/test/tools/llvm-extract/recursive.ll b/llvm/test/tools/llvm-extract/recursive.ll
index 7fa9eceba91eb4..05cd4f6edffc6f 100644
--- a/llvm/test/tools/llvm-extract/recursive.ll
+++ b/llvm/test/tools/llvm-extract/recursive.ll
@@ -32,9 +32,15 @@ define void @d() {
   ret void
 }
 
-define void @e() {
+define void @e() personality ptr @__gxx_personality_v0 {
   invoke void @c()
-  to label %L unwind label %L
+  to label %OK unwind label %L
+OK:
+  ret void
 L:
+  %exn = landingpad {ptr, i32} cleanup
+
   ret void
-}
\ No newline at end of file
+}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/llvm/test/tools/llvm-extract/verify-input.ll b/llvm/test/tools/llvm-extract/verify-input.ll
new file mode 100644
index 00000000000000..85051486c2a477
--- /dev/null
+++ b/llvm/test/tools/llvm-extract/verify-input.ll
@@ -0,0 +1,24 @@
+; RUN: not llvm-extract -S --func=e %s -o /dev/null 2>&1 | FileCheck -check-prefix=ERR %s
+; RUN: llvm-extract -S -disable-verify --func=e < %s | FileCheck %s
+
+; ERR: The unwind destination does not have an exception handling instruction!
+; ERR: error: input module is broken!
+
+; CHECK: declare void @c()
+define void @c() {
+  ret void
+}
+
+; CHECK: define void @e() {
+; CHECK-NEXT: invoke void @c()
+; CHECK-NEXT: to label %L unwind label %L
+
+; CHECK: L:
+; CHECK-NEXT: ret void
+define void @e() {
+  invoke void @c()
+  to label %L unwind label %L
+L:
+  ret void
+}
+
diff --git a/llvm/tools/llvm-extract/llvm-extract.cpp b/llvm/tools/llvm-extract/llvm-extract.cpp
index 17ce664a64ba22..717ee339eaa65c 100644
--- a/llvm/tools/llvm-extract/llvm-extract.cpp
+++ b/llvm/tools/llvm-extract/llvm-extract.cpp
@@ -19,6 +19,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/IRPrinter/IRPrintingPasses.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -57,6 +58,10 @@ static cl::opt<std::string> OutputFilename("o",
 static cl::opt<bool> Force("f", cl::desc("Enable binary output on terminals"),
                            cl::cat(ExtractCat));
 
+static cl::opt<bool> NoVerify("disable-verify",
+                              cl::desc("Do not run the verifier"),
+                              cl::cat(ExtractCat), cl::Hidden);
+
 static cl::opt<bool> DeleteFn("delete",
                               cl::desc("Delete specified Globals from Module"),
                               cl::cat(ExtractCat));
@@ -145,6 +150,12 @@ int main(int argc, char **argv) {
     return 1;
   }
 
+  if (!NoVerify && verifyModule(*M, &errs())) {
+    errs() << argv[0] << ": " << InputFilename
+           << ": error: input module is broken!\n";
+    return 1;
+  }
+
   // Use SetVector to avoid duplicates.
   SetVector<GlobalValue *> GVs;
 



More information about the llvm-commits mailing list