[llvm] [libDebugInfo] Prevent infinite recursion in DWARFDie::getTypeSize() (PR #74681)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 09:22:40 PST 2023


================
@@ -284,7 +285,9 @@ class DWARFDie {
   /// \param PointerSize the pointer size of the containing CU.
   /// \returns if this is a type DIE, or this DIE contains a DW_AT_type, returns
   /// the size of the type.
-  std::optional<uint64_t> getTypeSize(uint64_t PointerSize);
+  std::optional<uint64_t>
+  getTypeSize(uint64_t PointerSize,
+              llvm::SmallPtrSetImpl<const DWARFDebugInfoEntry *> &Visited);
----------------
felipepiovezan wrote:

FWIW I kind of agree with @pogo59 , this is exposing an implementation detail to the users of this call.
The more general way of handling this would be to do one of two things:

1. Keep the interface as before, but change the implementation to be iterative and have the set be defined inside the implementation.
2. Keep the interface as before, and keep the implementation recursive, but rename the old implementation to  an `impl` method that takes the set as a parameter, and make the implementation of the "normal" method define the set and pass it to the impl method.

Both of those will keep callers unchanged.

https://github.com/llvm/llvm-project/pull/74681


More information about the llvm-commits mailing list