[clang] [Driver] Disable -fobjc-constant-literals by default (PR #195000)

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 21:26:19 PDT 2026


https://github.com/ahatanak created https://github.com/llvm/llvm-project/pull/195000

Disable the feature by default in the driver so it is no longer implicitly enabled for ObjC compilations as there are unresolved issues (see https://github.com/llvm/llvm-project/pull/185130#issuecomment-4298886165). Users can still opt in explicitly with -fobjc-constant-literals.

>From 8d2eda39f7e33b6eb62a7e6a99a42fff940634a2 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka <ahatanak at gmail.com>
Date: Wed, 29 Apr 2026 17:23:43 -0700
Subject: [PATCH] [Driver] Disable -fobjc-constant-literals by default

Disable the feature by default in the driver so it is no longer
implicitly enabled for ObjC compilations as there are unresolved
issues (see https://github.com/llvm/llvm-project/pull/185130#issuecomment-4298886165).
Users can still opt in explicitly with -fobjc-constant-literals.
---
 clang/lib/Driver/ToolChains/Clang.cpp      |  2 +-
 clang/test/Driver/objc-constant-literals.m | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/objc-constant-literals.m

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index cfa3031431498..bdffa4fdd7e6b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4278,7 +4278,7 @@ static void RenderObjCOptions(const ToolChain &TC, const Driver &D,
     bool EnableConstantLiterals =
         Args.hasFlag(options::OPT_fobjc_constant_literals,
                      options::OPT_fno_objc_constant_literals,
-                     /*default=*/true) &&
+                     /*default=*/false) &&
         Runtime.hasConstantLiteralClasses();
     if (EnableConstantLiterals)
       CmdArgs.push_back("-fobjc-constant-literals");
diff --git a/clang/test/Driver/objc-constant-literals.m b/clang/test/Driver/objc-constant-literals.m
new file mode 100644
index 0000000000000..7903028d00541
--- /dev/null
+++ b/clang/test/Driver/objc-constant-literals.m
@@ -0,0 +1,21 @@
+// RUN: %clang -### -target arm64-apple-macosx11 -c %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang -### -target arm64-apple-macosx11 -fobjc-constant-literals -c %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=ENABLED
+// RUN: %clang -### -target arm64-apple-macosx11 -fno-objc-constant-literals -c %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DISABLED
+
+// DEFAULT-NOT: -fobjc-constant-literals
+// DEFAULT-NOT: -fconstant-nsnumber-literals
+// DEFAULT-NOT: -fconstant-nsarray-literals
+// DEFAULT-NOT: -fconstant-nsdictionary-literals
+
+// ENABLED: -fobjc-constant-literals
+// ENABLED: -fconstant-nsnumber-literals
+// ENABLED: -fconstant-nsarray-literals
+// ENABLED: -fconstant-nsdictionary-literals
+
+// DISABLED-NOT: -fobjc-constant-literals
+// DISABLED-NOT: -fconstant-nsnumber-literals
+// DISABLED-NOT: -fconstant-nsarray-literals
+// DISABLED-NOT: -fconstant-nsdictionary-literals



More information about the cfe-commits mailing list