Skip to content

Commit 79c7273

Browse files
committed
[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
1 parent 7cd4206 commit 79c7273

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10193,7 +10193,7 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) {
1019310193
Elt = SValInt.rotl(i*EltSize+EltSize).zextOrTrunc(EltSize);
1019410194
else
1019510195
Elt = SValInt.rotr(i*EltSize).zextOrTrunc(EltSize);
10196-
Elts.push_back(APValue(APSInt(Elt, EltTy->isSignedIntegerType())));
10196+
Elts.push_back(APValue(APSInt(Elt, !EltTy->isSignedIntegerType())));
1019710197
}
1019810198
} else {
1019910199
return Error(E);

clang/test/CodeGenOpenCL/vector_literals.cl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ void vector_literals_valid() {
6363
//CHECK: store <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, <4 x float>* %V2
6464
float4 V2 = (float4)(1);
6565
}
66+
67+
void vector_literals_with_cast() {
68+
// CHECK-LABEL: vector_literals_with_cast
69+
// CHECK: store <2 x i32> <i32 12, i32 34>, <2 x i32>*
70+
// CHECK: extractelement <2 x i32> %{{[0-9]+}}, i{{[0-9]+}} 0
71+
unsigned int withCast = ((int2)((int2)(12, 34))).s0;
72+
}

0 commit comments

Comments
 (0)