eopXD updated this revision to Diff 533961. eopXD added a comment. Extract RVV type check as a separate function as Craig has commented. Add test case from Aaron's comment.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D153510/new/ https://reviews.llvm.org/D153510 Files: clang/include/clang/Sema/Sema.h clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaDecl.cpp clang/test/Sema/riscv-types.c clang/test/Sema/riscv-vector-float16-check.c clang/test/Sema/riscv-vector-float32-check.c clang/test/Sema/riscv-vector-float64-check.c clang/test/Sema/riscv-vector-int64-check.c
Index: clang/test/Sema/riscv-vector-int64-check.c =================================================================== --- clang/test/Sema/riscv-vector-int64-check.c +++ clang/test/Sema/riscv-vector-int64-check.c @@ -6,3 +6,9 @@ vint64m1_t foo() { /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */ } /* expected-warning {{non-void function does not return a value}}*/ + +void bar(void) { + vint64m1_t i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */ + + (void)i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */ +} Index: clang/test/Sema/riscv-vector-float64-check.c =================================================================== --- clang/test/Sema/riscv-vector-float64-check.c +++ clang/test/Sema/riscv-vector-float64-check.c @@ -6,3 +6,9 @@ vfloat64m1_t foo() { /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */ } /* expected-warning {{non-void function does not return a value}}*/ + +void bar(void) { + vfloat64m1_t f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */ + + (void)f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */ +} Index: clang/test/Sema/riscv-vector-float32-check.c =================================================================== --- clang/test/Sema/riscv-vector-float32-check.c +++ clang/test/Sema/riscv-vector-float32-check.c @@ -6,3 +6,9 @@ vfloat32m1_t foo() { /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */ } /* expected-warning {{non-void function does not return a value}}*/ + +void bar(void) { + vfloat32m1_t f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */ + + (void)f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */ +} Index: clang/test/Sema/riscv-vector-float16-check.c =================================================================== --- clang/test/Sema/riscv-vector-float16-check.c +++ clang/test/Sema/riscv-vector-float16-check.c @@ -6,3 +6,9 @@ vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */ } /* expected-warning {{non-void function does not return a value}}*/ + +void bar(void) { + vfloat16m1_t f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */ + + (void)f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */ +} Index: clang/test/Sema/riscv-types.c =================================================================== --- clang/test/Sema/riscv-types.c +++ clang/test/Sema/riscv-types.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple riscv64 -target-feature +v -ast-print %s \ -// RUN: | FileCheck %s +// RUN: %clang_cc1 -triple riscv64 -target-feature +v \ +// RUN: -target-feature +experimental-zvfh -ast-print %s | FileCheck %s void bar(void) { // CHECK: __rvv_int64m1_t x0; Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -8769,6 +8769,8 @@ return; } } + if (T->isRVVType()) + checkRVVTypeSupport(T, NewVD->getLocation(), cast<ValueDecl>(CurContext)); } /// Perform semantic checking on a newly-created variable Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -4964,6 +4964,22 @@ return false; } +void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) { + const TargetInfo &TI = Context.getTargetInfo(); + if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) && + !TI.hasFeature("zve64x")) + Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x"; + if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) && + !TI.hasFeature("experimental-zvfh")) + Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zvfh"; + if (Ty->isRVVType(/* Bitwidth */ 32, /* IsFloat */ true) && + !TI.hasFeature("zve32f")) + Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve32f"; + if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ true) && + !TI.hasFeature("zve64d")) + Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64d"; +} + bool Sema::CheckNVPTXBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, CallExpr *TheCall) { Index: clang/lib/Sema/Sema.cpp =================================================================== --- clang/lib/Sema/Sema.cpp +++ clang/lib/Sema/Sema.cpp @@ -2048,20 +2048,8 @@ targetDiag(D->getLocation(), diag::note_defined_here, FD) << D; } - // RISC-V vector builtin types (RISCVVTypes.def) - if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) && - !TI.hasFeature("zve64x")) - Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zve64x"; - if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) && - !TI.hasFeature("experimental-zvfh")) - Diag(Loc, diag::err_riscv_type_requires_extension, FD) - << Ty << "zvfh"; - if (Ty->isRVVType(/* Bitwidth */ 32, /* IsFloat */ true) && - !TI.hasFeature("zve32f")) - Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zve32f"; - if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ true) && - !TI.hasFeature("zve64d")) - Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zve64d"; + if (Ty->isRVVType()) + checkRVVTypeSupport(Ty, Loc, D); // Don't allow SVE types in functions without a SVE target. if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) { Index: clang/include/clang/Sema/Sema.h =================================================================== --- clang/include/clang/Sema/Sema.h +++ clang/include/clang/Sema/Sema.h @@ -13571,6 +13571,7 @@ bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum); bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, CallExpr *TheCall); + void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D); bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, CallExpr *TheCall); bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits