llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: superdusty

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/199912.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+10) 


``````````diff
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

``````````

</details>


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

Reply via email to