[llvm] 0004fba - [StandardInstrumentations] Ensure non-null module pointer when getting display name for IR file (#110779)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 22:01:16 PDT 2024
Author: duk
Date: 2024-10-01T22:01:13-07:00
New Revision: 0004fba07972eb521b43d4336e6a9eff7e512ff8
URL: https://github.com/llvm/llvm-project/commit/0004fba07972eb521b43d4336e6a9eff7e512ff8
DIFF: https://github.com/llvm/llvm-project/commit/0004fba07972eb521b43d4336e6a9eff7e512ff8.diff
LOG: [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)
Added:
llvm/test/Other/dump-with-filter.ll
Modified:
llvm/lib/Passes/StandardInstrumentations.cpp
Removed:
################################################################################
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