From: Daniel Dunbar Date: Fri, 20 Mar 2009 23:39:23 +0000 (+0000) Subject: ccc/Driver: .s defaults to 'assembler-with-cpp' on Darwin. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e33bea4ef34598e7a4a6a3a117392268998552d4;p=clang ccc/Driver: .s defaults to 'assembler-with-cpp' on Darwin. - ccc doesn't handle assembler-with-cpp semantics correctly (but clang supports it) - This is sad, because it requires a fairly useless target hook. C'est la vie. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67418 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/HostInfo.h b/include/clang/Driver/HostInfo.h index 10ad2f9fe9..dbfda14ca2 100644 --- a/include/clang/Driver/HostInfo.h +++ b/include/clang/Driver/HostInfo.h @@ -10,6 +10,7 @@ #ifndef CLANG_DRIVER_HOSTINFO_H_ #define CLANG_DRIVER_HOSTINFO_H_ +#include "clang/Driver/Types.h" #include namespace clang { @@ -45,6 +46,10 @@ public: /// driver for this host and support -arch, -Xarch, etc. virtual bool useDriverDriver() const = 0; + /// lookupTypeForExtension - Return the default language type to use + /// for the given extension. + virtual types::ID lookupTypeForExtension(const char *Ext) const = 0; + /// getToolChain - Construct the toolchain to use for this host. /// /// \param Args - The argument list, which may be used to alter the diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 2c324010da..40c6e50063 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -445,9 +445,11 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const { Ty = types::TY_C; } else { // Otherwise lookup by extension, and fallback to ObjectType - // if not found. + // if not found. We use a host hook here because Darwin at + // least has its own idea of what .s is. if (const char *Ext = strrchr(Value, '.')) - Ty = types::lookupTypeForExtension(Ext + 1); + Ty = Host->lookupTypeForExtension(Ext + 1); + if (Ty == types::TY_INVALID) Ty = types::TY_Object; } diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index 39a688a4f5..8c24a3c707 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -57,6 +57,17 @@ public: virtual bool useDriverDriver() const; + virtual types::ID lookupTypeForExtension(const char *Ext) const { + types::ID Ty = types::lookupTypeForExtension(Ext); + + // Darwin always preprocesses assembly files (unless -x is used + // explicitly). + if (Ty == types::TY_PP_Asm) + return types::TY_Asm; + + return Ty; + } + virtual ToolChain *getToolChain(const ArgList &Args, const char *ArchName) const; }; @@ -173,6 +184,10 @@ public: virtual bool useDriverDriver() const; + virtual types::ID lookupTypeForExtension(const char *Ext) const { + return types::lookupTypeForExtension(Ext); + } + virtual ToolChain *getToolChain(const ArgList &Args, const char *ArchName) const; }; diff --git a/test/Driver/phases.c b/test/Driver/phases.c index f55cbc6755..1466d7c3e2 100644 --- a/test/Driver/phases.c +++ b/test/Driver/phases.c @@ -66,4 +66,14 @@ // RUN: grep -F '1: preprocessor, {0}, c-header-cpp-output' %t && // RUN: grep -F '2: precompiler, {1}, precompiled-header' %t && +// Darwin overrides the handling for .s +// RUN: touch %t.s && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-phases -c %t.s &> %t && +// RUN: grep '0: input, ".*\.s", assembler' %t && +// RUN: grep -F '1: assembler, {0}, object' %t && +// RUN: clang-driver -ccc-host-triple i386-apple-darwin9 -ccc-print-phases -c %t.s &> %t && +// RUN: grep '0: input, ".*\.s", assembler-with-cpp' %t && +// RUN: grep -F '1: preprocessor, {0}, assembler' %t && +// RUN: grep -F '2: assembler, {1}, object' %t && + // RUN: true diff --git a/tools/ccc/ccclib/Driver.py b/tools/ccc/ccclib/Driver.py index 5c978e2638..92f7c87ca0 100644 --- a/tools/ccc/ccclib/Driver.py +++ b/tools/ccc/ccclib/Driver.py @@ -426,7 +426,7 @@ class Driver(object): else: raise Arguments.InvalidArgumentsError("-E or -x required when input is from standard input") elif ext and ext in Types.kTypeSuffixMap: - klass = Types.kTypeSuffixMap[ext] + klass = self.hostInfo.lookupTypeForExtension(ext) else: # FIXME: Its not clear why we shouldn't just # revert to unknown. I think this is more likely a diff --git a/tools/ccc/ccclib/HostInfo.py b/tools/ccc/ccclib/HostInfo.py index 9f61b87502..c40a4f7c4d 100644 --- a/tools/ccc/ccclib/HostInfo.py +++ b/tools/ccc/ccclib/HostInfo.py @@ -1,4 +1,5 @@ import ToolChain +import Types class HostInfo(object): """HostInfo - Config information about a particular host which may @@ -14,6 +15,9 @@ class HostInfo(object): def useDriverDriver(self): abstract + def lookupTypeForExtension(self, ext): + abstract + def getToolChain(self): abstract @@ -37,6 +41,12 @@ class DarwinHostInfo(HostInfo): def useDriverDriver(self): return True + def lookupTypeForExtension(self, ext): + ty = Types.kTypeSuffixMap.get(ext) + if ty is Types.AsmTypeNoPP: + return Types.AsmType + return ty + def getToolChain(self): return self.getToolChainForArch(self.getArchName(None)) @@ -98,6 +108,9 @@ class UnknownHostInfo(HostInfo): def useDriverDriver(self): return False + def lookupTypeForExtension(self, ext): + return Types.kTypeSuffixMap.get(ext) + def getToolChain(self): return ToolChain.Generic_GCC_ToolChain(self.driver, '')