Skip to content
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

Minimal example of a bug from cppyy #365

Conversation

Vipul-Cariappa
Copy link
Collaborator

That needs to be fixed at CppInterOp
reference: look at comments at compiler-research/cppyy-backend#116


I have written a test case that is a minimal example of a failing test at cppyy (suspected).
I am not sure how to fix this. More experienced people here could take a look at it.

That needs to be fixed at CppInterOp
reference: look at comments at compiler-research/cppyy-backend#116
Comment on lines +171 to +172
EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetVariableType(datamembers[0])),
"my_namespace::Container");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The assertion fails here with

"Container" != "my_namespace::Container"

I need the fully qualified type name.

Copy link
Contributor

@vgvassilev vgvassilev Dec 3, 2024

Choose a reason for hiding this comment

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

Wouldn't GetQualifiedName or GetQualifiedCompleteName help?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well the following diff in GetVariableType passed the above test for me. I may be wrong due to lack of context.

--- a/lib/Interpreter/CppInterOp.cpp
+++ b/lib/Interpreter/CppInterOp.cpp
@@ -1216,7 +1216,10 @@ namespace Cpp {
     auto D = (Decl *) var;
 
     if (auto DD = llvm::dyn_cast_or_null<DeclaratorDecl>(D)) {
-      return DD->getType().getAsOpaquePtr();
+      QualType QT = DD->getType();
+
+      // Ensure the type includes the namespace.
+      QT = QT.getCanonicalType();
+      return QT.getAsOpaquePtr();
     }

Copy link
Contributor

Choose a reason for hiding this comment

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

If the change makes the test pass that's a good sign.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, let me run all the tests and get back to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vgvassilev I ran all the tests now, all tests pass but the typedef int I; failed in TypeReflectionTest.cpp, so changing the above diff makes all tests pass. What is your opinion here ?

TCppType_t GetVariableType(TCppScope_t var)
{
    auto D = (Decl *) var;

    if (auto DD = llvm::dyn_cast_or_null<DeclaratorDecl>(D)) {
        QualType QT = DD->getType();

        // Check if the type is a typedef type
        if (QT->isTypedefNameType()) {
            return QT.getAsOpaquePtr();
        }

        // Else, return the canonical type
        QT = QT.getCanonicalType();
        return QT.getAsOpaquePtr();
    }

    return 0;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@faze-geek, I did not test your changes locally. But if all existing tests and the test from this PR pass, you can open a PR of this branch (create a new branch from this branch). I will take a look at it. We may extend the test with other combinations.

Thanks for looking into this. 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure ! Will make the changes soon.

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

if (llvm::sys::RunningOnValgrind())
GTEST_SKIP() << "XFAIL due to Valgrind report";

std::string code = R"(
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::string" is directly included [misc-include-cleaner]

unittests/CppInterOp/VariableReflectionTest.cpp:6:

+ #include <string>

@mcbarton
Copy link
Collaborator

@Vipul-Cariappa has this bug been fixed now?

@faze-geek faze-geek mentioned this pull request Dec 19, 2024
4 tasks
@Vipul-Cariappa Vipul-Cariappa deleted the dev/GetDatamemberTypeAsString branch December 19, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants