[llvm] Allow DW_OP_rot, DW_OP_neg, and DW_OP_abs in DIExpression (PR #160757)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 25 11:48:23 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Tom Tromey (tromey)
<details>
<summary>Changes</summary>
The Ada front end can emit somewhat complicated DWARF expressions for the offset of a field. While working in this area I found that I needed DW_OP_rot (to implement a branch-free computation -- it looked more difficult to add support for branching); and DW_OP_neg and DW_OP_abs (just basic functionality).
---
Full diff: https://github.com/llvm/llvm-project/pull/160757.diff
3 Files Affected:
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp (+3)
- (modified) llvm/lib/IR/DebugInfoMetadata.cpp (+3)
- (added) llvm/test/Bitcode/DW_OP_rot_neg_abs.ll (+10)
``````````diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 1703b27d350f3..bc0bb349be249 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -618,12 +618,15 @@ bool DwarfExpression::addExpression(
case dwarf::DW_OP_dup:
case dwarf::DW_OP_push_object_address:
case dwarf::DW_OP_over:
+ case dwarf::DW_OP_rot:
case dwarf::DW_OP_eq:
case dwarf::DW_OP_ne:
case dwarf::DW_OP_gt:
case dwarf::DW_OP_ge:
case dwarf::DW_OP_lt:
case dwarf::DW_OP_le:
+ case dwarf::DW_OP_neg:
+ case dwarf::DW_OP_abs:
emitOp(OpNum);
break;
case dwarf::DW_OP_deref:
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 1ededb9e7b3e2..77d044b55f7e0 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -1768,6 +1768,7 @@ bool DIExpression::isValid() const {
case dwarf::DW_OP_bregx:
case dwarf::DW_OP_push_object_address:
case dwarf::DW_OP_over:
+ case dwarf::DW_OP_rot:
case dwarf::DW_OP_consts:
case dwarf::DW_OP_eq:
case dwarf::DW_OP_ne:
@@ -1775,6 +1776,8 @@ bool DIExpression::isValid() const {
case dwarf::DW_OP_ge:
case dwarf::DW_OP_lt:
case dwarf::DW_OP_le:
+ case dwarf::DW_OP_neg:
+ case dwarf::DW_OP_abs:
break;
}
}
diff --git a/llvm/test/Bitcode/DW_OP_rot_neg_abs.ll b/llvm/test/Bitcode/DW_OP_rot_neg_abs.ll
new file mode 100644
index 0000000000000..e185530ead6d6
--- /dev/null
+++ b/llvm/test/Bitcode/DW_OP_rot_neg_abs.ll
@@ -0,0 +1,10 @@
+;; This test checks the validity of DWARF operators DW_OP_rot, DW_OP_neg, and DW_OP_abs.
+
+; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
+
+; CHECK: !DIExpression(DW_OP_push_object_address, DW_OP_lit0, DW_OP_lit0, DW_OP_neg, DW_OP_abs, DW_OP_rot, DW_OP_rot, DW_OP_rot, DW_OP_plus, DW_OP_plus)
+
+; ModuleID = 'DW_OP_rot_neg_abs.adb'
+source_filename = "/dir/DW_OP_rot_neg_abs.ll"
+
+!named = !{!DIExpression(DW_OP_push_object_address, DW_OP_lit0, DW_OP_lit0, DW_OP_neg, DW_OP_abs, DW_OP_rot, DW_OP_rot, DW_OP_rot, DW_OP_plus, DW_OP_plus)}
``````````
</details>
https://github.com/llvm/llvm-project/pull/160757
More information about the llvm-commits
mailing list