aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/libclang/LibclangTest.cpp
diff options
context:
space:
mode:
authorLuca Di Sera <disera.luca@gmail.com>2022-08-29 08:16:18 -0400
committerAaron Ballman <aaron@aaronballman.com>2022-08-29 08:16:18 -0400
commit123062ec2f3e45bb1614a63bcb79c22527d9b914 (patch)
tree1c327313706f38d71d0a1c45d7ca4d17e39f4b43 /clang/unittests/libclang/LibclangTest.cpp
parentfe09cee34a6572f06bd3f230d1f14337ecab34b9 (diff)
downloadllvm-123062ec2f3e45bb1614a63bcb79c22527d9b914.zip
llvm-123062ec2f3e45bb1614a63bcb79c22527d9b914.tar.gz
llvm-123062ec2f3e45bb1614a63bcb79c22527d9b914.tar.bz2
Expose QualType::getUnqualifiedType in libclang
The method is now wrapped by clang_getUnqualifiedType. A declaration for clang_getUnqualifiedType was added to clang-c/Index.h to expose it to user of the library. An implementation for clang_getUnqualifiedType was introduced in CXType.cpp that wraps the equivalent method of the underlying QualType of a CXType. An export symbol was added to libclang.map under the new version entry LLVM_16. A test was added to LibclangTest.cpp that tests the removal of qualifiers for some CXTypes. Differential Revision: https://reviews.llvm.org/D132749
Diffstat (limited to 'clang/unittests/libclang/LibclangTest.cpp')
-rw-r--r--clang/unittests/libclang/LibclangTest.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index fc3ad43..e608485 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -843,6 +843,54 @@ TEST_F(LibclangParseTest, clang_Cursor_hasVarDeclExternalStorageTrue) {
},
nullptr);
}
+
+TEST_F(LibclangParseTest, clang_getUnqualifiedTypeRemovesQualifiers) {
+ std::string Header = "header.h";
+ WriteFile(Header, "void foo1(const int);\n"
+ "void foo2(volatile int);\n"
+ "void foo3(const volatile int);\n"
+ "void foo4(int* const);\n"
+ "void foo5(int* volatile);\n"
+ "void foo6(int* restrict);\n"
+ "void foo7(int* const volatile);\n"
+ "void foo8(int* volatile restrict);\n"
+ "void foo9(int* const restrict);\n"
+ "void foo10(int* const volatile restrict);\n");
+
+ auto is_qualified = [](CXType type) -> bool {
+ return clang_isConstQualifiedType(type) ||
+ clang_isVolatileQualifiedType(type) ||
+ clang_isRestrictQualifiedType(type);
+ };
+
+ auto from_CXString = [](CXString cx_string) -> std::string {
+ std::string string{clang_getCString(cx_string)};
+
+ clang_disposeString(cx_string);
+
+ return string;
+ };
+
+ ClangTU = clang_parseTranslationUnit(Index, Header.c_str(), nullptr, 0,
+ nullptr, 0, TUFlags);
+
+ Traverse([&is_qualified, &from_CXString](CXCursor cursor, CXCursor) {
+ if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
+ CXType arg_type = clang_getArgType(clang_getCursorType(cursor), 0);
+ EXPECT_TRUE(is_qualified(arg_type))
+ << "Input data '" << from_CXString(clang_getCursorSpelling(cursor))
+ << "' first argument does not have a qualified type.";
+
+ CXType unqualified_arg_type = clang_getUnqualifiedType(arg_type);
+ EXPECT_FALSE(is_qualified(unqualified_arg_type))
+ << "The type '" << from_CXString(clang_getTypeSpelling(arg_type))
+ << "' was not unqualified after a call to clang_getUnqualifiedType.";
+ }
+
+ return CXChildVisit_Continue;
+ });
+}
+
class LibclangRewriteTest : public LibclangParseTest {
public:
CXRewriter Rew = nullptr;