From 88c63daab3edd0f76729cbf69bf9bad0a7844136 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 4 Apr 2014 19:33:39 +0000 Subject: [PATCH] Vector [Sema]. Vector "splats" which are truncated should have a warning with -Wconversion. // rdar://16502418 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205646 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 11 ++++++++++- test/Sema/conversion.c | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 93c5cac6b0..9cd44d2cae 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -6113,11 +6113,20 @@ void CheckConditionalOperator(Sema &S, ConditionalOperator *E, /// implicit conversions in the given expression. There are a couple /// of competing diagnostics here, -Wconversion and -Wsign-compare. void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC) { - QualType T = OrigE->getType(); Expr *E = OrigE->IgnoreParenImpCasts(); if (E->isTypeDependent() || E->isValueDependent()) return; + + QualType T = OrigE->getType(); + // Check for conversion from an arithmetic type to a vector of arithmetic + // type elements. Warn if this results in truncation of each vector element. + if (isa(E)) { + if (ImplicitCastExpr *ICE = dyn_cast(OrigE)) + if ((ICE->getCastKind() == CK_VectorSplat) && + !T.isNull() && T->isExtVectorType()) + T = cast(T.getCanonicalType())->getElementType(); + } // For conditional operators, we analyze the arguments as if they // were being fed directly into the output. diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index a591ac0eef..121f2d40bb 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -417,3 +417,15 @@ void test26(int si, long sl) { si = si / sl; si = sl / si; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}} } + +// rdar://16502418 +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef __attribute__ ((ext_vector_type(16),__aligned__(32))) uint16_t ushort16; +typedef __attribute__ ((ext_vector_type( 8),__aligned__( 32))) uint32_t uint8; + +void test27(ushort16 constants) { + uint8 pairedConstants = (uint8) constants; + ushort16 crCbScale = pairedConstants.s4; // expected-warning {{implicit conversion loses integer precision: 'uint32_t' (aka 'unsigned int') to 'unsigned short'}} + ushort16 brBias = pairedConstants.s6; // expected-warning {{implicit conversion loses integer precision: 'uint32_t' (aka 'unsigned int') to 'unsigned short'}} +} -- 2.40.0