Fix: Resolve inherited members through implicit UsingShadowDecls#1038
Fix: Resolve inherited members through implicit UsingShadowDecls#1038Krishna-13-cyber wants to merge 3 commits into
Conversation
| } | ||
|
|
||
|
|
||
| static clang::UsingShadowDecl *CreateInheritedUsingShadow( |
There was a problem hiding this comment.
warning: 'CreateInheritedUsingShadow' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]
| static clang::UsingShadowDecl *CreateInheritedUsingShadow( | |
| ; |
| } | ||
| } | ||
| if (FoundND) | ||
| return INTEROP_RETURN((TCppScope_t)(FoundND->getCanonicalDecl())); |
There was a problem hiding this comment.
warning: use of undeclared identifier 'TCppScope_t' [clang-diagnostic-error]
ndND)
^| // record contexts. Use unqualified lookup from a synthesized point | ||
| // inside the class to traverse base classes and find the member. | ||
| auto* ND2 = LookupUnqualified(getSema(), DName, Within); | ||
| if (ND2 && ND2 != (clang::NamedDecl*)-1) { |
There was a problem hiding this comment.
warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
hin);
^| // record contexts. Use unqualified lookup from a synthesized point | ||
| // inside the class to traverse base classes and find the member. | ||
| auto* ND2 = LookupUnqualified(getSema(), DName, Within); | ||
| if (ND2 && ND2 != (clang::NamedDecl*)-1) { |
There was a problem hiding this comment.
warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
hin);
^| auto* ND2 = LookupUnqualified(getSema(), DName, Within); | ||
| if (ND2 && ND2 != (clang::NamedDecl*)-1) { | ||
| if (auto* Shadow = CreateInheritedUsingShadow(RD, ND2)) | ||
| return INTEROP_RETURN((TCppScope_t)(Shadow->getCanonicalDecl())); |
There was a problem hiding this comment.
warning: use of undeclared identifier 'TCppScope_t' [clang-diagnostic-error]
ND2))
^| if (ND2 && ND2 != (clang::NamedDecl*)-1) { | ||
| if (auto* Shadow = CreateInheritedUsingShadow(RD, ND2)) | ||
| return INTEROP_RETURN((TCppScope_t)(Shadow->getCanonicalDecl())); | ||
| return INTEROP_RETURN((TCppScope_t)(ND2->getCanonicalDecl())); |
There was a problem hiding this comment.
warning: use of undeclared identifier 'TCppScope_t' [clang-diagnostic-error]
()));
^| return INTEROP_RETURN((TCppScope_t)(Shadow->getCanonicalDecl())); | ||
| return INTEROP_RETURN((TCppScope_t)(ND2->getCanonicalDecl())); | ||
| } | ||
| if (ND2 == (clang::NamedDecl*)-1) |
There was a problem hiding this comment.
warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
}
^| return INTEROP_RETURN((TCppScope_t)(Shadow->getCanonicalDecl())); | ||
| return INTEROP_RETURN((TCppScope_t)(ND2->getCanonicalDecl())); | ||
| } | ||
| if (ND2 == (clang::NamedDecl*)-1) |
There was a problem hiding this comment.
warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
}
^| }; | ||
| )"); | ||
|
|
||
| Cpp::TCppScope_t strt_S = Cpp::GetNamed("S", nullptr); |
There was a problem hiding this comment.
warning: no type named 'TCppScope_t' in namespace 'Cpp' [clang-diagnostic-error]
Cpp::TCppScope_t strt_S = Cpp::GetNamed("S", nullptr);
^| )"); | ||
|
|
||
| Cpp::TCppScope_t strt_S = Cpp::GetNamed("S", nullptr); | ||
| Cpp::TCppScope_t strt_S_Val = Cpp::GetNamed("Val", strt_S); |
There was a problem hiding this comment.
warning: no type named 'TCppScope_t' in namespace 'Cpp' [clang-diagnostic-error]
Cpp::TCppScope_t strt_S_Val = Cpp::GetNamed("Val", strt_S);
^|
|
||
| clang::ASTContext &C = Record->getASTContext(); | ||
| clang::DeclarationNameInfo NameInfo(Target->getDeclName(), | ||
| clang::SourceLocation()); |
There was a problem hiding this comment.
warning: use nullptr [modernize-use-nullptr]
| clang::SourceLocation()); | |
| = nullptr; |
| Record->addDecl(Shadow); | ||
|
|
||
| return Shadow; | ||
| } |
There was a problem hiding this comment.
warning: no header providing "CppInternal::utils::Lookup::Named" is directly included [misc-include-cleaner]
lib/CppInterOp/CppInterOp.cpp:10:
- #include "Unwrap.h"
+ #include "CppInterOpInterpreter.h"
+ #include "Unwrap.h"|
|
||
| return Shadow; | ||
| } | ||
|
|
There was a problem hiding this comment.
warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
hin);
^|
|
||
| return Shadow; | ||
| } | ||
|
|
There was a problem hiding this comment.
warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
hin);
^| if (auto* RD = llvm::dyn_cast<clang::CXXRecordDecl>(Within)) { | ||
| clang::DeclarationName DName = &getSema().Context.Idents.get(name); | ||
| auto Decls = RD->lookup(DName); | ||
| clang::NamedDecl* FoundND = nullptr; |
There was a problem hiding this comment.
warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
hin);
^| if (auto* RD = llvm::dyn_cast<clang::CXXRecordDecl>(Within)) { | ||
| clang::DeclarationName DName = &getSema().Context.Idents.get(name); | ||
| auto Decls = RD->lookup(DName); | ||
| clang::NamedDecl* FoundND = nullptr; |
There was a problem hiding this comment.
warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
hin);
^| } | ||
| if (FoundND) | ||
| return INTEROP_RETURN((FoundND->getCanonicalDecl())); | ||
|
|
There was a problem hiding this comment.
warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast]
DRef.
^|
|
||
| Cpp::TCppScope_t strt_S = Cpp::GetNamed("S", nullptr); | ||
| Cpp::TCppScope_t strt_S_Val = Cpp::GetNamed("Val", strt_S); | ||
| Cpp::TCppScope_t strt_S1 = Cpp::GetNamed("S1", nullptr); |
There was a problem hiding this comment.
warning: expected ';' after expression [clang-diagnostic-error]
| Cpp::TCppScope_t strt_S1 = Cpp::GetNamed("S1", nullptr); | |
| Cpp::TCppScope_t; strt_S1 = Cpp::GetNamed("S1", nullptr); |
|
|
||
| Cpp::TCppScope_t strt_S = Cpp::GetNamed("S", nullptr); | ||
| Cpp::TCppScope_t strt_S_Val = Cpp::GetNamed("Val", strt_S); | ||
| Cpp::TCppScope_t strt_S1 = Cpp::GetNamed("S1", nullptr); |
There was a problem hiding this comment.
warning: no member named 'TCppScope_t' in namespace 'Cpp' [clang-diagnostic-error]
Cpp::TCppScope_t strt_S1 = Cpp::GetNamed("S1", nullptr);
^|
|
||
| Cpp::TCppScope_t strt_S = Cpp::GetNamed("S", nullptr); | ||
| Cpp::TCppScope_t strt_S_Val = Cpp::GetNamed("Val", strt_S); | ||
| Cpp::TCppScope_t strt_S1 = Cpp::GetNamed("S1", nullptr); |
There was a problem hiding this comment.
warning: use of undeclared identifier 'strt_S1'; did you mean 'strt_S'? [clang-diagnostic-error]
| Cpp::TCppScope_t strt_S1 = Cpp::GetNamed("S1", nullptr); | |
| Cpp::TCppScope_t strt_S = Cpp::GetNamed("S1", nullptr); |
Additional context
unittests/CppInterOp/ScopeReflectionTest.cpp:715: 'strt_S' declared here
Cpp::TCppScope_t strt_S = Cpp::GetNamed("S", nullptr);
^
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1038 +/- ##
==========================================
+ Coverage 86.23% 86.44% +0.20%
==========================================
Files 21 23 +2
Lines 5369 5658 +289
==========================================
+ Hits 4630 4891 +261
- Misses 739 767 +28
... and 4 files with indirect coverage changes
🚀 New features to boost your workflow:
|
Description
Please include a summary of changes, motivation and context for this PR.
Member lookup considered declarations could miss members inherited from base classes in some record lookup contexts.
The change adds a fallback to unqualified lookup when direct record lookup fails. This allows lookup to traverse base classes and find inherited members. When an inherited member is found, an implicit UsingShadowDecl is created in the derived class to represent that inherited member as if it were introduced into the derived class scope
UsingShadowDecl mechanism should handle inherited typedefs as well.
Fixes # (issue)
#93 fixes this issue.
Type of change
Please tick all options which are relevant.
Testing
Please describe the test(s) that you added and ran to verify your changes.
https://github.com/compiler-research/CppInterOp/pull/123/changes
this is the reproducible test, which gets passed after this patch.
Checklist