Spanification: Add regression tests about span frontier.
Add a useful tests that was missing and that could have detected a
problem in a patchset of:
https://chromium-review.googlesource.com/c/chromium/src/+/6190594
Bug: 356643982
Change-Id: I6bec89a512383bf3a514a9d227f6f90dbbf1e870
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6196965
Reviewed-by: Ali Hijazi <ahijazi@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Stephen Nusko <nuskos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1411507}
diff --git a/tools/clang/spanify/tests/span-frontier-basic-expected.cc b/tools/clang/spanify/tests/span-frontier-basic-expected.cc
new file mode 100644
index 0000000..400f8ad2
--- /dev/null
+++ b/tools/clang/spanify/tests/span-frontier-basic-expected.cc
@@ -0,0 +1,27 @@
+// Copyright 2025 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "base/containers/span.h"
+
+// Test the frontier change are applied correctly. Below, there are 3 kinds of
+// frontiers, but only 1 of them is spanified.
+// ┌──────────────────┐
+// │spanified_2 │
+// └▲────────────────▲┘
+// ┌───────┴───────┐┌───────┴───────┐
+// │not_spanified_2││spanified_1 (*)│ (* = buffer usage)
+// └▲──────────────┘└───────────────┘
+// ┌┴──────────────┐
+// │not_spanified_1│
+// └───────────────┘
+void test_frontier_basic() {
+ std::vector<int> buf(5, 5);
+ base::span<int> spanified_2 = buf;
+ base::span<int> spanified_1 = spanified_2; // Expect: frontier not applied.
+ int* not_spanified_2 = spanified_2.data(); // Expect: frontier applied
+ int* not_spanified_1 = not_spanified_2; // Expect: frontier not applied.
+ spanified_1[0] = 0;
+}
diff --git a/tools/clang/spanify/tests/span-frontier-basic-original.cc b/tools/clang/spanify/tests/span-frontier-basic-original.cc
new file mode 100644
index 0000000..72c4d0d
--- /dev/null
+++ b/tools/clang/spanify/tests/span-frontier-basic-original.cc
@@ -0,0 +1,25 @@
+// Copyright 2025 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+// Test the frontier change are applied correctly. Below, there are 3 kinds of
+// frontiers, but only 1 of them is spanified.
+// ┌──────────────────┐
+// │spanified_2 │
+// └▲────────────────▲┘
+// ┌───────┴───────┐┌───────┴───────┐
+// │not_spanified_2││spanified_1 (*)│ (* = buffer usage)
+// └▲──────────────┘└───────────────┘
+// ┌┴──────────────┐
+// │not_spanified_1│
+// └───────────────┘
+void test_frontier_basic() {
+ std::vector<int> buf(5, 5);
+ int* spanified_2 = buf.data();
+ int* spanified_1 = spanified_2; // Expect: frontier not applied.
+ int* not_spanified_2 = spanified_2; // Expect: frontier applied
+ int* not_spanified_1 = not_spanified_2; // Expect: frontier not applied.
+ spanified_1[0] = 0;
+}