mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-13 14:47:00 +00:00
b161c80b89
Fixes the bot: http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/15192 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280116 91177308-0d34-0410-b5e6-96231b3b80d8
49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
//===- unittests/IR/ModuleTest.cpp - Module unit tests --------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
bool sortByName(const GlobalVariable &L, const GlobalVariable &R) {
|
|
return L.getName() < R.getName();
|
|
}
|
|
|
|
bool sortByNameReverse(const GlobalVariable &L, const GlobalVariable &R) {
|
|
return sortByName(R, L);
|
|
}
|
|
|
|
TEST(ModuleTest, sortGlobalsByName) {
|
|
LLVMContext Context;
|
|
for (auto compare : {&sortByName, &sortByNameReverse}) {
|
|
Module M("M", Context);
|
|
Type *T = Type::getInt8Ty(Context);
|
|
GlobalValue::LinkageTypes L = GlobalValue::ExternalLinkage;
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "A");
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "F");
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "G");
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "E");
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "B");
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "H");
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "C");
|
|
(void)new GlobalVariable(M, T, false, L, nullptr, "D");
|
|
|
|
// Sort the globals by name.
|
|
EXPECT_FALSE(std::is_sorted(M.global_begin(), M.global_end(), compare));
|
|
M.getGlobalList().sort(compare);
|
|
EXPECT_TRUE(std::is_sorted(M.global_begin(), M.global_end(), compare));
|
|
}
|
|
}
|
|
|
|
} // end namespace
|