diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 5fab58a5af953d72cf049489957116c8a7cb28af..6a6baf96ad376aad7cef8cb006850ef398f8b5d3 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -2362,7 +2362,14 @@ static unsigned getBaseIndex(const CXXRecordDecl *Derived, /// 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); diff --git a/test/CodeGenObjC/encode-test.m b/test/CodeGenObjC/encode-test.m index 7f0e76fc3ffd4deb1d9b52c923a6582e848b2d56..a1f88e05250a9488629a83415e8d635edc7318f9 100644 --- a/test/CodeGenObjC/encode-test.m +++ b/test/CodeGenObjC/encode-test.m @@ -180,3 +180,14 @@ const char g14[] = @encode(__typeof__(*test_id)); // 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); +}