Skip to content

Commit a865ec7

Browse files
committed
[cling] Store enum values as data members to fix cppyy enum tests
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.
1 parent 94d61bd commit a865ec7

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

core/metacling/src/TClingDataMemberInfo.cxx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,17 @@ Longptr_t TClingDataMemberInfo::Offset()
397397
// clang there is misbehaviour in MangleContext::shouldMangleDeclName.
398398
// enum constants are essentially numbers and don't get addresses. However
399399
// ROOT expects the address to the enum constant initializer to be returned.
400-
else if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
400+
else if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) {
401401
// The raw data is stored as a long long, so we need to find the 'long'
402402
// part.
403-
#ifdef R__BYTESWAP
404-
// In this case at the beginning.
405-
return reinterpret_cast<Longptr_t>(ECD->getInitVal().getRawData());
406-
#else
407-
// In this case in the second part.
408-
return reinterpret_cast<Longptr_t>(((char*)ECD->getInitVal().getRawData())+sizeof(Longptr_t) );
409-
#endif
403+
404+
// The memory leak for `EnumConstantDecl` was fixed in:
405+
// https://github.com/llvm/llvm-project/pull/78311
406+
// We were relying on the leak to provide the address for EnumConstantDecl.
407+
// Now store the data value as a member instead.
408+
fEnumValue = ECD->getInitVal().getExtValue();
409+
return reinterpret_cast<Longptr_t>(&fEnumValue);
410+
}
410411
return -1L;
411412
}
412413

core/metacling/src/TClingDataMemberInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class TClingDataMemberInfo final : public TClingDeclInfo {
7777
TClingDataMemberIter fIter; // Current decl.
7878
std::string fTitle; // The meta info for the member.
7979
bool fFirstTime = true; // We need to skip the first increment to support the cint Next() semantics.
80+
int64_t fEnumValue; // Special case to handle enums
8081

8182
mutable std::string fIoType;
8283
mutable std::string fIoName;

0 commit comments

Comments
 (0)