[cfe-commits] r96511 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Types.h lib/Driver/Driver.cpp lib/Driver/Types.cpp test/Driver/clang-c-as-cxx.c
Daniel Dunbar
daniel at zuster.org
Wed Feb 17 12:32:58 PST 2010
Author: ddunbar
Date: Wed Feb 17 14:32:58 2010
New Revision: 96511
URL: http://llvm.org/viewvc/llvm-project?rev=96511&view=rev
Log:
PR5803: clang++: Treat untyped 'C' inputs as C++.
- Patch by Andrzej K. Haczewski, with a tweak by me to emit a 'deprecated'
diagnostic when we do this. We'll see what zee users say.
Added:
cfe/trunk/test/Driver/clang-c-as-cxx.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Driver/Types.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/Types.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=96511&r1=96510&r2=96511&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Feb 17 14:32:58 2010
@@ -88,6 +88,8 @@
def warn_drv_missing_resource_library : Warning<
"missing resource library '%0', link may fail">;
def warn_drv_conflicting_deployment_targets : Warning<
- "conflicting deployment targets, both MACOSX_DEPLOYMENT_TARGET '%0' and IPHONEOS_DEPLOYMENT_TARGET '%1' are present in environment">;
+ "conflicting deployment targets, both MACOSX_DEPLOYMENT_TARGET '%0' and IPHONEOS_DEPLOYMENT_TARGET '%1' are present in environment">;
+def warn_drv_treating_input_as_cxx : Warning<
+ "treating '%0' input as '%1' when in C++ mode, this behavior is deprecated">;
}
Modified: cfe/trunk/include/clang/Driver/Types.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.h?rev=96511&r1=96510&r2=96511&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Types.h (original)
+++ cfe/trunk/include/clang/Driver/Types.h Wed Feb 17 14:32:58 2010
@@ -80,6 +80,10 @@
/// getCompilationPhase - Return the \args N th compilation phase to
/// be done for this type.
phases::ID getCompilationPhase(ID Id, unsigned N);
+
+ /// lookupCXXTypeForCType - Lookup CXX input type that corresponds to given
+ /// C type (used for clang++ emulation of g++ behaviour)
+ ID lookupCXXTypeForCType(ID Id);
} // end namespace types
} // end namespace driver
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=96511&r1=96510&r2=96511&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Feb 17 14:32:58 2010
@@ -558,6 +558,17 @@
if (Ty == types::TY_INVALID)
Ty = types::TY_Object;
+
+ // If the driver is invoked as C++ compiler (like clang++ or c++) it
+ // should autodetect some input files as C++ for g++ compatibility.
+ if (CCCIsCXX) {
+ types::ID OldTy = Ty;
+ Ty = types::lookupCXXTypeForCType(Ty);
+
+ if (Ty != OldTy)
+ Diag(clang::diag::warn_drv_treating_input_as_cxx)
+ << getTypeName(OldTy) << getTypeName(Ty);
+ }
}
// -ObjC and -ObjC++ override the default language, but only for "source
Modified: cfe/trunk/lib/Driver/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Types.cpp?rev=96511&r1=96510&r2=96511&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Types.cpp (original)
+++ cfe/trunk/lib/Driver/Types.cpp Wed Feb 17 14:32:58 2010
@@ -213,3 +213,19 @@
return phases::Link;
}
+
+ID types::lookupCXXTypeForCType(ID Id) {
+ switch (Id) {
+ default:
+ return Id;
+
+ case types::TY_C:
+ return types::TY_CXX;
+ case types::TY_PP_C:
+ return types::TY_PP_CXX;
+ case types::TY_CHeader:
+ return types::TY_CXXHeader;
+ case types::TY_PP_CHeader:
+ return types::TY_PP_CXXHeader;
+ }
+}
Added: cfe/trunk/test/Driver/clang-c-as-cxx.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-c-as-cxx.c?rev=96511&view=auto
==============================================================================
--- cfe/trunk/test/Driver/clang-c-as-cxx.c (added)
+++ cfe/trunk/test/Driver/clang-c-as-cxx.c Wed Feb 17 14:32:58 2010
@@ -0,0 +1,6 @@
+// RUN: %clangxx -### %s 2>&1 | FileCheck %s
+//
+// PR5803
+//
+// CHECK: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
+// CHECK: "-cc1" {{.*}} "-x" "c++"
More information about the cfe-commits
mailing list