diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index 90c934d19..b832f3d73 100644 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -793,7 +793,11 @@ TCppIndex_t GetEnumConstantValue(TCppScope_t handle) { auto* D = (clang::Decl*)handle; if (auto* ECD = llvm::dyn_cast_or_null(D)) { const llvm::APSInt& Val = ECD->getInitVal(); - return INTEROP_RETURN(Val.getExtValue()); + if (Val.isRepresentableByInt64()) + return INTEROP_RETURN(Val.getExtValue()); + llvm::SmallString<40> StrVal; + Val.toString(StrVal); + return INTEROP_RETURN(std::stoul(StrVal.c_str())); } return INTEROP_RETURN(0); } diff --git a/unittests/CppInterOp/EnumReflectionTest.cpp b/unittests/CppInterOp/EnumReflectionTest.cpp index 19b58f3e7..c1c74e884 100644 --- a/unittests/CppInterOp/EnumReflectionTest.cpp +++ b/unittests/CppInterOp/EnumReflectionTest.cpp @@ -238,6 +238,10 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, EnumReflection_GetEnumConstantValue) { MinusNine }; int a = 10; + + enum TooLong : unsigned long long { + BIG = ((unsigned long long)1)<<63 + }; )"; GetAllTopLevelDecls(code, Decls); @@ -250,7 +254,12 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, EnumReflection_GetEnumConstantValue) { EXPECT_EQ(Cpp::GetEnumConstantValue(EnumConstants[4]), 54); EXPECT_EQ(Cpp::GetEnumConstantValue(EnumConstants[5]), -10); EXPECT_EQ(Cpp::GetEnumConstantValue(EnumConstants[6]), -9); + EXPECT_EQ(Cpp::GetEnumConstantValue(Decls[1]), 0); // Checking value of non enum constant + + EnumConstants = Cpp::GetEnumConstants(Decls[2]); + EXPECT_EQ(Cpp::GetEnumConstantValue(EnumConstants[0]), ((unsigned long long)1) + << 63); } TYPED_TEST(CPPINTEROP_TEST_MODE, EnumReflection_GetEnums) {