Files
TheRock/compiler/amd-llvm/llvm/unittests/IR/GlobalObjectTest.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

81 lines
2.4 KiB
C++

//===- GlobalObjectTest.cpp - Global object unit tests --------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "llvm/IR/GlobalObject.h"
#include "llvm/AsmParser/Parser.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/SourceMgr.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace {
using testing::Eq;
using testing::Optional;
using testing::StrEq;
static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
SMDiagnostic Err;
std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C);
if (!Mod)
Err.print("GlobalObjectTests", errs());
return Mod;
}
static LLVMContext C;
static std::unique_ptr<Module> M;
class GlobalObjectTest : public testing::Test {
public:
static void SetUpTestSuite() {
M = parseIR(C, R"(
@foo = global i32 3, !section_prefix !0
@bar = global i32 0
!0 = !{!"section_prefix", !"hot"}
)");
}
};
TEST_F(GlobalObjectTest, SectionPrefix) {
GlobalVariable *Foo = M->getGlobalVariable("foo");
// Initial section prefix is hot.
ASSERT_NE(Foo, nullptr);
ASSERT_THAT(Foo->getSectionPrefix(), Optional(StrEq("hot")));
// Test that set method returns false since existing section prefix is hot.
EXPECT_FALSE(Foo->setSectionPrefix("hot"));
// Set prefix from hot to unlikely.
Foo->setSectionPrefix("unlikely");
EXPECT_THAT(Foo->getSectionPrefix(), Optional(StrEq("unlikely")));
// Set prefix to empty is the same as clear.
Foo->setSectionPrefix("");
// Test that section prefix is cleared.
EXPECT_THAT(Foo->getSectionPrefix(), Eq(std::nullopt));
GlobalVariable *Bar = M->getGlobalVariable("bar");
// Initial section prefix is empty.
ASSERT_NE(Bar, nullptr);
ASSERT_THAT(Bar->getSectionPrefix(), Eq(std::nullopt));
// Test that set method returns false since Bar doesn't have prefix metadata.
EXPECT_FALSE(Bar->setSectionPrefix(""));
// Set from empty to hot.
EXPECT_TRUE(Bar->setSectionPrefix("hot"));
EXPECT_THAT(Bar->getSectionPrefix(), Optional(StrEq("hot")));
// Test that set method returns true and section prefix is cleared.
EXPECT_TRUE(Bar->setSectionPrefix(""));
EXPECT_THAT(Bar->getSectionPrefix(), Eq(std::nullopt));
}
} // namespace