Author: Timm Baeder Date: 2025-01-29T16:39:02+01:00 New Revision: a34a087fc59779c53512eda094e1ca914a4526f2
URL: https://github.com/llvm/llvm-project/commit/a34a087fc59779c53512eda094e1ca914a4526f2 DIFF: https://github.com/llvm/llvm-project/commit/a34a087fc59779c53512eda094e1ca914a4526f2.diff LOG: [clang][bytecode] Handle non-primitive vector element types (#124926) By rejecting them. We would crash before. Added: clang/test/AST/ByteCode/neon.c Modified: clang/lib/AST/ByteCode/Program.cpp Removed: ################################################################################ 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