[PATCH] D58729: Emit boxed expression as a compile-time constant if the expression inside the parentheses is a string literal

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 27 12:50:21 PST 2019


rjmccall added inline comments.


================
Comment at: lib/CodeGen/CGExprConstant.cpp:1793
+         "this boxed expression can't be emitted as a compile-time constant");
+  return emitConstantObjCStringLiteral(cast<StringLiteral>(E->getSubExpr()),
+                                       E->getType(), CGM);
----------------
`IgnoreParens`.


================
Comment at: lib/Sema/SemaExprObjC.cpp:534
+            NSStringPointer, NSStringPointer);
+        return new (Context) ObjCBoxedExpr(SL, BoxedType, nullptr, SR);
+      }
----------------
You're implicitly dropping sugar from the source expression here; I really think you should preserve that, and if it means you end up having to look through array-decay expressions, that's not the end of the world.

The need for a special case here is just to allow us to compile these even if there isn't a boxing method available?

Do you need to restrict the type of the string literal so that it doesn't apply to e.g. wide strings?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58729/new/

https://reviews.llvm.org/D58729





More information about the cfe-commits mailing list