[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / unittests / CodeGen / CheckTargetFeaturesTest.cpp
blob8fdb3d66d8cf8350010374e7135b2847f29ade86
1 #include "clang/Basic/Builtins.h"
2 #include "gtest/gtest.h"
4 using namespace llvm;
6 // These tests are to Check whether CodeGen::TargetFeatures works correctly.
7 TEST(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);
16 // Make sure the basic function ',' and '|' works correctly
17 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"));
22 // Make sure the ',' has higher priority.
23 ASSERT_TRUE(doCheck("A|B,C|D", "A"));
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"));
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"));
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"));