Skip to content

Add IsRestrictQualifiedType & GetNonRestrictQualifiedType functions #579

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Vipul-Cariappa
Copy link
Collaborator

Description

Example int *__restrict x

Fixes # (issue)

Helps fix a test case in cppyy.

Type of change

Please tick all options which are relevant.

  • Bug fix
  • New feature
  • Requires documentation updates

Testing

Added necessary tests.

Checklist

  • I have read the contribution guide recently

NonRestrictType.removeLocalRestrict();
return NonRestrictType.getAsOpaquePtr();
}
return nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not just return the type as-is if it is not restrict qualified?

Suggested change
return nullptr;
return type;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, LGTM!

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -1657,6 +1657,25 @@ namespace Cpp {
return QT.getCanonicalType().getAsOpaquePtr();
}

bool IsRestrictQualifiedType(TCppType_t type) {
if (!type)
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]

Suggested change
return 0;
return false;


TCppType_t GetNonRestrictQualifiedType(TCppType_t type) {
if (!type)
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use nullptr [modernize-use-nullptr]

Suggested change
return 0;
return nullptr;

@@ -605,3 +605,21 @@ TEST(TypeReflectionTest, IsFunctionPointerType) {
EXPECT_FALSE(
Cpp::IsFunctionPointerType(Cpp::GetVariableType(Cpp::GetNamed("i"))));
}

TEST(TypeReflectionTest, RestrictQualifiedType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'TEST' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

Suggested change
TEST(TypeReflectionTest, RestrictQualifiedType) {
TESTstatic (TypeReflectionTest, RestrictQualifiedType) {

Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 76.46%. Comparing base (951775f) to head (13e2cbd).

Files with missing lines Patch % Lines
lib/Interpreter/CppInterOp.cpp 90.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #579      +/-   ##
==========================================
+ Coverage   76.43%   76.46%   +0.03%     
==========================================
  Files           9        9              
  Lines        3666     3676      +10     
==========================================
+ Hits         2802     2811       +9     
- Misses        864      865       +1     
Files with missing lines Coverage Δ
include/clang/Interpreter/CppInterOp.h 96.29% <ø> (ø)
lib/Interpreter/CppInterOp.cpp 84.36% <90.00%> (+0.02%) ⬆️
Files with missing lines Coverage Δ
include/clang/Interpreter/CppInterOp.h 96.29% <ø> (ø)
lib/Interpreter/CppInterOp.cpp 84.36% <90.00%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -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 GetNonRestrictQualifiedType(TCppType_t type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CPPINTEROP_API TCppType_t GetNonRestrictQualifiedType(TCppType_t type);
CPPINTEROP_API TCppType_t GetNonRestrictType(TCppType_t type);

CPPINTEROP_API TCppType_t GetNonRestrictQualifiedType(TCppType_t type);

/// check if the type is restrict qualified i.e. __restrict
CPPINTEROP_API bool IsRestrictQualifiedType(TCppType_t type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CPPINTEROP_API bool IsRestrictQualifiedType(TCppType_t type);
CPPINTEROP_API bool IsRestrictType(TCppType_t type);

@mcbarton
Copy link
Collaborator

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 76.41%. Comparing base (28ba16e) to head (48734c6).

Files with missing lines Patch % Lines
lib/Interpreter/CppInterOp.cpp 85.71% 2 Missing ⚠️
Additional details and impacted files
🚀 New features to boost your workflow:

Can you create a test/modify an existing one such that the tests cover 100% of the patch?

@Vipul-Cariappa Vipul-Cariappa force-pushed the dev/restrict-type branch 2 times, most recently from 554d75b to 13e2cbd Compare May 23, 2025 09:02
NonRestrictType.removeLocalRestrict();
return NonRestrictType.getAsOpaquePtr();
}
return type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make codecov happy here?

Copy link
Contributor

@vgvassilev vgvassilev May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a generic interface for the cvr types. Something like:

bool HasTypeQualifier(Quals::Restrict & Quals::Const & Quals::Volatile) { ... }
bool StripTypeQualifier(...) { ... return true;/if something was really stripped/}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That can be done.

enum Qual { Restrict = 0b01, Const = 0b010, Volatile = 0b0100 };

bool HasTypeQualifier(TCppType_t, enum Qual) {
    ...
}

TCppType RemoveTypeQualifier(TCppType_t, enum Qual) {
    ...
}

The enum can be simply xored to combine different qualifiers.

@vgvassilev, Is this approach good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense. The enum should be const, volatile, restrict to follow the CVR terminology.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at #594

@Vipul-Cariappa
Copy link
Collaborator Author

The GitHub Actions are flaky today. Some are failing at the checkout step, or even before.

@vgvassilev
Copy link
Contributor

The GitHub Actions are flaky today. Some are failing at the checkout step, or even before.

Yes: https://www.githubstatus.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants