-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][test] Improve unit tests for Fixed point AST matchers. #134398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: None (earnol) ChangesWe have AST matchers for fixed point float numbers since commits 789215d and Full diff: https://github.com/llvm/llvm-project/pull/134398.diff 2 Files Affected:
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 680e21840b7d3..60d0bbf42cf23 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1017,6 +1017,49 @@ TEST_P(ASTMatchersTest, FloatLiteral) {
notMatches("double i = 5.0;", floatLiteral(equals(llvm::APFloat(6.0)))));
}
+TEST_P(ASTMatchersTest, FixedPointLiterals) {
+ StatementMatcher HasFixedPointLiteral = fixedPointLiteral();
+ EXPECT_TRUE(matchesWithFixedpoint("_Fract i = 0.25r;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Fract i = 0.25hr;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Fract i = 0.25uhr;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Fract i = 0.25ur;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Fract i = 0.25lr;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Fract i = 0.25ulr;", HasFixedPointLiteral));
+ EXPECT_TRUE(matchesWithFixedpoint("_Accum i = 1.25k;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Accum i = 1.25hk;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Accum i = 1.25uhk;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Accum i = 1.25uk;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Accum i = 1.25lk;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Accum i = 1.25ulk;", HasFixedPointLiteral));
+ EXPECT_TRUE(matchesWithFixedpoint("_Accum decexp1 = 1.575e1k;",
+ HasFixedPointLiteral));
+ EXPECT_TRUE(
+ matchesWithFixedpoint("_Accum hex = 0x1.25fp2k;", HasFixedPointLiteral));
+ EXPECT_TRUE(matchesWithFixedpoint("_Sat long _Fract i = 0.25r;",
+ HasFixedPointLiteral));
+ EXPECT_TRUE(matchesWithFixedpoint("_Sat short _Accum i = 256.0k;",
+ HasFixedPointLiteral));
+
+ EXPECT_TRUE(
+ notMatchesWithFixedpoint("short _Accum i = 2u;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ notMatchesWithFixedpoint("short _Accum i = 2;", HasFixedPointLiteral));
+ EXPECT_TRUE(
+ notMatchesWithFixedpoint("_Accum i = 1.25;", HasFixedPointLiteral));
+ EXPECT_TRUE(notMatchesWithFixedpoint("_Accum i = 1.25 * 4.5i;",
+ HasFixedPointLiteral));
+}
+
TEST_P(ASTMatchersTest, CXXNullPtrLiteralExpr) {
if (!GetParam().isCXX11OrLater()) {
return;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index ad2f5f355621c..5f8bdf7ecc621 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -289,6 +289,17 @@ testing::AssertionResult notMatchesWithOpenMP51(const Twine &Code,
{"-fopenmp=libomp", "-fopenmp-version=51"});
}
+template <typename T>
+testing::AssertionResult matchesWithFixedpoint(const std::string &Code,
+ const T &AMatcher) {
+ return matchesConditionally(Code, AMatcher, true, "-ffixed-point", FileContentMappings(), "input.c");
+}
+template <typename T>
+testing::AssertionResult notMatchesWithFixedpoint(const std::string &Code,
+ const T &AMatcher) {
+ return matchesConditionally(Code, AMatcher, false, "-ffixed-point", FileContentMappings(), "input.c");
+}
+
template <typename T>
testing::AssertionResult matchAndVerifyResultConditionally(
const Twine &Code, const T &AMatcher,
|
203d77b
to
655a39e
Compare
Gentle ping! Requesting a review from the community, since a week had passed with no response. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/14518 Here is the relevant piece of the build log for the reference
|
…134398) 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 by adding missing tests. Co-authored-by: Vladislav Aranov <[email protected]>
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 by adding missing tests.