Skip to content

Commit 0004fba

Browse files
authored
[StandardInstrumentations] Ensure non-null module pointer when getting display name for IR file (#110779)
Fixes a crash when using `-filter-print-funcs` with `-ir-dump-directory`. A quick reproducer on trunk (also included as a test): ```ll ; opt -passes=no-op-function -print-after=no-op-function -filter-print-funcs=nope -ir-dump-directory=somewhere test.ll define void @test() { ret void } ``` [Compiler Explorer](https://godbolt.org/z/sPErz44h4)
1 parent 62cd07f commit 0004fba

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,8 @@ PrintIRInstrumentation::~PrintIRInstrumentation() {
751751
static SmallString<32> getIRFileDisplayName(Any IR) {
752752
SmallString<32> Result;
753753
raw_svector_ostream ResultStream(Result);
754-
const Module *M = unwrapModule(IR);
754+
const Module *M = unwrapModule(IR, /*Force=*/true);
755+
assert(M && "should have unwrapped module");
755756
uint64_t NameHash = xxh3_64bits(M->getName());
756757
unsigned MaxHashWidth = sizeof(uint64_t) * 2;
757758
write_hex(ResultStream, NameHash, HexPrintStyle::Lower, MaxHashWidth);

llvm/test/Other/dump-with-filter.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
;; Make sure we can run -filter-print-funcs with -ir-dump-directory.
2+
; RUN: rm -rf %t/logs
3+
; RUN: opt %s -disable-output -passes='no-op-function' -print-before=no-op-function -print-after=no-op-function \
4+
; RUN: -ir-dump-directory %t/logs -filter-print-funcs=test2
5+
; RUN: ls %t/logs | count 2
6+
; RUN: rm -rf %t/logs
7+
8+
define void @test() {
9+
ret void
10+
}
11+
12+
define void @test2() {
13+
ret void
14+
}

0 commit comments

Comments
 (0)