Skip to content

Commit

Permalink
[cling] Store enum values as data members to fix cppyy enum tests
Browse files Browse the repository at this point in the history
This fixes the failing python enum tests like:
- `roottest-python-cpp-cpp`
- `roottest-python-cmdLineUtils-ROOT_8197`

Also remove `R__BYTESWAP` which should not be needed anymore.

The leak was fixed with:
llvm/llvm-project#78311

This caused our tests to fail as they relied on the
previous behavior.
  • Loading branch information
devajithvs committed Aug 28, 2024
1 parent 61da02d commit 6456e70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/metacling/src/TClingDataMemberInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,17 @@ Longptr_t TClingDataMemberInfo::Offset()
// clang there is misbehaviour in MangleContext::shouldMangleDeclName.
// enum constants are essentially numbers and don't get addresses. However
// ROOT expects the address to the enum constant initializer to be returned.
else if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
else if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) {
// The raw data is stored as a long long, so we need to find the 'long'
// part.
#ifdef R__BYTESWAP
// In this case at the beginning.
return reinterpret_cast<Longptr_t>(ECD->getInitVal().getRawData());
#else
// In this case in the second part.
return reinterpret_cast<Longptr_t>(((char*)ECD->getInitVal().getRawData())+sizeof(Longptr_t) );
#endif

// The memory leak for `EnumConstantDecl` was fixed in:
// https://github.com/llvm/llvm-project/pull/78311
// We were relying on the leak to provide the address for EnumConstantDecl.
// Now store the data value as a member instead.
fEnumValue = ECD->getInitVal().getExtValue();
return reinterpret_cast<Longptr_t>(&fEnumValue);
}
return -1L;
}

Expand Down
1 change: 1 addition & 0 deletions core/metacling/src/TClingDataMemberInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TClingDataMemberInfo final : public TClingDeclInfo {
TClingDataMemberIter fIter; // Current decl.
std::string fTitle; // The meta info for the member.
bool fFirstTime = true; // We need to skip the first increment to support the cint Next() semantics.
int64_t fEnumValue; // Special case to handle enums

mutable std::string fIoType;
mutable std::string fIoName;
Expand Down

0 comments on commit 6456e70

Please sign in to comment.