-
Couldn't load subscription status.
- Fork 35
Fix: resolve nested attributes of anonymous records in GetDatamembers #321
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
Changes from all commits
a801568
846796b
a2fd87e
e837ec6
34f0c4c
e8dd9a1
25cf88d
36f9aee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1128,9 +1128,31 @@ namespace Cpp { | |
|
|
||
| if (auto *CXXRD = llvm::dyn_cast_or_null<CXXRecordDecl>(D)) { | ||
| std::vector<TCppScope_t> datamembers; | ||
| for (auto it = CXXRD->field_begin(), end = CXXRD->field_end(); it != end; | ||
| it++) { | ||
| datamembers.push_back((TCppScope_t)*it); | ||
| llvm::SmallVector<RecordDecl::field_iterator, 2> stack_begin; | ||
| llvm::SmallVector<RecordDecl::field_iterator, 2> stack_end; | ||
| stack_begin.push_back(CXXRD->field_begin()); | ||
| stack_end.push_back(CXXRD->field_end()); | ||
| while (!stack_begin.empty()) { | ||
| if (stack_begin.back() == stack_end.back()) { | ||
| stack_begin.pop_back(); | ||
| stack_end.pop_back(); | ||
| continue; | ||
| } | ||
| Decl* D = *(stack_begin.back()); | ||
| if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) { | ||
| if (FD->isAnonymousStructOrUnion()) { | ||
| if (const auto* RT = FD->getType()->getAs<RecordType>()) { | ||
| if (auto* CXXRD = llvm::dyn_cast<CXXRecordDecl>(RT->getDecl())) { | ||
| stack_begin.back()++; | ||
| stack_begin.push_back(CXXRD->field_begin()); | ||
| stack_end.push_back(CXXRD->field_end()); | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| datamembers.push_back((TCppScope_t)D); | ||
| stack_begin.back()++; | ||
| } | ||
|
|
||
| return datamembers; | ||
|
|
@@ -1175,9 +1197,26 @@ namespace Cpp { | |
| auto *D = (Decl *) var; | ||
| auto &C = getASTContext(); | ||
|
|
||
| if (auto *FD = llvm::dyn_cast<FieldDecl>(D)) | ||
| return (intptr_t) C.toCharUnitsFromBits(C.getASTRecordLayout(FD->getParent()) | ||
| .getFieldOffset(FD->getFieldIndex())).getQuantity(); | ||
| if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) { | ||
| const clang::RecordDecl* RD = FD->getParent(); | ||
| intptr_t offset = | ||
| C.toCharUnitsFromBits(C.getFieldOffset(FD)).getQuantity(); | ||
| while (RD->isAnonymousStructOrUnion()) { | ||
| const clang::RecordDecl* anon = RD; | ||
| RD = llvm::dyn_cast<RecordDecl>(anon->getParent()); | ||
| for (auto F = RD->field_begin(); F != RD->field_end(); ++F) { | ||
| const auto* RT = F->getType()->getAs<RecordType>(); | ||
| if (!RT) | ||
| continue; | ||
| if (anon == RT->getDecl()) { | ||
| FD = *F; | ||
| break; | ||
| } | ||
| } | ||
| offset += C.toCharUnitsFromBits(C.getFieldOffset(FD)).getQuantity(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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();
^ |
||
| } | ||
| return offset; | ||
| } | ||
|
|
||
| if (auto *VD = llvm::dyn_cast<VarDecl>(D)) { | ||
| auto GD = GlobalDecl(VD); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); ^