francii updated this revision to Diff 501668.
francii added a comment.

Cleanup


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145021

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ibm-profiling.c
  clang/test/Driver/zos-profiling-error.c

Index: clang/test/Driver/zos-profiling-error.c
===================================================================
--- clang/test/Driver/zos-profiling-error.c
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang 2>&1 -### --target=s390x-none-zos -pg -S %s | FileCheck -check-prefix=FAIL-PG-NAME %s
-// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
Index: clang/test/Driver/ibm-profiling.c
===================================================================
--- /dev/null
+++ clang/test/Driver/ibm-profiling.c
@@ -0,0 +1,34 @@
+// RUN: %clang -### 2>&1 \
+// RUN:        --target=s390x-none-zos \
+// RUN:		   -S \
+// RUN:        -pg \
+// RUN:        %s \
+// RUN:        | FileCheck -check-prefix=FAIL-PG-NAME %s
+// FAIL-PG-NAME: error: unsupported option '-pg' for target 's390x-none-zos'
+
+// Check presecedence: -pg is unused when passed first.
+// RUN: %clang -### 2>&1 \
+// RUN:        --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:        -pg \
+// RUN:        -p \
+// RUN:        %s \
+// RUN:   	   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
+
+// Check presecedence: -p is unused when past first.
+// RUN: %clang -### 2>&1 \
+// RUN:        --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:        -p \
+// RUN:        -pg \
+// RUN:        %s \
+// RUN:        | FileCheck --check-prefix=UNUSED %s
+// UNUSED: warning: argument unused during compilation: '-p'
+
+// Check that -p is still used when not linking on AIX.
+// RUN: %clang -### 2>&1 \
+// RUN:        --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:        -p \
+// RUN:        -S \
+// RUN:        %s \
+// RUN:   | FileCheck --check-prefix=UNUSED %s
+// UNUSED-NOT: warning: argument unused during compilation: '-p'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6324,18 +6324,21 @@
             << A->getAsString(Args) << TripleStr;
     }
   }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
-    if (TC.getTriple().isOSAIX()) {
-      CmdArgs.push_back("-pg");
-    } else if (!TC.getTriple().isOSOpenBSD()) {
-      D.Diag(diag::err_drv_unsupported_opt_for_target)
-          << A->getAsString(Args) << TripleStr;
-    }
-  }
-  if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
-    if (TC.getTriple().isOSzOS()) {
-      D.Diag(diag::err_drv_unsupported_opt_for_target)
-          << A->getAsString(Args) << TripleStr;
+  if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
+    if (A->getOption().matches(options::OPT_pg)) {
+      if (TC.getTriple().isOSzOS()) {
+        D.Diag(diag::err_drv_unsupported_opt_for_target)
+            << A->getAsString(Args) << TripleStr;
+      }
+    } else if (A->getOption().matches(options::OPT_p)) {
+      A->claim();
+      if (TC.getTriple().isOSAIX()) {
+        if (!Args.hasArgNoClaim(options::OPT_pg))
+          CmdArgs.push_back("-pg");
+      } else if (!TC.getTriple().isOSOpenBSD()) {
+        D.Diag(diag::err_drv_unsupported_opt_for_target)
+            << A->getAsString(Args) << TripleStr;
+      }
     }
   }
 
Index: clang/lib/Driver/ToolChains/AIX.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -164,11 +164,12 @@
   }
 
   auto getCrt0Basename = [&Args, IsArch32Bit] {
+    Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg);
     // Enable gprofiling when "-pg" is specified.
-    if (Args.hasArg(options::OPT_pg))
+    if (A->getOption().matches(options::OPT_pg))
       return IsArch32Bit ? "gcrt0.o" : "gcrt0_64.o";
     // Enable profiling when "-p" is specified.
-    else if (Args.hasArg(options::OPT_p))
+    else if (A->getOption().matches(options::OPT_p))
       return IsArch32Bit ? "mcrt0.o" : "mcrt0_64.o";
     else
       return IsArch32Bit ? "crt0.o" : "crt0_64.o";
@@ -271,7 +272,7 @@
 
     CmdArgs.push_back("-lc");
 
-    if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
+    if (Args.hasArgNoClaim(options::OPT_p, options::OPT_pg)) {
       CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
                                            "/lib/profiled"));
       CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to