1 #include "../lib/Basic/BuiltinTargetFeatures.h" 2 #include "gtest/gtest.h" 3 4 using namespace llvm; 5 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 clang::Builtin::TargetFeatures TF(SM); 15 return TF.hasRequiredFeatures(BuiltinFeatures); 16 }; 17 // Make sure the basic function ',' and '|' works correctly 18 ASSERT_FALSE(doCheck("A,B,C,D", "A")); 19 ASSERT_TRUE(doCheck("A,B,C,D", "A,B,C,D")); 20 ASSERT_TRUE(doCheck("A|B", "A")); 21 ASSERT_FALSE(doCheck("A|B", "C")); 22 23 // Make sure the ',' has higher priority. 24 ASSERT_TRUE(doCheck("A|B,C|D", "A")); 25 26 // Make sure the parentheses do change the priority of '|'. 27 ASSERT_FALSE(doCheck("(A|B),(C|D)", "A")); 28 ASSERT_TRUE(doCheck("(A|B),(C|D)", "A,C")); 29 30 // Make sure the combination in parentheses works correctly. 31 ASSERT_FALSE(doCheck("(A,B|C),D", "A,C")); 32 ASSERT_FALSE(doCheck("(A,B|C),D", "A,D")); 33 ASSERT_TRUE(doCheck("(A,B|C),D", "C,D")); 34 ASSERT_TRUE(doCheck("(A,B|C),D", "A,B,D")); 35 36 // Make sure nested parentheses works correctly. 37 ASSERT_FALSE(doCheck("(A,(B|C)),D", "C,D")); 38 ASSERT_TRUE(doCheck("(A,(B|C)),D", "A,C,D")); 39 } 40