[llvm] Allow DW_OP_rot, DW_OP_neg, and DW_OP_abs in DIExpression (PR #160757)
Tom Tromey via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 25 11:47:51 PDT 2025
https://github.com/tromey created https://github.com/llvm/llvm-project/pull/160757
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).
>From 0cfc788004ea4e82ce3b75214d90401ed009cf8e Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey at adacore.com>
Date: Tue, 23 Sep 2025 14:56:07 -0600
Subject: [PATCH] Allow DW_OP_rot, DW_OP_neg, and DW_OP_abs in DIExpression
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).
---
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp | 3 +++
llvm/lib/IR/DebugInfoMetadata.cpp | 3 +++
llvm/test/Bitcode/DW_OP_rot_neg_abs.ll | 10 ++++++++++
3 files changed, 16 insertions(+)
create mode 100644 llvm/test/Bitcode/DW_OP_rot_neg_abs.ll
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)}
More information about the llvm-commits
mailing list