[llvm] [llvm-diff] Also diff alloca's allocated type and alignment (PR #84781)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 09:13:35 PDT 2024


https://github.com/YanWQ-monad created https://github.com/llvm/llvm-project/pull/84781

Currently, the function
https://github.com/llvm/llvm-project/blob/8c3304453c22ad1b5a914e64a7f6435f58f4099c/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp#L364-L369
doesn't handle the non-operand data of `AllocaInst`. For example,
``` llvm
alloca i64, align 1
alloca i32, align 1
```
would be considered the same instruction.

---

Under some special circumstances, that would make llvm-diff crash:
``` llvm
define ptr @func() {
  %1 = alloca i64, align 1
  %2 = alloca i32, align 1
  %3 = alloca i8, align 1
  ret ptr %2
}
```

``` llvm
define ptr @func() {
  %1 = alloca i64, align 1
  %2 = alloca i32, align 1
  ret ptr %2
}
```

```
$ ./build/bin/llvm-diff lhs.ll rhs.ll
in function func:
  in block %0 / %0:
    in instruction   ret ptr %2 /   ret ptr %2:
      operands %2 and %2 differ
llvm-diff: path/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp:268: void (anonymous namespace)::FunctionDifferenceEngine::unify(const Instruction *, const Instruction *): Assertion `!Result && "structural differences second time around?"' failed.
fish: Job 1, './build/bin/llvm-diff lhs.ll r…' terminated by signal SIGABRT (Abort)
```

>From 431bdd42855c957eb0efefc4a03ac4adacd4c5c8 Mon Sep 17 00:00:00 2001
From: YanWQ-monad <YanWQmonad at gmail.com>
Date: Mon, 11 Mar 2024 23:59:47 +0800
Subject: [PATCH] Diff alloca allocated type and alignment

---
 llvm/tools/llvm-diff/lib/DifferenceEngine.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp b/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
index 64b5051af14892..b34fd2acaa5368 100644
--- a/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
+++ b/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
@@ -527,6 +527,20 @@ class FunctionDifferenceEngine {
           Difference = true;
         }
       return Difference;
+    } else if (isa<AllocaInst>(L)) {
+      const AllocaInst *LI = cast<AllocaInst>(L);
+      const AllocaInst *RI = cast<AllocaInst>(R);
+
+      if (LI->getAllocatedType() != RI->getAllocatedType()) {
+        if (Complain)
+          Engine.log("alloca allocated type differ");
+        return true;
+      }
+      if (LI->getAlign() != RI->getAlign()) {
+        if (Complain)
+          Engine.log("alloca alignment differ");
+        return true;
+      }
     } else if (isa<UnreachableInst>(L)) {
       return false;
     }



More information about the llvm-commits mailing list