brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · f0ed0e8 Raw
61 lines · cpp
1//===- llvm/unittest/CodeGen/TypeTraitsTest.cpp --------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/CodeGen/RDFRegisters.h"10#include "llvm/CodeGen/RegisterPressure.h"11#include "llvm/CodeGen/ScheduleDAG.h"12#include "llvm/CodeGen/SelectionDAGNodes.h"13#include "llvm/CodeGen/SlotIndexes.h"14#include "llvm/CodeGen/TargetPassConfig.h"15#include "gtest/gtest.h"16#include <functional>17#include <type_traits>18#include <utility>19 20using namespace llvm;21 22static_assert(std::is_trivially_copyable_v<PressureChange>,23              "trivially copyable");24static_assert(std::is_trivially_copyable_v<SDep>, "trivially copyable");25static_assert(std::is_trivially_copyable_v<SDValue>, "trivially copyable");26static_assert(std::is_trivially_copyable_v<SlotIndex>, "trivially copyable");27static_assert(std::is_trivially_copyable_v<IdentifyingPassPtr>,28              "trivially copyable");29 30// https://llvm.org/PR10516931// Verify that we won't accidently specialize std::less and std::equal_to in a32// wrong way.33// C++17 [namespace.std]/2, C++20/23 [namespace.std]/5:34//   A program may explicitly instantiate a template defined in the standard35//   library only if the declaration36//   - depends on the name of a user-defined type and37//   - the instantiation meets the standard library requirements for the38//   original template.39template <class Fn> constexpr bool CheckStdCmpRequirements() {40  // std::less and std::equal_to are literal, default constructible, and41  // copyable classes.42  Fn f1{};43  auto f2 = f1;44  auto f3 = std::move(f2);45  f2 = f3;46  f2 = std::move(f3);47 48  // Properties held on all known implementations, although not guaranteed by49  // the standard.50  static_assert(std::is_empty_v<Fn>);51  static_assert(std::is_trivially_default_constructible_v<Fn>);52  static_assert(std::is_trivially_copyable_v<Fn>);53 54  return true;55}56 57static_assert(CheckStdCmpRequirements<std::less<rdf::RegisterRef>>(),58              "same as the original template");59static_assert(CheckStdCmpRequirements<std::equal_to<rdf::RegisterRef>>(),60              "same as the original template");61