Skip to content

[ObjectiveC] -rewrite-objc was treating inputs as preprocessed files #137623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025

Conversation

jmmartinez
Copy link
Contributor

-rewrite-objc passes -x objective-c++-cpp-output as input type to the preprocessor job. This is not correct since we would be preprocessing a preprocessed file. The correct input type is objective-c++.

@jmmartinez jmmartinez requested a review from ahatanak April 28, 2025 12:41
@jmmartinez jmmartinez self-assigned this Apr 28, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 28, 2025

@llvm/pr-subscribers-clang

Author: Juan Manuel Martinez Caamaño (jmmartinez)

Changes

-rewrite-objc passes -x objective-c++-cpp-output as input type to the preprocessor job. This is not correct since we would be preprocessing a preprocessed file. The correct input type is objective-c++.


Full diff: https://github.com/llvm/llvm-project/pull/137623.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1)
  • (added) clang/test/Driver/rewrite-objc-preproc.m (+5)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index f98cd389509cd..4c3d55a62f66d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -521,7 +521,7 @@ static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
 
   CmdArgs.push_back("-x");
   if (Args.hasArg(options::OPT_rewrite_objc))
-    CmdArgs.push_back(types::getTypeName(types::TY_PP_ObjCXX));
+    CmdArgs.push_back(types::getTypeName(types::TY_ObjCXX));
   else {
     // Map the driver type to the frontend type. This is mostly an identity
     // mapping, except that the distinction between module interface units
diff --git a/clang/test/Driver/rewrite-objc-preproc.m b/clang/test/Driver/rewrite-objc-preproc.m
new file mode 100644
index 0000000000000..f32d09c5a15f3
--- /dev/null
+++ b/clang/test/Driver/rewrite-objc-preproc.m
@@ -0,0 +1,5 @@
+// RUN: %clang --target=x86_64-apple-macosx10.7.0 -rewrite-objc %s -o - -### 2>&1 | \
+// RUN:   FileCheck %s
+//
+// Check that we're running a preprocessing stage passing a not-preprocessed objective-c++ file as input
+// CHECK: "-E"{{.*}}"-x" "objective-c++"

@llvmbot
Copy link
Member

llvmbot commented Apr 28, 2025

@llvm/pr-subscribers-clang-driver

Author: Juan Manuel Martinez Caamaño (jmmartinez)

Changes

-rewrite-objc passes -x objective-c++-cpp-output as input type to the preprocessor job. This is not correct since we would be preprocessing a preprocessed file. The correct input type is objective-c++.


Full diff: https://github.com/llvm/llvm-project/pull/137623.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1)
  • (added) clang/test/Driver/rewrite-objc-preproc.m (+5)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index f98cd389509cd..4c3d55a62f66d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -521,7 +521,7 @@ static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
 
   CmdArgs.push_back("-x");
   if (Args.hasArg(options::OPT_rewrite_objc))
-    CmdArgs.push_back(types::getTypeName(types::TY_PP_ObjCXX));
+    CmdArgs.push_back(types::getTypeName(types::TY_ObjCXX));
   else {
     // Map the driver type to the frontend type. This is mostly an identity
     // mapping, except that the distinction between module interface units
diff --git a/clang/test/Driver/rewrite-objc-preproc.m b/clang/test/Driver/rewrite-objc-preproc.m
new file mode 100644
index 0000000000000..f32d09c5a15f3
--- /dev/null
+++ b/clang/test/Driver/rewrite-objc-preproc.m
@@ -0,0 +1,5 @@
+// RUN: %clang --target=x86_64-apple-macosx10.7.0 -rewrite-objc %s -o - -### 2>&1 | \
+// RUN:   FileCheck %s
+//
+// Check that we're running a preprocessing stage passing a not-preprocessed objective-c++ file as input
+// CHECK: "-E"{{.*}}"-x" "objective-c++"

@jmmartinez jmmartinez merged commit fbf08a6 into llvm:main May 12, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants