llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Yutong Zhu (YutongZhuu) <details> <summary>Changes</summary> This PR attempts to fix #<!-- -->173614. The ``TryGetExprRange`` function now checks if the oprand is an unsigned vector when computing the ranges. Thanks for reviewing. --- Full diff: https://github.com/llvm/llvm-project/pull/182627.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Sema/SemaChecking.cpp (+18) - (added) clang/test/Sema/compare.cpp (+14) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77e2078a5ffbf..18c3667894172 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -498,6 +498,8 @@ Improvements to Clang's diagnostics - Clang now generates a fix-it for C++20 designated initializers when the initializers do not match the declaration order in the structure. +- Clang now doesn't throw assertion errors when comparing unsigned vectors(#173614) + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ba4b25961d70d..052828107a867 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -11500,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); + } + } + std::optional<IntRange> SubRange = TryGetExprRange( C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate); @@ -11518,6 +11527,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); + } + } std::optional<IntRange> SubRange = TryGetExprRange( C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate); diff --git a/clang/test/Sema/compare.cpp b/clang/test/Sema/compare.cpp new file mode 100644 index 0000000000000..fb5d82847e2a0 --- /dev/null +++ b/clang/test/Sema/compare.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only +// Expect no assertion failures in this file (#173614). +typedef unsigned long __attribute__((__vector_size__(8))) W; + +int i; +W g; + +void negation(void) { + W w = i == (-g); +} + +void bitwiseNot(void) { + W w = i == (~g); +} `````````` </details> https://github.com/llvm/llvm-project/pull/182627 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
