Skip to content

Return enum constant values as their int64_t bit pattern - #1096

Merged
aaronj0 merged 1 commit into
compiler-research:mainfrom
aaronj0:enum-constant-int64
Aug 31, 2026
Merged

Return enum constant values as their int64_t bit pattern#1096
aaronj0 merged 1 commit into
compiler-research:mainfrom
aaronj0:enum-constant-int64

Conversation

@aaronj0

@aaronj0 aaronj0 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Supersedes #970, from the ROOT migration commit root-project/root@4ccb37c with fixes for the Windows and WASM failures where 32-bit unsigned long overflows stoul. The fallback in that PR parsed 1ULL<<63 with std::stoul which throew out_of_range (unsigned long is 32-bit on those platforms)

GetEnumConstantValue returns size_t and calls APSInt::getExtValue unguarded, which asserts above INT64_MAX. Round-tripping large values through std::stoul throws where unsigned long is 32 bit (LLP64 Windows, wasm32), and a size_t return truncates there regardless. ROOT's Windows CI hit this as an uncaught out_of_range in MetaClingTests test_GH_20925.

GetEnumConstantValue returns size_t and calls APSInt::getExtValue
unguarded, which asserts above INT64_MAX. Round-tripping large values
through std::stoul (compiler-research#970) throws where unsigned long is 32 bit (LLP64
Windows, wasm32), and a size_t return truncates there regardless.
ROOT's Windows CI hit this as an uncaught out_of_range in
MetaClingTests test_GH_20925.

Return the 64-bit pattern as int64_t everywhere: getExtValue when
representable, the zero-extended value as two's complement otherwise.
@aaronj0
aaronj0 force-pushed the enum-constant-int64 branch from c385166 to 14f494b Compare August 27, 2026 11:09
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.68%. Comparing base (1795887) to head (14f494b).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1096   +/-   ##
=======================================
  Coverage   87.68%   87.68%           
=======================================
  Files          23       23           
  Lines        6382     6384    +2     
=======================================
+ Hits         5596     5598    +2     
  Misses        786      786           
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 90.49% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 90.49% <100.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions


auto HugeConstants = Cpp::GetEnumConstants(Decls[1]);
EXPECT_EQ(Cpp::GetEnumConstantValue(HugeConstants[0]),
(int64_t)((uint64_t)1 << 63));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "int64_t" is directly included [misc-include-cleaner]

unittests/CppInterOp/EnumReflectionTest.cpp:7:

+ #include <cstdint>


auto HugeConstants = Cpp::GetEnumConstants(Decls[1]);
EXPECT_EQ(Cpp::GetEnumConstantValue(HugeConstants[0]),
(int64_t)((uint64_t)1 << 63));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "uint64_t" is directly included [misc-include-cleaner]

            (int64_t)((uint64_t)1 << 63));
                       ^

@vgvassilev vgvassilev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % comment.

}

size_t GetEnumConstantValue(ConstDeclRef DRef) {
int64_t GetEnumConstantValue(ConstDeclRef DRef) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a platform-independent typedef?

@aaronj0 aaronj0 Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, int64_t is available on all platforms from <cstdint>. We already have API's using typedefs from cstdint: GetBaseClassOffset returns int64_t, and InsertOrReplaceJitSymbol accepts uint64_t param, which matches APSInt::getExtValue()

@aaronj0
aaronj0 merged commit 4fa0f95 into compiler-research:main Aug 31, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants