Commit 1b8468f0 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r293596:

------------------------------------------------------------------------
r293596 | ahatanak | 2017-01-30 18:31:39 -0800 (Mon, 30 Jan 2017) | 7 lines

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

------------------------------------------------------------------------


git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_40@293653 91177308-0d34-0410-b5e6-96231b3b80d8
parent 7bf54fb3
......@@ -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);
......
......@@ -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);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment