diff --git a/include/clang/Interpreter/CppInterOp.h b/include/clang/Interpreter/CppInterOp.h index 7d1fdb12a..1b4fbaa22 100644 --- a/include/clang/Interpreter/CppInterOp.h +++ b/include/clang/Interpreter/CppInterOp.h @@ -546,6 +546,12 @@ namespace Cpp { /// out of it. CPPINTEROP_API TCppType_t GetCanonicalType(TCppType_t type); + /// Get non restrict qualified version of the given type + CPPINTEROP_API TCppType_t GetNonRestrictType(TCppType_t type); + + /// check if the type is restrict qualified i.e. __restrict + CPPINTEROP_API bool IsRestrictType(TCppType_t type); + /// Used to either get the built-in type of the provided string, or /// use the name to lookup the actual type. CPPINTEROP_API TCppType_t GetType(const std::string& type); diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index 1710b91b6..723ad8fe9 100755 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -1657,6 +1657,21 @@ namespace Cpp { return QT.getCanonicalType().getAsOpaquePtr(); } + bool IsRestrictType(TCppType_t type) { + QualType QT = QualType::getFromOpaquePtr(type); + return QT.isRestrictQualified(); + } + + TCppType_t GetNonRestrictType(TCppType_t type) { + QualType QT = QualType::getFromOpaquePtr(type); + if (QT.isRestrictQualified()) { + QualType NonRestrictType(QT); + NonRestrictType.removeLocalRestrict(); + return NonRestrictType.getAsOpaquePtr(); + } + return type; + } + // Internal functions that are not needed outside the library are // encompassed in an anonymous namespace as follows. This function converts // from a string to the actual type. It is used in the GetType() function. diff --git a/unittests/CppInterOp/TypeReflectionTest.cpp b/unittests/CppInterOp/TypeReflectionTest.cpp index a3e482596..5ffb18fbd 100644 --- a/unittests/CppInterOp/TypeReflectionTest.cpp +++ b/unittests/CppInterOp/TypeReflectionTest.cpp @@ -610,3 +610,22 @@ TEST(TypeReflectionTest, IsFunctionPointerType) { EXPECT_FALSE( Cpp::IsFunctionPointerType(Cpp::GetVariableType(Cpp::GetNamed("i")))); } + +TEST(TypeReflectionTest, RestrictQualifiedType) { + Cpp::CreateInterpreter(); + Cpp::Declare(R"( + int *x; + int *__restrict y; + )"); + + Cpp::TCppType_t x = Cpp::GetVariableType(Cpp::GetNamed("x")); + Cpp::TCppType_t y = Cpp::GetVariableType(Cpp::GetNamed("y")); + + EXPECT_FALSE(Cpp::IsRestrictType(x)); + EXPECT_TRUE(Cpp::IsRestrictType(y)); + + EXPECT_EQ(Cpp::GetCanonicalType(Cpp::GetNonRestrictType(y)), + Cpp::GetCanonicalType(x)); + EXPECT_EQ(Cpp::GetCanonicalType(Cpp::GetNonRestrictType(x)), + Cpp::GetCanonicalType(x)); +}