<div dir="ltr">Hello everyone,<div><br></div><div>As part of the SMT encoding of constraints done in the CSA, we are triggering a segfault when trying to get the integer type order between an enumType and an integer.</div><div><br></div><div>The code from ASTContext.cpp, starting in line 5814:</div><div><br></div><div>static const Type *getIntegerTypeForEnum(const EnumType *ET) {<br>  // Incomplete enum types are not treated as integer types.<br>  // FIXME: In C++, enum types are never integer types.<br>  if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())<br>    return ET->getDecl()->getIntegerType().getTypePtr();<br><b>  return nullptr; // [1]</b><br>}<br><br>/// getIntegerTypeOrder - Returns the highest ranked integer type:<br>/// C99 6.3.1.8p1.  If LHS > RHS, return 1.  If LHS == RHS, return 0. If<br>/// LHS < RHS, return -1.<br>int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const {<br>  const Type *LHSC = getCanonicalType(LHS).getTypePtr();<br>  const Type *RHSC = getCanonicalType(RHS).getTypePtr();<br><br>  // Unwrap enums to their underlying type.<br><b>  if (const auto *ET = dyn_cast<EnumType>(LHSC))<br>    LHSC = getIntegerTypeForEnum(ET); </b><b>// [0]</b><br>  if (const auto *ET = dyn_cast<EnumType>(RHSC))<br>    RHSC = getIntegerTypeForEnum(ET);<br><br>  if (LHSC == RHSC) return 0;<br><br><b>  bool LHSUnsigned = LHSC->isUnsignedIntegerType(); </b><b>// [2]</b><br>  bool RHSUnsigned = RHSC->isUnsignedIntegerType();<br clear="all"><div><br></div><div>The problem happens when LHS (or RHS) is a C++11 enum: getIntegerTypeForEnum [0] is called but returns a nullptr [1], and later we try to call a method from the nullptr [2].</div><div><br></div><div>~</div><div><br></div><div>Any suggestion of how we can fix/work around it? It doesn't seem to affect Sema in any way, but the code seems rather fragile...</div><div><br></div><div>I hacked around it by doing:</div><div>-  return nullptr;<br>+  return ET->getDecl()->getPromotionType().getTypePtr();<br></div><div><br></div><div>But it does not seem right, there is even a comment there that reads:</div><div>// FIXME: In C++, enum types are never integer types.<br></div><div><br></div><div>Thank you,</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><br></div><div>Mikhail Ramalho.</div></div></div></div></div>