[cfe-commits] r72142 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaCXX/types_compatible_p.cpp test/SemaTemplate/instantiate-expr-3.cpp

Douglas Gregor dgregor at apple.com
Tue May 19 15:28:02 PDT 2009


Author: dgregor
Date: Tue May 19 17:28:02 2009
New Revision: 72142

URL: http://llvm.org/viewvc/llvm-project?rev=72142&view=rev
Log:
Ban the use of __builtin_types_compatible_p in C++; g++ doesn't support it,
and it isn't clear exactly what it's supposed to mean. Thanks Eli!

Added:
    cfe/trunk/test/SemaCXX/types_compatible_p.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
    cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=72142&r1=72141&r2=72142&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 19 17:28:02 2009
@@ -110,6 +110,8 @@
 def warn_redecl_library_builtin : Warning<
   "incompatible redeclaration of library function %0">;
 def err_builtin_definition : Error<"definition of builtin function %0">;
+def err_types_compatible_p_in_cplusplus : Error<
+  "__builtin_types_compatible_p is not valid in C++">;
 
 /// parser diagnostics
 def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=72142&r1=72141&r2=72142&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue May 19 17:28:02 2009
@@ -5022,6 +5022,12 @@
 
   assert((!argT1.isNull() && !argT2.isNull()) && "Missing type argument(s)");
 
+  if (getLangOptions().CPlusPlus) {
+    Diag(BuiltinLoc, diag::err_types_compatible_p_in_cplusplus)
+      << SourceRange(BuiltinLoc, RPLoc);
+    return ExprError();
+  }
+
   return Owned(new (Context) TypesCompatibleExpr(Context.IntTy, BuiltinLoc,
                                                  argT1, argT2, RPLoc));
 }

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=72142&r1=72141&r2=72142&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Tue May 19 17:28:02 2009
@@ -469,22 +469,8 @@
 
 Sema::OwningExprResult 
 TemplateExprInstantiator::VisitTypesCompatibleExpr(TypesCompatibleExpr *E) {
-  QualType Type1 = SemaRef.InstantiateType(E->getArgType1(), TemplateArgs,
-                                           /*FIXME:*/ E->getBuiltinLoc(),
-                                           DeclarationName());
-  if (Type1.isNull())
-    return SemaRef.ExprError();
-
-  QualType Type2 = SemaRef.InstantiateType(E->getArgType2(), TemplateArgs,
-                                           /*FIXME:*/ E->getBuiltinLoc(),
-                                           DeclarationName());
-  if (Type2.isNull())
-    return SemaRef.ExprError();
-
-  return SemaRef.ActOnTypesCompatibleExpr(E->getBuiltinLoc(),
-                                          Type1.getAsOpaquePtr(),
-                                          Type2.getAsOpaquePtr(),
-                                          E->getRParenLoc());
+  assert(false && "__builtin_types_compatible_p is not legal in C++");
+  return SemaRef.ExprError();
 }
 
 Sema::OwningExprResult 

Added: cfe/trunk/test/SemaCXX/types_compatible_p.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/types_compatible_p.cpp?rev=72142&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/types_compatible_p.cpp (added)
+++ cfe/trunk/test/SemaCXX/types_compatible_p.cpp Tue May 19 17:28:02 2009
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+bool f() {
+  return __builtin_types_compatible_p(int, const int); // expected-error{{C++}}
+}

Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp?rev=72142&r1=72141&r2=72142&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp Tue May 19 17:28:02 2009
@@ -71,18 +71,6 @@
 template struct StatementExpr0<N1::X>; // expected-note{{instantiation}}
 
 // ---------------------------------------------------------------------
-// __builtin_types_compatible_p
-// ---------------------------------------------------------------------
-template<typename T, typename U, bool Result>
-struct TypesCompatible0 {
-  void f() {
-    int a[__builtin_types_compatible_p(T, U) == Result? 1 : -1];
-  }
-};
-
-template struct TypesCompatible0<int, const int, true>;
-
-// ---------------------------------------------------------------------
 // __builtin_shufflevector
 // ---------------------------------------------------------------------
 typedef __attribute__(( ext_vector_type(2) )) double double2;





More information about the cfe-commits mailing list