[clang] 9f07256 - [Driver] -p: change from unused warning to error for most targets

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 2 10:57:54 PST 2022


Author: Fangrui Song
Date: 2022-12-02T18:57:48Z
New Revision: 9f07256a51924feabf151b5f5fbbab16af2a76c5

URL: https://github.com/llvm/llvm-project/commit/9f07256a51924feabf151b5f5fbbab16af2a76c5
DIFF: https://github.com/llvm/llvm-project/commit/9f07256a51924feabf151b5f5fbbab16af2a76c5.diff

LOG: [Driver] -p: change from unused warning to error for most targets

AIX and OpenBSD seem to use -p. For most targets (at least FreeBSD and Linux),
-p is legacy (GCC freebsd has a warning). We don't want the uses to grow, so
making -p an alias for -pg is not recommended. I think the uses are small.

Reviewed By: mgorny

Differential Revision: https://reviews.llvm.org/D138255

Added: 
    clang/test/Driver/p.c

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d9c1f42c01fb..fe6435d7c8c4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,9 @@ code bases.
 - To match GCC, ``__ppc64__`` is no longer defined on PowerPC64 targets. Use
   ``__powerpc64__`` instead.
 
+- ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
+  to an ``-Wunused-command-line-argument`` warning in previous releases.
+
 What's New in Clang |release|?
 ==============================
 Some of the major new features and improvements to Clang are listed

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 16130982eb8c..6ec4172e3ebd 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6214,6 +6214,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
             << A->getAsString(Args) << TripleStr;
     }
   }
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
+    if (!TC.getTriple().isOSAIX() && !TC.getTriple().isOSOpenBSD()) {
+      D.Diag(diag::err_drv_unsupported_opt_for_target)
+          << A->getAsString(Args) << TripleStr;
+    }
+  }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
       (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))

diff  --git a/clang/test/Driver/p.c b/clang/test/Driver/p.c
new file mode 100644
index 000000000000..102cb3c33527
--- /dev/null
+++ b/clang/test/Driver/p.c
@@ -0,0 +1,7 @@
+/// For most targets -p is legacy. We used to report -Wunused-command-line-argument.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -c -p %s 2>&1 | FileCheck %s --check-prefix=ERR
+
+// RUN: %clang -### --target=x86_64-unknown-openbsd -c -p %s 2>&1 | FileCheck %s --implicit-check-not=error:
+// RUN: %clang -### --target=powerpc64-ibm-aix -c -p %s 2>&1 | FileCheck %s --implicit-check-not=error:
+
+// ERR: error: unsupported option '-p' for target {{.*}}


        


More information about the cfe-commits mailing list