Author: Aaron Ballman Date: 2022-05-04T13:25:21-04:00 New Revision: 859d92394812c0e5e650ab337717719b9687e5ce
URL: https://github.com/llvm/llvm-project/commit/859d92394812c0e5e650ab337717719b9687e5ce DIFF: https://github.com/llvm/llvm-project/commit/859d92394812c0e5e650ab337717719b9687e5ce.diff LOG: Fix a failing assertion with vector type initialization When constant evaluating the initializer for an object of vector type, we would call APInt::trunc() but truncate to the same bit-width the object already had, which would cause an assertion. Instead, use APInt::truncOrSelf() so that we no longer assert in this situation. Fix #50216 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/AST/ExprConstant.cpp clang/test/Sema/vector-init.c Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 079523a07361e..3187dad2b729e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -132,6 +132,10 @@ Bug Fixes argument to a generic selection expression has side effects in the case where the expression is result dependent. This fixes `Issue 50227 <https://github.com/llvm/llvm-project/issues/50227>`_. +- Fixed an assertion when constant evaluating an initializer for a GCC/Clang + floating-point vector type when the width of the initialization is exactly + the same as the elements of the vector being initialized. + Fixes `Issue 50216 <https://github.com/llvm/llvm-project/issues/50216>`_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 70a1e0bbd91aa..650ba305c48b1 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -10353,9 +10353,9 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) { for (unsigned i = 0; i < NElts; i++) { llvm::APInt Elt; if (BigEndian) - Elt = SValInt.rotl(i*EltSize+FloatEltSize).trunc(FloatEltSize); + Elt = SValInt.rotl(i*EltSize+FloatEltSize).truncOrSelf(FloatEltSize); else - Elt = SValInt.rotr(i*EltSize).trunc(FloatEltSize); + Elt = SValInt.rotr(i*EltSize).truncOrSelf(FloatEltSize); Elts.push_back(APValue(APFloat(Sem, Elt))); } } else if (EltTy->isIntegerType()) { diff --git a/clang/test/Sema/vector-init.c b/clang/test/Sema/vector-init.c index c7c278f96368f..554e976892636 100644 --- a/clang/test/Sema/vector-init.c +++ b/clang/test/Sema/vector-init.c @@ -42,3 +42,11 @@ void test3(void) { longlong2 arr1[2] = { test3_helper(), test3_helper() }; short4 arr2[2] = { test3_helper(), test3_helper() }; // expected-error 2 {{initializing 'short4' (vector of 4 'short' values) with an expression of incompatible type 'short8' (vector of 8 'short' values)}} } + +// GH50216 +// These would previously crash when constant evaluating the initializers. +typedef double float64x1_t __attribute__((vector_size(8))); +float64x1_t arg1 = (float64x1_t)0x3fedf9d4343c7c80; // okay + +typedef float float32x1_t __attribute__((vector_size(4))); +float32x1_t arg2 = (float32x1_t)0x3fedf9d4; // okay _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits