[clang] ae41232 - [clang][Interp] Fix Descriptor::getElemQualType() for complex/vectors
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 21 00:34:39 PDT 2024
Author: Timm Bäder
Date: 2024-06-21T09:34:18+02:00
New Revision: ae41232191ec73b5ee96e5f21df99a42ca25d626
URL: https://github.com/llvm/llvm-project/commit/ae41232191ec73b5ee96e5f21df99a42ca25d626
DIFF: https://github.com/llvm/llvm-project/commit/ae41232191ec73b5ee96e5f21df99a42ca25d626.diff
LOG: [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.
Added:
Modified:
clang/lib/AST/Interp/Descriptor.cpp
clang/test/AST/Interp/vectors.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp
index d20ab1340c890..fcb778f7aeab0 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -359,8 +359,14 @@ QualType Descriptor::getType() const {
QualType Descriptor::getElemQualType() const {
assert(isArray());
- const auto *AT = cast<ArrayType>(getType());
- return AT->getElementType();
+ QualType T = getType();
+ if (const auto *AT = T->getAsArrayTypeUnsafe())
+ return AT->getElementType();
+ if (const auto *CT = T->getAs<ComplexType>())
+ return CT->getElementType();
+ if (const auto *CT = T->getAs<VectorType>())
+ return CT->getElementType();
+ llvm_unreachable("Array that's not an array/complex/vector type?");
}
SourceLocation Descriptor::getLocation() const {
diff --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp
index 61c400b57b3f8..6991a348b07a9 100644
--- a/clang/test/AST/Interp/vectors.cpp
+++ b/clang/test/AST/Interp/vectors.cpp
@@ -81,3 +81,13 @@ namespace VectorElementExpr {
static_assert(twoElts.x == 22, ""); // ref-error {{not an integral constant expression}}
static_assert(twoElts.y == 33, ""); // ref-error {{not an integral constant expression}}
}
+
+namespace Temporaries {
+ typedef __attribute__((vector_size(16))) int vi4a;
+ typedef __attribute__((ext_vector_type(4))) int vi4b;
+ struct S {
+ vi4a v;
+ vi4b w;
+ };
+ int &&s = S().w[1];
+}
More information about the cfe-commits
mailing list