https://github.com/superdusty created 
https://github.com/llvm/llvm-project/pull/199912

Fixes #196948

This patch prevents a crash when comparing a fixed point type with a
BitInt type (e.g., `static_assert(i == 42.0k)`).

The crash occurred because GetFixedPointRank expects a BuiltinType,
but BitInt is not a BuiltinType.

Added checks in:
- `unsupportedTypeConversion`: reject fixed point/BitInt conversions
- `handleFixedPointConversion`: reject fixed point/BitInt comparisons

Now clang properly emits an error instead of crashing.

>From 8ea495d6b225fb45827c7cb4ad837c5f1e3d64db Mon Sep 17 00:00:00 2001
From: cry <[email protected]>
Date: Wed, 27 May 2026 17:30:06 +0800
Subject: [PATCH] [Clang] Fix crash when comparing fixed point type with BitInt

---
 clang/lib/Sema/SemaExpr.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 521a8516ac179..2f79ff3edcb79 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1287,6 +1287,10 @@ static QualType handleFloatConversion(Sema &S, 
ExprResult &LHS,
 /// Helper function of UsualArithmeticConversions().
 static bool unsupportedTypeConversion(const Sema &S, QualType LHSType,
                                       QualType RHSType) {
+  if ((LHSType->isFixedPointType() && RHSType->isBitIntType()) ||
+      (LHSType->isBitIntType() && RHSType->isFixedPointType()))
+    return true;
+
   // No issue if either is not a floating point type.
   if (!LHSType->isFloatingType() || !RHSType->isFloatingType())
     return false;
@@ -1534,6 +1538,12 @@ static QualType handleFixedPointConversion(Sema &S, 
QualType LHSTy,
          "Special fixed point arithmetic operation conversions are only "
          "applied to ints or other fixed point types");
 
+  // If either type is BitInt, return an empty type to avoid crashing
+  // when GetFixedPointRank is called later.
+  if (LHSTy->isBitIntType() || RHSTy->isBitIntType()) {
+    return QualType();
+  }
+
   // If one operand has signed fixed-point type and the other operand has
   // unsigned fixed-point type, then the unsigned fixed-point operand is
   // converted to its corresponding signed fixed-point type and the resulting

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

Reply via email to