[llvm] 5752fb8 - llvm-extract: Fix not verifying input file (#225378)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 06:06:10 PDT 2026
Author: Matt Arsenault
Date: 2026-09-22T15:06:04+02:00
New Revision: 5752fb836ad4beb66316fb87825257072d677d1e
URL: https://github.com/llvm/llvm-project/commit/5752fb836ad4beb66316fb87825257072d677d1e
DIFF: https://github.com/llvm/llvm-project/commit/5752fb836ad4beb66316fb87825257072d677d1e.diff
LOG: llvm-extract: Fix not verifying input file (#225378)
Copy the behavior from opt, and add a -disable-verify flag.
Added:
llvm/test/tools/llvm-extract/verify-input.ll
Modified:
llvm/test/tools/llvm-extract/recursive.ll
llvm/tools/llvm-extract/llvm-extract.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-extract/recursive.ll b/llvm/test/tools/llvm-extract/recursive.ll
index 7fa9eceba91eb..05cd4f6edffc6 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 0000000000000..85051486c2a47
--- /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 17ce664a64ba2..717ee339eaa65 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