Merged in r293653.

Thanks,
Hans

On Mon, Jan 30, 2017 at 7:16 PM, Akira Hatanaka <ahatan...@apple.com> wrote:
> Hans, can this be merged to 4.0? This fixes a regression from 3.9 (the part I 
> touched was committed a few years ago, but didn’t cause an assert until 
> recently).
>
>> On Jan 30, 2017, at 6:31 PM, Akira Hatanaka via cfe-commits 
>> <cfe-commits@lists.llvm.org> wrote:
>>
>> Author: ahatanak
>> Date: Mon Jan 30 20:31:39 2017
>> New Revision: 293596
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=293596&view=rev
>> Log:
>> Handle ObjCEncodeExpr in extractStringLiteralCharacter.
>>
>> This fixes an assertion failure that occurs later in the function when
>> an ObjCEncodeExpr is cast to StringLiteral.
>>
>> rdar://problem/30111207
>>
>> Modified:
>>    cfe/trunk/lib/AST/ExprConstant.cpp
>>    cfe/trunk/test/CodeGenObjC/encode-test.m
>>
>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=293596&r1=293595&r2=293596&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jan 30 20:31:39 2017
>> @@ -2394,7 +2394,14 @@ static unsigned getBaseIndex(const CXXRe
>> /// Extract the value of a character from a string literal.
>> static APSInt extractStringLiteralCharacter(EvalInfo &Info, const Expr *Lit,
>>                                             uint64_t Index) {
>> -  // FIXME: Support ObjCEncodeExpr, MakeStringConstant
>> +  // FIXME: Support MakeStringConstant
>> +  if (const auto *ObjCEnc = dyn_cast<ObjCEncodeExpr>(Lit)) {
>> +    std::string Str;
>> +    Info.Ctx.getObjCEncodingForType(ObjCEnc->getEncodedType(), Str);
>> +    assert(Index <= Str.size() && "Index too large");
>> +    return APSInt::getUnsigned(Str.c_str()[Index]);
>> +  }
>> +
>>   if (auto PE = dyn_cast<PredefinedExpr>(Lit))
>>     Lit = PE->getFunctionName();
>>   const StringLiteral *S = cast<StringLiteral>(Lit);
>>
>> Modified: cfe/trunk/test/CodeGenObjC/encode-test.m
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test.m?rev=293596&r1=293595&r2=293596&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenObjC/encode-test.m (original)
>> +++ cfe/trunk/test/CodeGenObjC/encode-test.m Mon Jan 30 20:31:39 2017
>> @@ -180,3 +180,14 @@ const char g14[] = @encode(__typeof__(*t
>>
>> // CHECK: @g15 = constant [2 x i8] c":\00"
>> const char g15[] = @encode(SEL);
>> +
>> +typedef typeof(sizeof(int)) size_t;
>> +size_t strlen(const char *s);
>> +
>> +// CHECK-LABEL: @test_strlen(
>> +// CHECK: %[[i:.*]] = alloca i32
>> +// CHECK: store i32 1, i32* %[[i]]
>> +void test_strlen() {
>> +  const char array[] = @encode(int);
>> +  int i = strlen(array);
>> +}
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to