[pkg-d-commits] [ldc] 71/74: Print -mcpu=help / -mattr=help output only once (#2152)

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:54:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta2
in repository ldc.

commit d229a273e523b213025d1d4837cfbe5ea52ed001
Author: kinke <kinke at users.noreply.github.com>
Date:   Mon Jun 5 01:19:00 2017 +0200

    Print -mcpu=help / -mattr=help output only once (#2152)
    
    When creating LLVM's TargetMachine, llvm::SubtargetFeatures::getFeatureBits()
    is called 3 times, and the help is printed 3 times (or even 6 times when
    specifying both `-mcpu=help -mattr=help`).
    
    So use some new code making sure the help is printed only once and return
    0 early without trying to compile anything (and so erroring if no source
    files have been specified etc.).
    
    Fixes issue #2073.
---
 driver/main.cpp       | 19 ++++++++++++++++++-
 tests/driver/gh2073.d |  7 +++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/driver/main.cpp b/driver/main.cpp
index 7e44541..5aa7f78 100644
--- a/driver/main.cpp
+++ b/driver/main.cpp
@@ -355,6 +355,19 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
 
   helpOnly = mCPU == "help" ||
              (std::find(mAttrs.begin(), mAttrs.end(), "help") != mAttrs.end());
+  if (helpOnly) {
+    auto triple = llvm::Triple(cfg_triple);
+    std::string errMsg;
+    if (auto target = lookupTarget("", triple, errMsg)) {
+      llvm::errs() << "Targeting " << target->getName() << ". ";
+      // this prints the available CPUs and features of the target to stderr...
+      target->createMCSubtargetInfo(cfg_triple, "help", "");
+    } else {
+      error(Loc(), "%s", errMsg.c_str());
+      fatal();
+    }
+    return;
+  }
 
   // Print some information if -v was passed
   // - path to compiler binary
@@ -962,7 +975,11 @@ int cppmain(int argc, char **argv) {
   Strings files;
   parseCommandLine(argc, argv, files, helpOnly);
 
-  if (files.dim == 0 && !helpOnly) {
+  if (helpOnly) {
+    return 0;
+  }
+
+  if (files.dim == 0) {
     cl::PrintHelpMessage();
     return EXIT_FAILURE;
   }
diff --git a/tests/driver/gh2073.d b/tests/driver/gh2073.d
new file mode 100644
index 0000000..66a88e0
--- /dev/null
+++ b/tests/driver/gh2073.d
@@ -0,0 +1,7 @@
+// RUN: %ldc -mcpu=help 2>&1 | FileCheck %s
+// RUN: %ldc -mattr=help 2>&1 | FileCheck %s
+// RUN: %ldc -mcpu=help -mattr=help 2>&1 | FileCheck %s
+
+// CHECK: Available CPUs for this target:
+// CHECK: Available features for this target:
+// CHECK-NOT: Available CPUs for this target:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list