https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/124926
By rejecting them. We would crash before. >From bd1f50f8ef4ea1139f3058b1c24a71e9cbee0823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 29 Jan 2025 15:24:51 +0100 Subject: [PATCH] [clang][bytecode] Handle non-primitive vector element types By rejecting them. We would crash before. --- clang/lib/AST/ByteCode/Program.cpp | 14 ++++++++++---- clang/test/AST/ByteCode/neon.c | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 clang/test/AST/ByteCode/neon.c diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index 7d8862d606ba3c..1ffe7cd721f11f 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -453,15 +453,21 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, // Complex types - represented as arrays of elements. if (const auto *CT = Ty->getAs<ComplexType>()) { - PrimType ElemTy = *Ctx.classify(CT->getElementType()); - return allocateDescriptor(D, ElemTy, MDSize, 2, IsConst, IsTemporary, + std::optional<PrimType> ElemTy = Ctx.classify(CT->getElementType()); + if (!ElemTy) + return nullptr; + + return allocateDescriptor(D, *ElemTy, MDSize, 2, IsConst, IsTemporary, IsMutable); } // Same with vector types. if (const auto *VT = Ty->getAs<VectorType>()) { - PrimType ElemTy = *Ctx.classify(VT->getElementType()); - return allocateDescriptor(D, ElemTy, MDSize, VT->getNumElements(), IsConst, + std::optional<PrimType> ElemTy = Ctx.classify(VT->getElementType()); + if (!ElemTy) + return nullptr; + + return allocateDescriptor(D, *ElemTy, MDSize, VT->getNumElements(), IsConst, IsTemporary, IsMutable); } diff --git a/clang/test/AST/ByteCode/neon.c b/clang/test/AST/ByteCode/neon.c new file mode 100644 index 00000000000000..5905d780860399 --- /dev/null +++ b/clang/test/AST/ByteCode/neon.c @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -disable-O0-optnone -emit-llvm -o - %s -fexperimental-new-constant-interpreter + +// REQUIRES: aarch64-registered-target + +/// This just tests that we're not crashing with a non-primitive vector element type. + +typedef __mfp8 mfloat8_t; +typedef __bf16 bfloat16_t; + +typedef __attribute__((neon_vector_type(8))) mfloat8_t mfloat8x8_t; +typedef __attribute__((neon_vector_type(8))) bfloat16_t bfloat16x8_t; + +typedef __UINT64_TYPE__ fpm_t; +#define __ai static __inline__ __attribute__((__always_inline__, __nodebug__)) +__ai __attribute__((target("fp8,neon"))) bfloat16x8_t vcvt1_bf16_mf8_fpm(mfloat8x8_t __p0, fpm_t __p1) { + bfloat16x8_t __ret; + __ret = (bfloat16x8_t) __builtin_neon_vcvt1_bf16_mf8_fpm(__p0, __p1); + return __ret; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits