================
@@ -2527,6 +2527,83 @@ bool arePotentiallyOverlappingStringLiterals(const 
Pointer &LHS,
   return Shorter == Longer.take_front(Shorter.size());
 }
 
+static const MaterializeTemporaryExpr *
+getInitializerListBackingArray(const Pointer &Ptr) {
+  if (Ptr.isZero() || !Ptr.isBlockPointer() || Ptr.block()->isDynamic())
+    return nullptr;
+
+  const auto *MTE =
+      dyn_cast_or_null<MaterializeTemporaryExpr>(Ptr.getDeclDesc()->asExpr());
+  return IsInitializerListBackingArray(MTE) ? MTE : nullptr;
+}
+
+static bool getArrayIndex(const Pointer &Ptr, Pointer &Array, uint64_t &Index) 
{
+  if (Ptr.isZero() || !Ptr.isBlockPointer() || !Ptr.isArrayElement())
+    return false;
+
+  Pointer Expanded = Ptr.expand();
+  if (!Expanded.inArray())
+    return false;
+
+  Index = Expanded.isOnePastEnd() ? Expanded.getNumElems()
+                                  : static_cast<uint64_t>(Expanded.getIndex());
+  Array = Expanded.getArray();
+  return true;
+}
+
+bool arePotentiallyOverlappingInitListBackingArrays(InterpState &S,
----------------
yronglin wrote:

I have added more comments. It implements the address-comparison rejection rule 
from `[intro.object]/9` (CWG2765): given two pointers that both designate 
elements of `std::initializer_list` backing arrays, it returns `true` when the 
two backing arrays could be merged by the implementation — i.e., their contents 
agree on the overlapping region — in which case the comparison is unspecified 
and must be rejected in constant evaluation. It mirrors the AST-side helper of 
the same purpose in `ExprConstant.cpp`, including the conservative "missing 
element data ⇒ assume potential merge" default.


https://github.com/llvm/llvm-project/pull/197458
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to