From 79c727328b908051616ed39ceae137b5f1d064cd Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Wed, 27 Jan 2021 09:30:26 +0000 Subject: [PATCH] [clang] Fix signedness in vector bitcast evaluation The included test case triggered a sign assertion on the result in `Success()`. This was caused by the APSInt created for a bitcast having its signedness bit inverted. The second APSInt constructor argument is `isUnsigned`, so invert the result of `isSignedIntegerType`. Relanding this patch after reverting. The test case had to be updated to be insensitive to 32/64-bit extractelement indices. Differential Revision: https://reviews.llvm.org/D95135 --- clang/lib/AST/ExprConstant.cpp | 2 +- clang/test/CodeGenOpenCL/vector_literals.cl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 56181bb..c197372 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -10193,7 +10193,7 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) { Elt = SValInt.rotl(i*EltSize+EltSize).zextOrTrunc(EltSize); else Elt = SValInt.rotr(i*EltSize).zextOrTrunc(EltSize); - Elts.push_back(APValue(APSInt(Elt, EltTy->isSignedIntegerType()))); + Elts.push_back(APValue(APSInt(Elt, !EltTy->isSignedIntegerType()))); } } else { return Error(E); diff --git a/clang/test/CodeGenOpenCL/vector_literals.cl b/clang/test/CodeGenOpenCL/vector_literals.cl index af57171..6f9399c 100644 --- a/clang/test/CodeGenOpenCL/vector_literals.cl +++ b/clang/test/CodeGenOpenCL/vector_literals.cl @@ -63,3 +63,10 @@ void vector_literals_valid() { //CHECK: store <4 x float> , <4 x float>* %V2 float4 V2 = (float4)(1); } + +void vector_literals_with_cast() { + // CHECK-LABEL: vector_literals_with_cast + // CHECK: store <2 x i32> , <2 x i32>* + // CHECK: extractelement <2 x i32> %{{[0-9]+}}, i{{[0-9]+}} 0 + unsigned int withCast = ((int2)((int2)(12, 34))).s0; +} -- 2.7.4