Skip to content

Commit

Permalink
[StandardInstrumentations] Ensure non-null module pointer when gettin…
Browse files Browse the repository at this point in the history
…g 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)
  • Loading branch information
duk-37 authored Oct 2, 2024
1 parent 62cd07f commit 0004fba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llvm/lib/Passes/StandardInstrumentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Other/dump-with-filter.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 0004fba

Please sign in to comment.