brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 8fdb3d6 Raw
39 lines · cpp
1#include "clang/Basic/Builtins.h"2#include "gtest/gtest.h"3 4using namespace llvm;5 6// These tests are to Check whether CodeGen::TargetFeatures works correctly.7TEST(CheckTargetFeaturesTest, checkBuiltinFeatures) {8  auto doCheck = [](StringRef BuiltinFeatures, StringRef FuncFeatures) {9    SmallVector<StringRef, 1> Features;10    FuncFeatures.split(Features, ',');11    StringMap<bool> SM;12    for (StringRef F : Features)13      SM.insert(std::make_pair(F, true));14    return clang::Builtin::evaluateRequiredTargetFeatures(BuiltinFeatures, SM);15  };16  // Make sure the basic function ',' and '|' works correctly17  ASSERT_FALSE(doCheck("A,B,C,D", "A"));18  ASSERT_TRUE(doCheck("A,B,C,D", "A,B,C,D"));19  ASSERT_TRUE(doCheck("A|B", "A"));20  ASSERT_FALSE(doCheck("A|B", "C"));21 22  // Make sure the ',' has higher priority.23  ASSERT_TRUE(doCheck("A|B,C|D", "A"));24 25  // Make sure the parentheses do change the priority of '|'.26  ASSERT_FALSE(doCheck("(A|B),(C|D)", "A"));27  ASSERT_TRUE(doCheck("(A|B),(C|D)", "A,C"));28 29  // Make sure the combination in parentheses works correctly.30  ASSERT_FALSE(doCheck("(A,B|C),D", "A,C"));31  ASSERT_FALSE(doCheck("(A,B|C),D", "A,D"));32  ASSERT_TRUE(doCheck("(A,B|C),D", "C,D"));33  ASSERT_TRUE(doCheck("(A,B|C),D", "A,B,D"));34 35  // Make sure nested parentheses works correctly.36  ASSERT_FALSE(doCheck("(A,(B|C)),D", "C,D"));37  ASSERT_TRUE(doCheck("(A,(B|C)),D", "A,C,D"));38}39