Page MenuHomePhabricator

[Sema] Make string literal init an rvalue.

Authored by efriedma on Feb 7 2019, 6:00 PM.



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 .

Diff Detail

rC Clang

Event Timeline

efriedma created this revision.Feb 7 2019, 6:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2019, 6:00 PM
rsmith accepted this revision.Feb 8 2019, 12:46 PM

Thanks, this is a much cleaner model than having two different APValue representations for arrays.

This revision is now accepted and ready to land.Feb 8 2019, 12:46 PM