Fix: resolve nested attributes of anonymous records in GetDatamembers#321
Conversation
|
The test fail with |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
lib/Interpreter/CppInterOp.cpp
Outdated
| if (D->getKind() == clang::Decl::Field && | ||
| dyn_cast<FieldDecl>(D)->isAnonymousStructOrUnion()) { |
There was a problem hiding this comment.
| if (D->getKind() == clang::Decl::Field && | |
| dyn_cast<FieldDecl>(D)->isAnonymousStructOrUnion()) { | |
| if (isa<FieldDecl>(D) && | |
| cast<FieldDecl>(D)->isAnonymousStructOrUnion()) { |
There was a problem hiding this comment.
I think we should have a proper dyn_cast and isAnonymousStructOrUnion as a nested if...
Yes, but only for this test file. |
|
Hi @vgvassilev, Valgrind fails. Should I add if (llvm::sys::RunningOnValgrind())
GTEST_SKIP() << "XFAIL due to Valgrind report";? It is |
lib/Interpreter/CppInterOp.cpp
Outdated
| continue; | ||
| } | ||
| Decl* D = *(stack_begin.back()); | ||
| if (D->getKind() == clang::Decl::Field) { |
There was a problem hiding this comment.
| if (D->getKind() == clang::Decl::Field) { |
lib/Interpreter/CppInterOp.cpp
Outdated
| const clang::RecordDecl* RD = FD->getParent(); | ||
| intptr_t offset = | ||
| C.toCharUnitsFromBits( | ||
| C.getASTRecordLayout(RD).getFieldOffset(FD->getFieldIndex())) |
There was a problem hiding this comment.
| C.getASTRecordLayout(RD).getFieldOffset(FD->getFieldIndex())) | |
| C.getFieldOffset(FD) |
lib/Interpreter/CppInterOp.cpp
Outdated
| if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) { | ||
| if (FD->isAnonymousStructOrUnion()) { | ||
| if (auto* CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>( | ||
| FD->getType()->getAs<RecordType>()->getDecl())) { |
There was a problem hiding this comment.
warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]
FD->getType()->getAs<RecordType>()->getDecl())) {
^Additional context
lib/Interpreter/CppInterOp.cpp:1128: Assuming 'D' is a 'CastReturnType'
if (auto *CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>(D)) {
^lib/Interpreter/CppInterOp.cpp:1128: 'CXXRD' is non-null
if (auto *CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>(D)) {
^lib/Interpreter/CppInterOp.cpp:1128: Taking true branch
if (auto *CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>(D)) {
^lib/Interpreter/CppInterOp.cpp:1134: Loop condition is true. Entering loop body
while (!stack_begin.empty()) {
^lib/Interpreter/CppInterOp.cpp:1135: Taking false branch
if (stack_begin.back() == stack_end.back()) {
^lib/Interpreter/CppInterOp.cpp:1141: Assuming 'D' is a 'CastReturnType'
if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) {
^lib/Interpreter/CppInterOp.cpp:1141: 'FD' is non-null
if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) {
^lib/Interpreter/CppInterOp.cpp:1141: Taking true branch
if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) {
^lib/Interpreter/CppInterOp.cpp:1142: Assuming the condition is true
if (FD->isAnonymousStructOrUnion()) {
^lib/Interpreter/CppInterOp.cpp:1142: Taking true branch
if (FD->isAnonymousStructOrUnion()) {
^lib/Interpreter/CppInterOp.cpp:1144: Assuming the object is not a 'const RecordType *'
FD->getType()->getAs<RecordType>()->getDecl())) {
^lib/Interpreter/CppInterOp.cpp:1144: Called C++ object pointer is null
FD->getType()->getAs<RecordType>()->getDecl())) {
^
Yes, please do. |
| if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) { | ||
| const clang::RecordDecl* RD = FD->getParent(); | ||
| intptr_t offset = | ||
| C.toCharUnitsFromBits(C.getFieldOffset(FD)).getQuantity(); |
There was a problem hiding this comment.
warning: narrowing conversion from 'uint64_t' (aka 'unsigned long') to signed type 'int64_t' (aka 'long') is implementation-defined [cppcoreguidelines-narrowing-conversions]
C.toCharUnitsFromBits(C.getFieldOffset(FD)).getQuantity();
^| break; | ||
| } | ||
| } | ||
| offset += C.toCharUnitsFromBits(C.getFieldOffset(FD)).getQuantity(); |
There was a problem hiding this comment.
warning: narrowing conversion from 'uint64_t' (aka 'unsigned long') to signed type 'int64_t' (aka 'long') is implementation-defined [cppcoreguidelines-narrowing-conversions]
offset += C.toCharUnitsFromBits(C.getFieldOffset(FD)).getQuantity();
^
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #321 +/- ##
==========================================
+ Coverage 73.44% 73.69% +0.25%
==========================================
Files 8 8
Lines 2990 3019 +29
==========================================
+ Hits 2196 2225 +29
Misses 794 794
|
Co-authored-by: Vassil Vassilev <v.g.vassilev@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
No description provided.