Skip to content

Commit feaa5aa

Browse files
authored
Fix a crash in constant evaluation of ExtVectorElementExprs (#136771)
Handle the case where the base expression is a pointer to a vector type. rdar://149223362
1 parent 2ca071b commit feaa5aa

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/AST/ExprConstant.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -9202,7 +9202,10 @@ bool LValueExprEvaluator::VisitExtVectorElementExpr(
92029202

92039203
if (Success) {
92049204
Result.setFrom(Info.Ctx, Val);
9205-
const auto *VT = E->getBase()->getType()->castAs<VectorType>();
9205+
QualType BaseType = E->getBase()->getType();
9206+
if (E->isArrow())
9207+
BaseType = BaseType->getPointeeType();
9208+
const auto *VT = BaseType->castAs<VectorType>();
92069209
HandleLValueVectorElement(Info, E, Result, VT->getElementType(),
92079210
VT->getNumElements(), Indices[0]);
92089211
}

clang/test/SemaCXX/constexpr-vectors-access-elements.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ static_assert(b.lo.lo == 1); // expected-error {{not an integral constant expres
4343
// make sure clang rejects taking address of a vector element
4444
static_assert(&b[1]); // expected-error {{address of vector element requested}}
4545

46+
constexpr const FourIntsExtVec *p = &b;
47+
static_assert(p->x == 1);
4648
}

0 commit comments

Comments
 (0)