[Lldb-commits] [lldb] c47df3e - [lldb][test] Make vector operator[] return T& to workaround Arm codegen issue

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 21 04:57:03 PDT 2024


Author: David Spickett
Date: 2024-10-21T11:54:54Z
New Revision: c47df3e8c8f47bab8a8302757c50710e0e1c43fb

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

LOG: [lldb][test] Make vector operator[] return T& to workaround Arm codegen issue

Since https://github.com/llvm/llvm-project/pull/109628 landed, this test
has been failing on 32-bit Arm.

This is due to a codegen problem (whether added or uncovered by the change,
not known) where the trap instruction is placed after the frame pointer
and link register are restored.

https://github.com/llvm/llvm-project/issues/113154

So the code was:
```
std::__1::vector<int>::operator[](unsigned int):
  sub sp, sp, #8
  str r0, [sp, #4]
  str r1, [sp]
  add sp, sp, #8
  .inst 0xe7ffdefe
  bx lr
```
When lldb saw the trap, the PC was inside operator[] but the frame
information actually pointed to g.

This bug only happens for leaf functions so adding a return type
works around it:
```
std::__1::vector<int>::operator[](unsigned int):
  push {r11, lr}
  mov r11, sp
  sub sp, sp, #8
  str r0, [sp, #4]
  str r1, [sp]
  mov sp, r11
  pop {r11, lr}
  .inst 0xe7ffdefe
  bx lr
```
(and operator[] should return T& anyway)

Now the PC location and frame information should match and the
test passes.

Added: 
    

Modified: 
    lldb/test/Shell/Recognizer/Inputs/verbose_trap-in-stl.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/Shell/Recognizer/Inputs/verbose_trap-in-stl.cpp b/lldb/test/Shell/Recognizer/Inputs/verbose_trap-in-stl.cpp
index 4f01827944e166..20db722ef105da 100644
--- a/lldb/test/Shell/Recognizer/Inputs/verbose_trap-in-stl.cpp
+++ b/lldb/test/Shell/Recognizer/Inputs/verbose_trap-in-stl.cpp
@@ -1,7 +1,7 @@
 namespace std {
 inline namespace __1 {
 template <typename T> struct vector {
-  void operator[](unsigned) { __builtin_verbose_trap("Bounds error", "out-of-bounds access"); }
+  T& operator[](unsigned) { __builtin_verbose_trap("Bounds error", "out-of-bounds access"); }
 };
 } // namespace __1
 } // namespace std


        


More information about the lldb-commits mailing list