r205646 - Vector [Sema]. Vector "splats" which are truncated should have a warning

Steve Canon scanon at apple.com
Fri Apr 4 17:58:52 PDT 2014


I added a warning with r205521, for this and some other scalar->vector conversions.

-- Steve

Sent from my iPhone

> On Apr 4, 2014, at 8:14 PM, jahanian <fjahanian at apple.com> wrote:
> 
> This is strange. Before my patch, there was no warning for my test. This was the reason behind the patch.
> If my patch is no longer needed due to other changes which took place while I was fixing this,  I can take it out.
> 
> - Fariborz
> 
> 
>> On Apr 4, 2014, at 3:05 PM, Stephen Canon <scanon at apple.com> wrote:
>> 
>> Hi Fariborz --
>> 
>> Before this patch, we were generating the following warning for your test case:
>> 
>>    implicit conversion loses integer precision: 'uint32_t' (aka 'unsigned int') to 'ushort16'
>> 
>> with your patch, we get the following instead:
>> 
>>    implicit conversion loses integer precision: 'uint32_t' (aka 'unsigned int') to 'unsigned short'
>> 
>> I have a slight preference for the warning we used to issue, as it refers to the conversion that actually takes place conceptually (scalar -> vector), rather than the "subconversion" that changes the value (scalar -> vector element).  Reasonable people may disagree, of course.
>> 
>> – Steve
>> 
>>> On Apr 4, 2014, at 3:33 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>>> 
>>> Author: fjahanian
>>> Date: Fri Apr  4 14:33:39 2014
>>> New Revision: 205646
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=205646&view=rev
>>> Log:
>>> Vector [Sema]. Vector "splats" which are truncated should have a warning
>>> with -Wconversion. // rdar://16502418
>>> 
>>> Modified:
>>>  cfe/trunk/lib/Sema/SemaChecking.cpp
>>>  cfe/trunk/test/Sema/conversion.c
>>> 
>>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=205646&r1=205645&r2=205646&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Apr  4 14:33:39 2014
>>> @@ -6113,11 +6113,20 @@ void CheckConditionalOperator(Sema &S, C
>>> /// 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<ExtVectorElementExpr>(E)) {
>>> +    if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(OrigE))
>>> +      if ((ICE->getCastKind() == CK_VectorSplat) &&
>>> +          !T.isNull() && T->isExtVectorType())
>>> +        T = cast<ExtVectorType>(T.getCanonicalType())->getElementType();
>>> +  }
>>> 
>>> // For conditional operators, we analyze the arguments as if they
>>> // were being fed directly into the output.
>>> 
>>> Modified: cfe/trunk/test/Sema/conversion.c
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/conversion.c?rev=205646&r1=205645&r2=205646&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/test/Sema/conversion.c (original)
>>> +++ cfe/trunk/test/Sema/conversion.c Fri Apr  4 14:33:39 2014
>>> @@ -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'}}
>>> +}
>>> 
>>> 
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 




More information about the cfe-commits mailing list