r225530 - Driver: tweak the code for determining default image name
Hans Wennborg
hans at hanshq.net
Fri Jan 9 09:38:54 PST 2015
Author: hans
Date: Fri Jan 9 11:38:53 2015
New Revision: 225530
URL: http://llvm.org/viewvc/llvm-project?rev=225530&view=rev
Log:
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.
Added:
cfe/trunk/test/Driver/default-image-name.c
Modified:
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/lib/Driver/Driver.cpp
Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=225530&r1=225529&r2=225530&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Fri Jan 9 11:38:53 2015
@@ -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.
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=225530&r1=225529&r2=225530&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Jan 9 11:38:53 2015
@@ -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) c
if (FinalOutput)
LinkingOutput = FinalOutput->getValue();
else
- LinkingOutput = DefaultImageName.c_str();
+ LinkingOutput = getDefaultImageName();
}
InputInfo II;
@@ -1624,6 +1623,11 @@ void Driver::BuildJobsForAction(Compilat
}
}
+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(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(co
StringRef DarwinArchName) const {
llvm::Triple Target = computeTargetTriple(DefaultTargetTriple, Args,
DarwinArchName);
- if (Target.isOSWindows())
- DefaultImageName = "a.exe";
ToolChain *&TC = ToolChains[Target.str()];
if (!TC) {
Added: cfe/trunk/test/Driver/default-image-name.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/default-image-name.c?rev=225530&view=auto
==============================================================================
--- cfe/trunk/test/Driver/default-image-name.c (added)
+++ cfe/trunk/test/Driver/default-image-name.c Fri Jan 9 11:38:53 2015
@@ -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
More information about the cfe-commits
mailing list