Open Quuxplusone opened 3 years ago
Attached stack.txt
(14813 bytes, text/plain): stack-dump
A workaround is to not use an underlying type (if that's possible).
Looks like SMTConv.h does not handle extraction of the underlying type for
scoped enums.
Looking at ASTContext.cpp, there is a comment added from commit
e65ab9e80eec0e56235bd74c6d487e5a89f66146 ...
+static const Type *getIntegerTypeForEnum(const EnumType *ET) {
+ // Incomplete enum types are not treated as integer types.
+ // FIXME: In C++, enum types are never integer types.
+ if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+ return ET->getDecl()->getIntegerType().getTypePtr();
+ return NULL;
+}
and SMTConv.h specifically only looks for Integral Or Enumeration types that
are also Arithmetic - and a scoped enum is excluded as Arithmetic in Type.cpp,
see ...
bool Type::isArithmeticType() const {
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::Float128 &&
BT->getKind() != BuiltinType::BFloat16;
if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
// GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
// If a body isn't seen by the time we get here, return false.
//
// C++0x: Enumerations are not arithmetic types. For now, just return
// false for scoped enumerations since that will disable any
// unwanted implicit conversions.
return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete();
return isa<ComplexType>(CanonicalType) || isExtIntType();
}
One approach in SMTConv.h is to check the LTy and RTy and "promote" the scoped
enum to the LTy or RTy type. This seems to work. But I don't feel comfortable
making this change at this time without first correcting the test infra to
support non Z3 and Z3 usage when running LITs (per Balazs comments).
I think https://reviews.llvm.org/D85528 should resolve this.
However, we need a bit more time to evaluate the impact on the results.
The fix could not make into the latest release.
It would be awesome to find more considerably big projects using enum classes
while casting them to the underlaying type.
Most of the projects we are testing on lack this property.
Let me know if you have some projects in mind!
Cheers.
stack.txt
(14813 bytes, text/plain)