diff --git a/core/metacling/src/TClingDataMemberInfo.cxx b/core/metacling/src/TClingDataMemberInfo.cxx index 57d64ef3c7c32..db4793f917d75 100644 --- a/core/metacling/src/TClingDataMemberInfo.cxx +++ b/core/metacling/src/TClingDataMemberInfo.cxx @@ -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(D)) + else if (const EnumConstantDecl *ECD = dyn_cast(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(ECD->getInitVal().getRawData()); -#else - // In this case in the second part. - return reinterpret_cast(((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(&fEnumValue); + } return -1L; } diff --git a/core/metacling/src/TClingDataMemberInfo.h b/core/metacling/src/TClingDataMemberInfo.h index b3a901bb4278d..e07869005b016 100644 --- a/core/metacling/src/TClingDataMemberInfo.h +++ b/core/metacling/src/TClingDataMemberInfo.h @@ -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;