From: Hans Wennborg Date: Wed, 7 Aug 2013 00:32:15 +0000 (+0000) Subject: clang-cl: Use .obj as object file extension instead of .o X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=909930fc19ff69b08f2ea6f6e2996d24c816f311;p=clang clang-cl: Use .obj as object file extension instead of .o Differential Revision: http://llvm-reviews.chandlerc.com/D1302 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187840 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index b2db31845f..dad25e8be6 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -129,6 +129,9 @@ public: /// Whether the driver is just the preprocessor. bool CCCIsCPP() const { return Mode == CPPMode; } + /// Whether the driver should follow cl.exe like behavior. + bool IsCLMode() const { return Mode == CLMode; } + /// Only print tool bindings, don't build any jobs. unsigned CCCPrintBindings : 1; diff --git a/include/clang/Driver/Types.h b/include/clang/Driver/Types.h index be5015e843..cca576a054 100644 --- a/include/clang/Driver/Types.h +++ b/include/clang/Driver/Types.h @@ -34,7 +34,7 @@ namespace types { /// getTypeTempSuffix - Return the suffix to use when creating a /// temp file of this type, or null if unspecified. - const char *getTypeTempSuffix(ID Id); + const char *getTypeTempSuffix(ID Id, bool CLMode = false); /// onlyAssembleType - Should this type only be assembled. bool onlyAssembleType(ID Id); diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 729b9afe62..3fddc8fe6e 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1589,7 +1589,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, StringRef Name = llvm::sys::path::filename(BaseInput); std::pair Split = Name.split('.'); std::string TmpName = - GetTemporaryPath(Split.first, types::getTypeTempSuffix(JA.getType())); + GetTemporaryPath(Split.first, + types::getTypeTempSuffix(JA.getType(), IsCLMode())); return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str())); } @@ -1620,8 +1621,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, if (llvm::sys::path::has_extension(Filename.str())) Filename = Filename.substr(0, Filename.rfind(".")); Filename.append("."); - // FIXME: For clang-cl, we want .obj rather than .o for object files. - Filename.append(types::getTypeTempSuffix(types::TY_Object)); + Filename.append(types::getTypeTempSuffix(types::TY_Object, IsCLMode())); } NamedOutput = C.getArgs().MakeArgString(Filename.c_str()); @@ -1665,7 +1665,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C, StringRef Name = llvm::sys::path::filename(BaseInput); std::pair Split = Name.split('.'); std::string TmpName = - GetTemporaryPath(Split.first, types::getTypeTempSuffix(JA.getType())); + GetTemporaryPath(Split.first, + types::getTypeTempSuffix(JA.getType(), IsCLMode())); return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str())); } } diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp index 19870fe6fd..67ef2a6a83 100644 --- a/lib/Driver/Types.cpp +++ b/lib/Driver/Types.cpp @@ -44,7 +44,9 @@ types::ID types::getPreprocessedType(ID Id) { return getInfo(Id).PreprocessedType; } -const char *types::getTypeTempSuffix(ID Id) { +const char *types::getTypeTempSuffix(ID Id, bool CLMode) { + if (Id == TY_Object && CLMode) + return "obj"; return getInfo(Id).TempSuffix; } @@ -135,6 +137,7 @@ types::ID types::lookupTypeForExtension(const char *Ext) { .Case("s", TY_PP_Asm) .Case("S", TY_Asm) .Case("o", TY_Object) + .Case("obj", TY_Object) .Case("ii", TY_PP_CXX) .Case("mi", TY_PP_ObjC) .Case("mm", TY_ObjCXX) diff --git a/test/Driver/cl-Fo.c b/test/Driver/cl-Fo.c index b820f0dcef..fe3d58d46b 100644 --- a/test/Driver/cl-Fo.c +++ b/test/Driver/cl-Fo.c @@ -5,23 +5,23 @@ // command-line option, e.g. on Mac where %s is commonly under /Users. // RUN: %clang_cl /Foa -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-NAME %s -// CHECK-NAME: "-o" "a.o" +// CHECK-NAME: "-o" "a.obj" // RUN: %clang_cl /Foa.ext /Fob.ext -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-NAMEEXT %s // CHECK-NAMEEXT: warning: overriding '/Foa.ext' option with '/Fob.ext' // CHECK-NAMEEXT: "-o" "b.ext" // RUN: %clang_cl /Fofoo.dir/ -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-DIR %s -// CHECK-DIR: "-o" "foo.dir{{[/\\]+}}cl-Fo.o" +// CHECK-DIR: "-o" "foo.dir{{[/\\]+}}cl-Fo.obj" // RUN: %clang_cl /Fofoo.dir/a -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-DIRNAME %s -// CHECK-DIRNAME: "-o" "foo.dir{{[/\\]+}}a.o" +// CHECK-DIRNAME: "-o" "foo.dir{{[/\\]+}}a.obj" // RUN: %clang_cl /Fofoo.dir/a.ext -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-DIRNAMEEXT %s // CHECK-DIRNAMEEXT: "-o" "foo.dir{{[/\\]+}}a.ext" // RUN: %clang_cl /Fo.. -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-CRAZY %s -// CHECK-CRAZY: "-o" "...o" +// CHECK-CRAZY: "-o" "...obj" // RUN: %clang_cl /Fo -### 2>&1 | FileCheck -check-prefix=CHECK-MISSINGARG %s @@ -31,4 +31,4 @@ // CHECK-MULTIPLESOURCEERROR: error: cannot specify '/Foa.obj' when compiling multiple source files // RUN: %clang_cl /Fomydir/ -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-MULTIPLESOURCEOK %s -// CHECK-MULTIPLESOURCEOK: "-o" "mydir{{[/\\]+}}cl-Fo.o" +// CHECK-MULTIPLESOURCEOK: "-o" "mydir{{[/\\]+}}cl-Fo.obj"