================
@@ -570,23 +572,42 @@ class SMTConv {
   // TODO: Refactor to put elsewhere
   static inline QualType getAPSIntType(ASTContext &Ctx,
                                        const llvm::APSInt &Int) {
-    return Ctx.getIntTypeForBitwidth(Int.getBitWidth(), Int.isSigned());
+    QualType Ty = Ctx.getIntTypeForBitwidth(Int.getBitWidth(), Int.isSigned());
+    // If Ty is Null, could be because the original type was a _BitInt.
+    // Get the bit size and round up to next power of 2, max char size
+    if (Ty.isNull()) {
+      unsigned CharTypeSize = Ctx.getTypeSize(Ctx.CharTy);
+      unsigned pow2DestWidth =
+          std::max(llvm::bit_ceil(Int.getBitWidth()), CharTypeSize);
+      Ty = Ctx.getIntTypeForBitwidth(pow2DestWidth, Int.isSigned());
+    }
+    return Ty;
+  }
+
+  static inline bool IsPower2(unsigned bits) {
----------------
NagyDonat wrote:

You don't need to implement this helper function because it already exists in 
the support headers, see e.g. `llvm::isPowerOf2_32` defined in 
`llvm/include/llvm/Support/MathExtras.h` or `llvm::has_single_bit` from 
`llvm/include/llvm/ADT/bit.h`.

https://github.com/llvm/llvm-project/pull/143310
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to