From: Hans Wennborg Date: Fri, 9 Jan 2015 17:38:53 +0000 (+0000) Subject: Driver: tweak the code for determining default image name X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=427a453b76ddca6faa2d4444be8bab07fd3ef9ee;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225530 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 20ca5f0dca..67d67c3074 100644 --- a/include/clang/Driver/Driver.h +++ b/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/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 38765f00f1..68ff98bd6f 100644 --- a/lib/Driver/Driver.cpp +++ b/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/test/Driver/default-image-name.c b/test/Driver/default-image-name.c new file mode 100644 index 0000000000..00cf7dfbd9 --- /dev/null +++ b/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