================
@@ -342,6 +342,30 @@ class SMTConv {
                     Ctx.getTypeSize(FromTy));
   }
 
+  static inline llvm::SMTExprRef convertToBoolExpr(llvm::SMTSolverRef &Solver,
+                                                   ASTContext &Ctx,
+                                                   const llvm::SMTExprRef &Exp,
+                                                   QualType Ty) {
+    if (Ty->isBooleanType())
+      return Exp;
+
+    if (Ty->isRealFloatingType()) {
+      llvm::APFloat Zero =
+          llvm::APFloat::getZero(Ctx.getFloatTypeSemantics(Ty));
+      return fromFloatBinOp(Solver, Exp, BO_NE, Solver->mkFloat(Zero));
+    }
+
+    if (Ty->isIntegralOrEnumerationType() || Ty->isAnyPointerType() ||
+        Ty->isBlockPointerType() || Ty->isReferenceType()) {
+      return fromBinOp(
+          Solver, Exp, BO_NE,
+          Solver->mkBitvector(llvm::APSInt("0"), Ctx.getTypeSize(Ty)),
+          Ty->isSignedIntegerOrEnumerationType());
+    }
+
+    llvm_unreachable("Unsupported type for boolean conversion!");
----------------
steakhal wrote:

Is it conventional to have `llvm_unreachable` for cases that look plausible to 
hit by accident?
It feels like we should not optimize and assume that this block should not be 
reached, thus have time-travel optimizations under this assumption.

Can we somehow forge some harmless `llvm::SMTExprRef` and return that instead? 
And turn this `llvm_unreachable` into an `assert`?

https://github.com/llvm/llvm-project/pull/205078
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to