Skip to content

Commit b87b759

Browse files
tbaederrAlexisPerry
authored andcommitted
[clang][Interp] Fix Descriptor::getElemQualType() for complex/vectors
We handle them like arrays but still need to differentiate between array/vector/complex types when dealing with QualTypes.
1 parent 01b833a commit b87b759

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clang/lib/AST/Interp/Descriptor.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,14 @@ QualType Descriptor::getType() const {
359359

360360
QualType Descriptor::getElemQualType() const {
361361
assert(isArray());
362-
const auto *AT = cast<ArrayType>(getType());
363-
return AT->getElementType();
362+
QualType T = getType();
363+
if (const auto *AT = T->getAsArrayTypeUnsafe())
364+
return AT->getElementType();
365+
if (const auto *CT = T->getAs<ComplexType>())
366+
return CT->getElementType();
367+
if (const auto *CT = T->getAs<VectorType>())
368+
return CT->getElementType();
369+
llvm_unreachable("Array that's not an array/complex/vector type?");
364370
}
365371

366372
SourceLocation Descriptor::getLocation() const {

clang/test/AST/Interp/vectors.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ namespace VectorElementExpr {
8181
static_assert(twoElts.x == 22, ""); // ref-error {{not an integral constant expression}}
8282
static_assert(twoElts.y == 33, ""); // ref-error {{not an integral constant expression}}
8383
}
84+
85+
namespace Temporaries {
86+
typedef __attribute__((vector_size(16))) int vi4a;
87+
typedef __attribute__((ext_vector_type(4))) int vi4b;
88+
struct S {
89+
vi4a v;
90+
vi4b w;
91+
};
92+
int &&s = S().w[1];
93+
}

0 commit comments

Comments
 (0)