[llvm] [DirectX] Fix crash in DXILFlattenArrays for function declarations (PR #116690)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 18 12:16:14 PST 2024


https://github.com/bogner created https://github.com/llvm/llvm-project/pull/116690

We were skipping intrinsics here, but really we need to skip all function declarations - if the function doesn't have a body there's nothing to walk.

>From 6a66498d2bf27ac3ca5d2f52c3032de2918ac3b1 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Fri, 15 Nov 2024 14:39:56 -0800
Subject: [PATCH] [DirectX] Fix crash in DXILFlattenArrays for function
 declarations

We were skipping intrinsics here, but really we need to skip all function
declarations - if the function doesn't have a body there's nothing to walk.
---
 llvm/lib/Target/DirectX/DXILFlattenArrays.cpp | 2 +-
 llvm/test/CodeGen/DirectX/flatten-array.ll    | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp b/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
index dec3a9b4a82643..e4a3bc76eeacd2 100644
--- a/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
+++ b/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
@@ -402,7 +402,7 @@ static bool flattenArrays(Module &M) {
   DenseMap<GlobalVariable *, GlobalVariable *> GlobalMap;
   flattenGlobalArrays(M, GlobalMap);
   for (auto &F : make_early_inc_range(M.functions())) {
-    if (F.isIntrinsic())
+    if (F.isDeclaration())
       continue;
     MadeChange |= Impl.visit(F);
   }
diff --git a/llvm/test/CodeGen/DirectX/flatten-array.ll b/llvm/test/CodeGen/DirectX/flatten-array.ll
index fd894e0104c4e9..754d5a25ca905f 100644
--- a/llvm/test/CodeGen/DirectX/flatten-array.ll
+++ b/llvm/test/CodeGen/DirectX/flatten-array.ll
@@ -186,3 +186,6 @@ define void @global_gep_store() {
   store i32 1, i32* %3, align 4
   ret void
 }
+
+; Make sure we don't try to walk the body of a function declaration.
+declare void @opaque_function()



More information about the llvm-commits mailing list