summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorEli Friedman <efriedma@quicinc.com>2019-02-08 21:18:46 +0000
committerEli Friedman <efriedma@quicinc.com>2019-02-08 21:18:46 +0000
commit3bf72d7d64b8465acd4f4af1a469d68d9dc86058 (patch)
tree1ef27b84d2b770c22d76b641a6e0c0446e14b7c4 /clang/lib/Sema/SemaInit.cpp
parent57e60a501ed20f0e6483bad9535fac93312b8e77 (diff)
downloadbcm5719-llvm-3bf72d7d64b8465acd4f4af1a469d68d9dc86058.tar.gz
bcm5719-llvm-3bf72d7d64b8465acd4f4af1a469d68d9dc86058.zip
[Sema] Make string literal init an rvalue.
This allows substantially simplifying the expression evaluation code, because we don't have to special-case lvalues which are actually string literal initialization. This currently throws away an optimization where we would avoid creating an array APValue for string literal initialization. If we really want to optimize this case, we should fix APValue so it can store simple arrays more efficiently, like llvm::ConstantDataArray. This shouldn't affect the memory usage for other string literals. (Not sure if this is a blocker; I don't think string literal init is common enough for this to be a serious issue, but I could be wrong.) The change to test/CodeGenObjC/encode-test.m is a weird side-effect of these changes: we currently don't constant-evaluate arrays in C, so the strlen call shouldn't be folded, but lvalue string init managed to get around that check. I this this is fine. Fixes https://bugs.llvm.org/show_bug.cgi?id=40430 . llvm-svn: 353569
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r--clang/lib/Sema/SemaInit.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 3f6bb069df7..59aa42078b5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -144,6 +144,7 @@ static StringInitFailureKind IsStringInit(Expr *init, QualType declType,
static void updateStringLiteralType(Expr *E, QualType Ty) {
while (true) {
E->setType(Ty);
+ E->setValueKind(VK_RValue);
if (isa<StringLiteral>(E) || isa<ObjCEncodeExpr>(E))
break;
else if (ParenExpr *PE = dyn_cast<ParenExpr>(E))
OpenPOWER on IntegriCloud