Skip to content

Commit a34a087

Browse files
authored
[clang][bytecode] Handle non-primitive vector element types (#124926)
By rejecting them. We would crash before.
1 parent 0c63ec5 commit a34a087

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,21 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
453453

454454
// Complex types - represented as arrays of elements.
455455
if (const auto *CT = Ty->getAs<ComplexType>()) {
456-
PrimType ElemTy = *Ctx.classify(CT->getElementType());
457-
return allocateDescriptor(D, ElemTy, MDSize, 2, IsConst, IsTemporary,
456+
std::optional<PrimType> ElemTy = Ctx.classify(CT->getElementType());
457+
if (!ElemTy)
458+
return nullptr;
459+
460+
return allocateDescriptor(D, *ElemTy, MDSize, 2, IsConst, IsTemporary,
458461
IsMutable);
459462
}
460463

461464
// Same with vector types.
462465
if (const auto *VT = Ty->getAs<VectorType>()) {
463-
PrimType ElemTy = *Ctx.classify(VT->getElementType());
464-
return allocateDescriptor(D, ElemTy, MDSize, VT->getNumElements(), IsConst,
466+
std::optional<PrimType> ElemTy = Ctx.classify(VT->getElementType());
467+
if (!ElemTy)
468+
return nullptr;
469+
470+
return allocateDescriptor(D, *ElemTy, MDSize, VT->getNumElements(), IsConst,
465471
IsTemporary, IsMutable);
466472
}
467473

clang/test/AST/ByteCode/neon.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -disable-O0-optnone -emit-llvm -o - %s -fexperimental-new-constant-interpreter
2+
3+
// REQUIRES: aarch64-registered-target
4+
5+
/// This just tests that we're not crashing with a non-primitive vector element type.
6+
7+
typedef __mfp8 mfloat8_t;
8+
typedef __bf16 bfloat16_t;
9+
10+
typedef __attribute__((neon_vector_type(8))) mfloat8_t mfloat8x8_t;
11+
typedef __attribute__((neon_vector_type(8))) bfloat16_t bfloat16x8_t;
12+
13+
typedef __UINT64_TYPE__ fpm_t;
14+
#define __ai static __inline__ __attribute__((__always_inline__, __nodebug__))
15+
__ai __attribute__((target("fp8,neon"))) bfloat16x8_t vcvt1_bf16_mf8_fpm(mfloat8x8_t __p0, fpm_t __p1) {
16+
bfloat16x8_t __ret;
17+
__ret = (bfloat16x8_t) __builtin_neon_vcvt1_bf16_mf8_fpm(__p0, __p1);
18+
return __ret;
19+
}

0 commit comments

Comments
 (0)