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 `_. +- 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 `_. 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