Author: Joe Ellis Date: 2021-02-23T13:40:58Z New Revision: 1b1b30cf0f7d9619afb32e16f4a7c007da4ffccf
URL: https://github.com/llvm/llvm-project/commit/1b1b30cf0f7d9619afb32e16f4a7c007da4ffccf DIFF: https://github.com/llvm/llvm-project/commit/1b1b30cf0f7d9619afb32e16f4a7c007da4ffccf.diff LOG: [clang][SVE] Don't warn on vector to sizeless builtin implicit conversion This commit prevents warnings from -Wconversion when a clang vector type is implicitly converted to a sizeless builtin type -- for example, when implicitly converting a fixed-predicate to a scalable predicate. The code below: 1 #include <arm_sve.h> 2 3 #define N __ARM_FEATURE_SVE_BITS 4 #define FIXED_ATTR __attribute__((arm_sve_vector_bits (N))) 5 typedef svbool_t fixed_svbool_t FIXED_ATTR; 6 7 inline fixed_svbool_t foo(fixed_svbool_t p) { 8 return svnot_z(svptrue_b64(), p); 9 } would previously raise this warning: warning: implicit conversion turns vector to scalar: \ 'fixed_svbool_t' (vector of 8 'unsigned char' values) to 'svbool_t' \ (aka '__SVBool_t') [-Wconversion] Note that many cases of these implicit conversions were already permitted because many functions inside arm_sve.h are spawned via preprocessor macros, and the call to isInSystemMacro would cover us in this case. This commit fixes the remaining cases. Differential Revision: https://reviews.llvm.org/D97053 Added: Modified: clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 2d3d36f4adad..b41d94361d50 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -12051,7 +12051,16 @@ static void CheckImplicitConversion(Sema &S, Expr *E, QualType T, checkObjCDictionaryLiteral(S, QualType(Target, 0), DictionaryLiteral); // Strip vector types. - if (isa<VectorType>(Source)) { + if (const auto *SourceVT = dyn_cast<VectorType>(Source)) { + if (Target->isVLSTBuiltinType()) { + auto SourceVectorKind = SourceVT->getVectorKind(); + if (SourceVectorKind == VectorType::SveFixedLengthDataVector || + SourceVectorKind == VectorType::SveFixedLengthPredicateVector || + (SourceVectorKind == VectorType::GenericVector && + S.Context.getTypeSize(Source) == S.getLangOpts().ArmSveVectorBits)) + return; + } + if (!isa<VectorType>(Target)) { if (S.SourceMgr.isInSystemMacro(CC)) return; diff --git a/clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp b/clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp index 5e796b7c8995..0437a264f65b 100644 --- a/clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp +++ b/clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns -Wconversion %s // expected-no-diagnostics #include <stdint.h> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits