diff options
author | Hans Wennborg <hans@hanshq.net> | 2015-01-09 17:38:53 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2015-01-09 17:38:53 +0000 |
commit | a7707220e338ca9434b7f6af6b1a1a9f006af588 (patch) | |
tree | 0c7ed9db0e41d0a71a7b56830ecc985839ca8c0b | |
parent | 1440bb2a26ff13df1b29762658ee122cc0bc47ae (diff) | |
download | bcm5719-llvm-a7707220e338ca9434b7f6af6b1a1a9f006af588.tar.gz bcm5719-llvm-a7707220e338ca9434b7f6af6b1a1a9f006af588.zip |
Driver: tweak the code for determining default image name
It seemed odd to have to make DefaultImageName be a mutable member of Driver.
We don't need to the full result of computeTargetTriple() to determine the
image name; just base it on DefaultTargetTriple.
llvm-svn: 225530
-rw-r--r-- | clang/include/clang/Driver/Driver.h | 6 | ||||
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 14 | ||||
-rw-r--r-- | clang/test/Driver/default-image-name.c | 7 |
3 files changed, 18 insertions, 9 deletions
diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index 20ca5f0dca0..67d67c3074d 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -104,9 +104,6 @@ public: /// Default target triple. std::string DefaultTargetTriple; - /// Default name for linked images (e.g., "a.out"). - mutable std::string DefaultImageName; - /// Driver title to use with help. std::string DriverTitle; @@ -365,6 +362,9 @@ public: const char *LinkingOutput, InputInfo &Result) const; + /// Returns the default name for linked images (e.g., "a.out"). + const char *getDefaultImageName() const; + /// GetNamedOutputPath - Return the name to use for the output of /// the action \p JA. The result is appended to the compilation's /// list of temporary or result files, as appropriate. diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 38765f00f12..68ff98bd6f3 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -50,7 +50,6 @@ Driver::Driver(StringRef ClangExecutable, : Opts(createDriverOptTable()), Diags(Diags), Mode(GCCMode), ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT), UseStdLib(true), DefaultTargetTriple(DefaultTargetTriple), - DefaultImageName("a.out"), DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr), @@ -1411,7 +1410,7 @@ void Driver::BuildJobs(Compilation &C) const { if (FinalOutput) LinkingOutput = FinalOutput->getValue(); else - LinkingOutput = DefaultImageName.c_str(); + LinkingOutput = getDefaultImageName(); } InputInfo II; @@ -1624,6 +1623,11 @@ void Driver::BuildJobsForAction(Compilation &C, } } +const char *Driver::getDefaultImageName() const { + llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple)); + return Target.isOSWindows() ? "a.exe" : "a.out"; +} + /// \brief Create output filename based on ArgValue, which could either be a /// full filename, filename without extension, or a directory. If ArgValue /// does not provide a filename, then use BaseName, and use the extension @@ -1742,12 +1746,12 @@ const char *Driver::GetNamedOutputPath(Compilation &C, NamedOutput = MakeCLOutputFilename(C.getArgs(), "", BaseName, types::TY_Image); } else if (MultipleArchs && BoundArch) { - SmallString<128> Output(DefaultImageName.c_str()); + SmallString<128> Output(getDefaultImageName()); Output += "-"; Output.append(BoundArch); NamedOutput = C.getArgs().MakeArgString(Output.c_str()); } else - NamedOutput = DefaultImageName.c_str(); + NamedOutput = getDefaultImageName(); } else { const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode()); assert(Suffix && "All types used for output should have a suffix."); @@ -1996,8 +2000,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, StringRef DarwinArchName) const { llvm::Triple Target = computeTargetTriple(DefaultTargetTriple, Args, DarwinArchName); - if (Target.isOSWindows()) - DefaultImageName = "a.exe"; ToolChain *&TC = ToolChains[Target.str()]; if (!TC) { diff --git a/clang/test/Driver/default-image-name.c b/clang/test/Driver/default-image-name.c new file mode 100644 index 00000000000..00cf7dfbd95 --- /dev/null +++ b/clang/test/Driver/default-image-name.c @@ -0,0 +1,7 @@ +// RUN: %clang -target i386-unknown-linux-gnu %s -### 2>&1 | FileCheck -check-prefix=LINUX %s +// LINUX: a.out + +// RUN: %clang -target i686-pc-windows-msvc %s -### 2>&1 | FileCheck -check-prefix=WIN %s +// RUN: %clang -target i686-pc-windows-gnu %s -### 2>&1 | FileCheck -check-prefix=WIN %s +// RUN: %clang -target i686-windows-gnu %s -### 2>&1 | FileCheck -check-prefix=WIN %s +// WIN: a.exe |