r227115 - Fix assert instantiating string init of static variable

Ben Langmuir blangmuir at apple.com
Mon Jan 26 12:03:14 PST 2015


> On Jan 26, 2015, at 11:43 AM, Richard Smith <richard at metafoo.co.uk> wrote:
> 
> On Mon, Jan 26, 2015 at 11:04 AM, Ben Langmuir <blangmuir at apple.com <mailto:blangmuir at apple.com>> wrote:
>> Author: benlangmuir
>> Date: Mon Jan 26 13:04:10 2015
>> New Revision: 227115
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=227115&view=rev
>> Log:
>> Fix assert instantiating string init of static variable
>> 
>> ... when the variable's type is a typedef of a ConstantArrayType. Just
>> look through the typedef (and any other sugar).  We only use the
>> constant array type here to get the element count.
>> 
>> Modified:
>>    cfe/trunk/lib/Sema/SemaInit.cpp
>>    cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
>> 
>> Modified: cfe/trunk/lib/Sema/SemaInit.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=227115&r1=227114&r2=227115&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Sema/SemaInit.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Jan 26 13:04:10 2015
>> @@ -149,9 +149,9 @@ static void updateStringLiteralType(Expr
>> static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
>>                             Sema &S) {
>>   // Get the length of the string as parsed.
>> -  uint64_t StrLength =
>> -    cast<ConstantArrayType>(Str->getType())->getSize().getZExtValue();
>> -
>> +  auto *ConstantArrayTy =
>> +      cast<ConstantArrayType>(Str->getType()->getUnqualifiedDesugaredType());
> 
> Please use getAsArrayTypeUnsafe() instead of getUnqualifiedDesugaredType() here.

Thanks for the review.  Fixed in r227129

Ben

> 
>> +  uint64_t StrLength = ConstantArrayTy->getSize().getZExtValue();
>> 
>>   if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) {
>>     // C99 6.7.8p14. We have an array of character type with unknown size
>> 
>> Modified: cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp?rev=227115&r1=227114&r2=227115&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp (original)
>> +++ cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp Mon Jan 26 13:04:10 2015
>> @@ -114,3 +114,15 @@ namespace PR6449 {
>>   template class X1<char>;
>> 
>> }
>> +
>> +typedef char MyString[100];
>> +template <typename T>
>> +struct StaticVarWithTypedefString {
>> +  static MyString str;
>> +};
>> +template <typename T>
>> +MyString StaticVarWithTypedefString<T>::str = "";
>> +
>> +void testStaticVarWithTypedefString() {
>> +  (void)StaticVarWithTypedefString<int>::str;
>> +}
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150126/16b4d006/attachment.html>


More information about the cfe-commits mailing list