Skip to content

Commit b3558de

Browse files
author
Vladislav Aranov
committed
[clang][test] Improve unit tests for Fixed point AST matchers.
We have AST matchers for fixed point float numbers since commits 789215d and ff91206. However in those commits the unit tests were not added. Amending the test suit.
1 parent 5fbd065 commit b3558de

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,49 @@ TEST_P(ASTMatchersTest, FloatLiteral) {
10171017
notMatches("double i = 5.0;", floatLiteral(equals(llvm::APFloat(6.0)))));
10181018
}
10191019

1020+
TEST_P(ASTMatchersTest, FixedPointLiterals) {
1021+
StatementMatcher HasFixedPointLiteral = fixedPointLiteral();
1022+
EXPECT_TRUE(matchesWithFixedpoint("_Fract i = 0.25r;", HasFixedPointLiteral));
1023+
EXPECT_TRUE(
1024+
matchesWithFixedpoint("_Fract i = 0.25hr;", HasFixedPointLiteral));
1025+
EXPECT_TRUE(
1026+
matchesWithFixedpoint("_Fract i = 0.25uhr;", HasFixedPointLiteral));
1027+
EXPECT_TRUE(
1028+
matchesWithFixedpoint("_Fract i = 0.25ur;", HasFixedPointLiteral));
1029+
EXPECT_TRUE(
1030+
matchesWithFixedpoint("_Fract i = 0.25lr;", HasFixedPointLiteral));
1031+
EXPECT_TRUE(
1032+
matchesWithFixedpoint("_Fract i = 0.25ulr;", HasFixedPointLiteral));
1033+
EXPECT_TRUE(matchesWithFixedpoint("_Accum i = 1.25k;", HasFixedPointLiteral));
1034+
EXPECT_TRUE(
1035+
matchesWithFixedpoint("_Accum i = 1.25hk;", HasFixedPointLiteral));
1036+
EXPECT_TRUE(
1037+
matchesWithFixedpoint("_Accum i = 1.25uhk;", HasFixedPointLiteral));
1038+
EXPECT_TRUE(
1039+
matchesWithFixedpoint("_Accum i = 1.25uk;", HasFixedPointLiteral));
1040+
EXPECT_TRUE(
1041+
matchesWithFixedpoint("_Accum i = 1.25lk;", HasFixedPointLiteral));
1042+
EXPECT_TRUE(
1043+
matchesWithFixedpoint("_Accum i = 1.25ulk;", HasFixedPointLiteral));
1044+
EXPECT_TRUE(matchesWithFixedpoint("_Accum decexp1 = 1.575e1k;",
1045+
HasFixedPointLiteral));
1046+
EXPECT_TRUE(
1047+
matchesWithFixedpoint("_Accum hex = 0x1.25fp2k;", HasFixedPointLiteral));
1048+
EXPECT_TRUE(matchesWithFixedpoint("_Sat long _Fract i = 0.25r;",
1049+
HasFixedPointLiteral));
1050+
EXPECT_TRUE(matchesWithFixedpoint("_Sat short _Accum i = 256.0k;",
1051+
HasFixedPointLiteral));
1052+
1053+
EXPECT_TRUE(
1054+
notMatchesWithFixedpoint("short _Accum i = 2u;", HasFixedPointLiteral));
1055+
EXPECT_TRUE(
1056+
notMatchesWithFixedpoint("short _Accum i = 2;", HasFixedPointLiteral));
1057+
EXPECT_TRUE(
1058+
notMatchesWithFixedpoint("_Accum i = 1.25;", HasFixedPointLiteral));
1059+
EXPECT_TRUE(notMatchesWithFixedpoint("_Accum i = 1.25 * 4.5i;",
1060+
HasFixedPointLiteral));
1061+
}
1062+
10201063
TEST_P(ASTMatchersTest, CXXNullPtrLiteralExpr) {
10211064
if (!GetParam().isCXX11OrLater()) {
10221065
return;

clang/unittests/ASTMatchers/ASTMatchersTest.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,19 @@ testing::AssertionResult notMatchesWithOpenMP51(const Twine &Code,
289289
{"-fopenmp=libomp", "-fopenmp-version=51"});
290290
}
291291

292+
template <typename T>
293+
testing::AssertionResult matchesWithFixedpoint(const std::string &Code,
294+
const T &AMatcher) {
295+
return matchesConditionally(Code, AMatcher, true, "-ffixed-point",
296+
FileContentMappings(), "input.c");
297+
}
298+
template <typename T>
299+
testing::AssertionResult notMatchesWithFixedpoint(const std::string &Code,
300+
const T &AMatcher) {
301+
return matchesConditionally(Code, AMatcher, false, "-ffixed-point",
302+
FileContentMappings(), "input.c");
303+
}
304+
292305
template <typename T>
293306
testing::AssertionResult matchAndVerifyResultConditionally(
294307
const Twine &Code, const T &AMatcher,

0 commit comments

Comments
 (0)