[llvm] 7f596bb - [DebugInfo] printCompactDWARFExpr: don't assert on stack size

Scott Linder via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 13:49:32 PDT 2023


Author: Scott Linder
Date: 2023-04-19T20:46:18Z
New Revision: 7f596bb50944ee41a9dd1cb95c196dc6f8873b21

URL: https://github.com/llvm/llvm-project/commit/7f596bb50944ee41a9dd1cb95c196dc6f8873b21
DIFF: https://github.com/llvm/llvm-project/commit/7f596bb50944ee41a9dd1cb95c196dc6f8873b21.diff

LOG: [DebugInfo] printCompactDWARFExpr: don't assert on stack size

Gracefully handle non-1 stack sizes in printCompactDWARFExpr rather than
assert. Add support for DW_OP_nop and test the zero-sized stack case.

This is intended to be nearly NFC.

Differential Revision: https://reviews.llvm.org/D147269

Added: 
    

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
    llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 523dee486d2d6..3adc6c7bcbe56 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -454,6 +454,9 @@ static bool printCompactDWARFExpr(
       Stack.back().Kind = PrintedExpr::Value;
       break;
     }
+    case dwarf::DW_OP_nop: {
+      break;
+    }
     default:
       if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
         // DW_OP_reg<N>: A register, with the register num implied by the
@@ -487,7 +490,10 @@ static bool printCompactDWARFExpr(
     ++I;
   }
 
-  assert(Stack.size() == 1 && "expected one value on stack");
+  if (Stack.size() != 1) {
+    OS << "<stack of size " << Stack.size() << ", expected 1>";
+    return false;
+  }
 
   if (Stack.front().Kind == PrintedExpr::Address)
     OS << "[" << Stack.front().String << "]";

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
index e0c59189bf841..819f7d56a4318 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
@@ -124,3 +124,11 @@ TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_entry_value_mem) {
       {DW_OP_entry_value, 0x02, DW_OP_breg13, 0x10, DW_OP_stack_value},
       "entry([SP+16])");
 }
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_nop) {
+  TestExprPrinter({DW_OP_nop}, "<stack of size 0, expected 1>");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_nop_OP_reg) {
+  TestExprPrinter({DW_OP_nop, DW_OP_reg0}, "R0");
+}


        


More information about the llvm-commits mailing list