[llvm] [StandardInstrumentations] Ensure non-null module pointer when getting display name for IR file (PR #110779)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 18:56:27 PDT 2024
https://github.com/duk-37 updated https://github.com/llvm/llvm-project/pull/110779
>From 2c8c0d3a1f235004f4a98f7f289f447ac638f179 Mon Sep 17 00:00:00 2001
From: duk <37 at cmail.nu>
Date: Tue, 1 Oct 2024 21:31:28 -0400
Subject: [PATCH] [StandardInstrumentations] Ensure non-null module pointer
when getting display name for IR file
Fixes a crash when using -filter-print-funcs with -ir-dump-directory.
---
llvm/lib/Passes/StandardInstrumentations.cpp | 3 ++-
llvm/test/Other/dump-with-filter.ll | 14 ++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Other/dump-with-filter.ll
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 036484c9c1c0c4..c960afcf6e9736 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -751,7 +751,8 @@ PrintIRInstrumentation::~PrintIRInstrumentation() {
static SmallString<32> getIRFileDisplayName(Any IR) {
SmallString<32> Result;
raw_svector_ostream ResultStream(Result);
- const Module *M = unwrapModule(IR);
+ const Module *M = unwrapModule(IR, /*Force=*/true);
+ assert(M && "should have unwrapped module");
uint64_t NameHash = xxh3_64bits(M->getName());
unsigned MaxHashWidth = sizeof(uint64_t) * 2;
write_hex(ResultStream, NameHash, HexPrintStyle::Lower, MaxHashWidth);
diff --git a/llvm/test/Other/dump-with-filter.ll b/llvm/test/Other/dump-with-filter.ll
new file mode 100644
index 00000000000000..6b6d73112fcc70
--- /dev/null
+++ b/llvm/test/Other/dump-with-filter.ll
@@ -0,0 +1,14 @@
+;; Make sure we can run -filter-print-funcs with -ir-dump-directory.
+; RUN: rm -rf %t/logs
+; RUN: opt %s -disable-output -passes='no-op-function' -print-before=no-op-function -print-after=no-op-function \
+; RUN: -ir-dump-directory %t/logs -filter-print-funcs=test2
+; RUN: ls %t/logs | count 2
+; RUN: rm -rf %t/logs
+
+define void @test() {
+ ret void
+}
+
+define void @test2() {
+ ret void
+}
More information about the llvm-commits
mailing list