[clang] [Clang] Fix assertion "unsigned range includes negative?" in AnalyzeComparison during Sema of vector comparison with mismatched signed/unsigned types and __builtin_convertvector (PR #182627)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 25 02:50:48 PST 2026


================
@@ -11679,6 +11500,15 @@ static std::optional<IntRange> TryGetExprRange(ASTContext &C, const Expr *E,
                                Approximate);
       }
 
+      QualType T = E->getType();
+      if (const auto *VT = T->getAs<VectorType>()) {
+        QualType ElemTy = VT->getElementType();
+        if (ElemTy->isUnsignedIntegerType()) {
+          return TryGetExprRange(C, UO->getSubExpr(), MaxWidth,
+                                 InConstantContext, Approximate);
+        }
+      }
+
----------------
ojhunt wrote:

There's a lot of duplication here. I think a better approach would be

```cpp
case UO_Minus:
  QualType ElemType = E->getType();
  if (const VectorType *VT = ElementType->getAs<VectorType>())
    ElementType = VT->getElementType();
  if (ElementType->isUnsignedIntegerType())
  ...
```

and again for below. 

Long term there should probably be a function that can provide the fundamental type of a scalar, but for now there isn't.

https://github.com/llvm/llvm-project/pull/182627


More information about the cfe-commits mailing list