Skip to content

Commit 3231cb4

Browse files
authored
[clang] Fix copy/paste error in vector __builtin_elementwise_{add,sub}_sat implementation. (#147973)
Closes #147891.
1 parent 638943b commit 3231cb4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11537,12 +11537,12 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1153711537
switch (E->getBuiltinCallee()) {
1153811538
case Builtin::BI__builtin_elementwise_add_sat:
1153911539
ResultElements.push_back(APValue(
11540-
APSInt(LHS.isSigned() ? LHS.sadd_sat(RHS) : RHS.uadd_sat(RHS),
11540+
APSInt(LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS),
1154111541
DestEltTy->isUnsignedIntegerOrEnumerationType())));
1154211542
break;
1154311543
case Builtin::BI__builtin_elementwise_sub_sat:
1154411544
ResultElements.push_back(APValue(
11545-
APSInt(LHS.isSigned() ? LHS.ssub_sat(RHS) : RHS.usub_sat(RHS),
11545+
APSInt(LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS),
1154611546
DestEltTy->isUnsignedIntegerOrEnumerationType())));
1154711547
break;
1154811548
}

clang/test/Sema/constant_builtins_vector.cpp renamed to clang/test/Sema/constant-builtins-vector.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef unsigned long long vector4ulong __attribute__((__vector_size__(32)));
2727
typedef unsigned int vector4uint __attribute__((__vector_size__(16)));
2828
typedef short vector4short __attribute__((__vector_size__(8)));
2929
typedef char vector4char __attribute__((__vector_size__(4)));
30+
typedef unsigned char vector4uchar __attribute__((__vector_size__(4)));
3031
typedef BitInt8 vector4BitInt8 __attribute__((__vector_size__(4)));
3132
typedef BitInt32 vector4BitInt32 __attribute__((__vector_size__(16)));
3233
typedef BitInt128 vector4BitInt128 __attribute__((__vector_size__(64)));
@@ -848,6 +849,7 @@ static_assert(__builtin_elementwise_add_sat(~(1 << 31), 42) == ~(1 << 31));
848849
static_assert(__builtin_elementwise_add_sat((1 << 31), -42) == (1 << 31));
849850
static_assert(__builtin_elementwise_add_sat(~0U, 1U) == ~0U);
850851
static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_add_sat((vector4char){1, 2, 3, 4}, (vector4char){1, 2, 3, 4})) == (LITTLE_END ? 0x08060402 : 0x02040608));
852+
static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_add_sat((vector4uchar){1, 2, 3, 4}, (vector4uchar){0, 1, 2, 3})) == (LITTLE_END ? 0x07050301U : 0x01030507U));
851853
static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_add_sat((vector4short){(short)0x8000, (short)0x8001, (short)0x8002, (short)0x8003}, (vector4short){-7, -8, -9, -10}) == (LITTLE_END ? 0x8000800080008000 : 0x8000800080008000)));
852854

853855
static_assert(__builtin_elementwise_sub_sat(1, 2) == -1);
@@ -856,4 +858,5 @@ static_assert(__builtin_elementwise_sub_sat(~(1 << 31), -42) == ~(1 << 31));
856858
static_assert(__builtin_elementwise_sub_sat((1 << 31), 42) == (1 << 31));
857859
static_assert(__builtin_elementwise_sub_sat(0U, 1U) == 0U);
858860
static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_sub_sat((vector4char){5, 4, 3, 2}, (vector4char){1, 1, 1, 1})) == (LITTLE_END ? 0x01020304 : 0x04030201));
861+
static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_sub_sat((vector4uchar){5, 4, 3, 2}, (vector4uchar){1, 1, 1, 1})) == (LITTLE_END ? 0x01020304U : 0x04030201U));
859862
static_assert(__builtin_bit_cast(unsigned long long, __builtin_elementwise_sub_sat((vector4short){(short)0x8000, (short)0x8001, (short)0x8002, (short)0x8003}, (vector4short){7, 8, 9, 10}) == (LITTLE_END ? 0x8000800080008000 : 0x8000800080008000)));

0 commit comments

Comments
 (0)