[llvm-branch-commits] [clang] [SSAF] Remove UnsafeBufferUsageTest.h (PR #195201)
Ziqing Luo via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Apr 30 17:07:19 PDT 2026
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/195201
The idea is that we do not want to have test-only functionality in any interface.
We have lit tests covering the removed unit test.
>From 192f092594a385b356e5ac9f679ff5d252b861ed Mon Sep 17 00:00:00 2001
From: Ziqing Luo <ziqing_luo at apple.com>
Date: Thu, 30 Apr 2026 17:01:25 -0700
Subject: [PATCH] [SSAF] Remove UnsafeBufferUsageTest.h
The idea is that we do not want to have test-only functionality in any
interface.
---
.../UnsafeBufferUsage/UnsafeBufferUsageTest.h | 29 ------------
.../UnsafeBufferUsageFormat.cpp | 23 ---------
.../UnsafeBufferUsageTest.cpp | 47 -------------------
3 files changed, 99 deletions(-)
delete mode 100644 clang/include/clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.h
diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.h b/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.h
deleted file mode 100644
index 6a2d1161246f2..0000000000000
--- a/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- UnsafeBufferUsageTest.h ----------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Functions and data structures that help UnsafeBufferUsage unit tests.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_UNSAFEBUFFERUSAGE_UNSAFEBUFFERUSAGETEST_H
-#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_UNSAFEBUFFERUSAGE_UNSAFEBUFFERUSAGETEST_H
-
-#include "clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsage.h"
-#include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/EntitySummary.h"
-#include "llvm/Support/Error.h"
-
-namespace clang::ssaf {
-
-llvm::Expected<std::unique_ptr<EntitySummary>> serializeDeserializeRoundTrip(
- const UnsafeBufferUsageEntitySummary &S,
- std::function<uint64_t(EntityId)> IdToIntFn,
- std::function<llvm::Expected<EntityId>(uint64_t)> IdFromIntFn);
-
-} // namespace clang::ssaf
-
-#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_UNSAFEBUFFERUSAGE_UNSAFEBUFFERUSAGETEST_H
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageFormat.cpp b/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageFormat.cpp
index ce1ef0b3ba691..dc686c416ac0c 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageFormat.cpp
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageFormat.cpp
@@ -10,7 +10,6 @@
#include "clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h"
#include "clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevelFormat.h"
#include "clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsage.h"
-#include "clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.h"
#include "clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/JSON.h"
@@ -84,25 +83,3 @@ static llvm::Registry<JSONFormat::FormatInfo>::Add<
// NOLINTNEXTLINE(misc-use-internal-linkage)
volatile int UnsafeBufferUsageSSAFJSONFormatAnchorSource = 0;
-
-// For unit test:
-llvm::Expected<std::unique_ptr<EntitySummary>>
-ssaf::serializeDeserializeRoundTrip(
- const UnsafeBufferUsageEntitySummary &S,
- std::function<uint64_t(EntityId)> IdToIntFn,
- std::function<llvm::Expected<EntityId>(uint64_t)> IdFromIntFn) {
-
- auto IdToJson = [&IdToIntFn](EntityId Id) -> Object {
- return Object({{"@", IdToIntFn(Id)}});
- };
- auto IdFromJson =
- [&IdFromIntFn](const Object &O) -> llvm::Expected<EntityId> {
- const auto *Int = O.get("@");
-
- if (Int && Int->getAsUINT64())
- return IdFromIntFn(*Int->getAsUINT64());
- return llvm::createStringError("failed to get EntityId from Object");
- };
-
- return deserializeImpl(serialize(S, IdToJson), IdFromJson);
-}
diff --git a/clang/unittests/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.cpp b/clang/unittests/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.cpp
index 465488357e20e..4c51214253cef 100644
--- a/clang/unittests/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.cpp
+++ b/clang/unittests/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.cpp
@@ -12,7 +12,6 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h"
-#include "clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageTest.h"
#include "clang/ScalableStaticAnalysisFramework/Core/ASTEntityMapping.h"
#include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityId.h"
#include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityIdTable.h"
@@ -188,52 +187,6 @@ TEST_F(UnsafeBufferUsageTest, UnsafeBufferUsageEntityPointerLevelSetTest) {
EXPECT_THAT(getSubsetOf(Set, E3), UnorderedElementsAre(P5));
}
-//////////////////////////////////////////////////////////////
-// (De-)Serialization Tests //
-//////////////////////////////////////////////////////////////
-
-TEST_F(UnsafeBufferUsageTest, UnsafeBufferUsageSerializeTest) {
- ASSERT_TRUE(setUpTest(R"cpp(
- void foo(int ***p, int ****q, int x) {
- p[5][5][5];
- q[5][5][5][5];
- }
- )cpp"));
- const auto *Sum = getEntitySummary("foo");
- ASSERT_NE(Sum, nullptr);
- EXPECT_EQ(*Sum, makeSet(__LINE__, {{"p", 1U},
- {"p", 2U},
- {"p", 3U},
- {"q", 1U},
- {"q", 2U},
- {"q", 3U},
- {"q", 4U}}));
-
- std::function<uint64_t(EntityId)> IdToIntFn = [](EntityId Id) -> uint64_t {
- return getIndex(Id);
- };
- std::function<llvm::Expected<EntityId>(uint64_t)> IdFromIntFn =
- [this](uint64_t Int) -> llvm::Expected<EntityId> {
- std::optional<EntityId> Result = std::nullopt;
-
- getIdTable(TUSum).forEach([&Int, &Result](const EntityName &, EntityId Id) {
- if (getIndex(Id) == Int)
- Result = Id;
- });
- if (Result)
- return *Result;
- return llvm::createStringError("failed to convert %d to an EntityId", Int);
- };
-
- auto RoundTripResult =
- serializeDeserializeRoundTrip(*Sum, IdToIntFn, IdFromIntFn);
-
- EXPECT_THAT_ERROR(RoundTripResult.takeError(), llvm::Succeeded());
- ASSERT_NE(*RoundTripResult, nullptr);
- EXPECT_EQ(*Sum, *static_cast<const UnsafeBufferUsageEntitySummary *>(
- RoundTripResult->get()));
-}
-
//////////////////////////////////////////////////////////////
// Extractor Tests //
//////////////////////////////////////////////////////////////
More information about the llvm-branch-commits
mailing list