Author: Amr Hesham Date: 2025-12-20T19:30:27+01:00 New Revision: 46902a71f332c812c4471e8730ffbf7c446104df
URL: https://github.com/llvm/llvm-project/commit/46902a71f332c812c4471e8730ffbf7c446104df DIFF: https://github.com/llvm/llvm-project/commit/46902a71f332c812c4471e8730ffbf7c446104df.diff LOG: [CIR] Add sizeof for fixed vector type (#172861) Add sizeof for fixed vector type and Mark sizeof & alignof as NYI for scalable Vector as it depends on using llvm.vscale not just the vector size Added: Modified: clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index dbd67b367ec4c..a06f1f1dc1784 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -2576,6 +2576,19 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr( return builder.getConstant( loc, cir::IntAttr::get(cgf.cgm.uInt64Ty, llvm::APSInt(llvm::APInt(64, 1), true))); + } else if (e->getKind() == UETT_VectorElements) { + auto vecTy = cast<cir::VectorType>(convertType(e->getTypeOfArgument())); + if (vecTy.getIsScalable()) { + cgf.getCIRGenModule().errorNYI( + e->getSourceRange(), + "VisitUnaryExprOrTypeTraitExpr: sizeOf scalable vector"); + return builder.getConstant( + loc, cir::IntAttr::get(cgf.cgm.uInt64Ty, + e->EvaluateKnownConstInt(cgf.getContext()))); + } + + return builder.getConstant( + loc, cir::IntAttr::get(cgf.cgm.uInt64Ty, vecTy.getSize())); } return builder.getConstant( diff --git a/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp b/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp index 071c52a0918e3..3669c45059bd4 100644 --- a/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp +++ b/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp @@ -7,20 +7,26 @@ void foo() { unsigned long i = sizeof(int); // CHECK: cir.const #cir.int<4> : !u64i - unsigned long l = sizeof(long); + unsigned long l = sizeof(long); // CHECK: cir.const #cir.int<8> : !u64i - unsigned long f = sizeof(float); + unsigned long f = sizeof(float); // CHECK: cir.const #cir.int<4> : !u64i - unsigned long d = sizeof(double); + unsigned long d = sizeof(double); // CHECK: cir.const #cir.int<8> : !u64i unsigned long iArr = sizeof(int[5]); // CHECK: cir.const #cir.int<20> : !u64i - unsigned long dArr = sizeof(double[5]); + unsigned long dArr = sizeof(double[5]); // CHECK: cir.const #cir.int<40> : !u64i + + unsigned long vi4 = sizeof(int __attribute__((vector_size(4)))); + // CHECK: cir.const #cir.int<4> : !u64i + + unsigned long evi4 = sizeof(int __attribute__((ext_vector_type(4)))); + // CHECK: cir.const #cir.int<16> : !u64i } void foo2() { @@ -30,18 +36,24 @@ void foo2() { unsigned long i = alignof(int); // CHECK: cir.const #cir.int<4> : !u64i - unsigned long l = alignof(long); + unsigned long l = alignof(long); // CHECK: cir.const #cir.int<8> : !u64i - unsigned long f = alignof(float); + unsigned long f = alignof(float); // CHECK: cir.const #cir.int<4> : !u64i - unsigned long d = alignof(double); + unsigned long d = alignof(double); // CHECK: cir.const #cir.int<8> : !u64i unsigned long iArr = alignof(int[5]); // CHECK: cir.const #cir.int<4> : !u64i - unsigned long dArr = alignof(double[5]); + unsigned long dArr = alignof(double[5]); // CHECK: cir.const #cir.int<8> : !u64i + + unsigned long vi4 = alignof(int __attribute__((vector_size(4)))); + // CHECK: cir.const #cir.int<4> : !u64i + + unsigned long evi4 = alignof(int __attribute__((ext_vector_type(4)))); + // CHECK: cir.const #cir.int<16> : !u64i } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
