[clang] [ObjC] Emit number, array, and dictionary literals as constants (PR #185130)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 6 16:55:10 PST 2026


================
@@ -47,20 +47,46 @@ namespace clang {
 class ASTContext;
 class CXXBaseSpecifier;
 
+/// Base class for Objective-C object literals (@"...", @42, @[], @{}).
+class ObjCObjectLiteral : public Expr {
+protected:
+  ObjCObjectLiteral(StmtClass SC, QualType T, bool ECI, ExprValueKind VK,
+                    ExprObjectKind OK)
+      : Expr(SC, T, VK, OK) {
+    setDependence(ExprDependence::None);
+    ObjCObjectLiteralBits.IsExpressibleAsConstantInitializer = ECI;
+  }
+  explicit ObjCObjectLiteral(StmtClass SC, EmptyShell Empty)
+      : Expr(SC, Empty) {}
+
+public:
+  bool isGlobalAllocation() const {
+    return isExpressibleAsConstantInitializer();
+  }
+  bool isExpressibleAsConstantInitializer() const {
+    return ObjCObjectLiteralBits.IsExpressibleAsConstantInitializer;
+  }
+  void setExpressibleAsConstantInitializer(bool ECI) {
----------------
ojhunt wrote:

To be clear, ECI seems fine here courtesy of the method name

https://github.com/llvm/llvm-project/pull/185130


More information about the cfe-commits mailing list