[cfe-commits] r72134 - in /cfe/trunk: include/clang/AST/Expr.h lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-expr-3.cpp

Douglas Gregor dgregor at apple.com
Tue May 19 13:55:32 PDT 2009


Author: dgregor
Date: Tue May 19 15:55:31 2009
New Revision: 72134

URL: http://llvm.org/viewvc/llvm-project?rev=72134&view=rev
Log:
Template instantiation for __builtin_types_compatible_p.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
    cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=72134&r1=72133&r2=72134&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue May 19 15:55:31 2009
@@ -1616,7 +1616,7 @@
   virtual child_iterator child_end();
 };
 
-/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
+/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
 /// This AST node represents a function that returns 1 if two *types* (not
 /// expressions) are compatible. The result of this built-in function can be
 /// used in integer constant expressions.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Tue May 19 15:55:31 2009
@@ -56,6 +56,7 @@
     OwningExprResult VisitConditionalOperator(ConditionalOperator *E);
     // FIXME: AddrLabelExpr
     OwningExprResult VisitStmtExpr(StmtExpr *E);
+    OwningExprResult VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
     OwningExprResult VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
     OwningExprResult VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *E);
     OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
@@ -466,6 +467,26 @@
 }
 
 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());
+}
+
+Sema::OwningExprResult 
 TemplateExprInstantiator::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
   bool isSizeOf = E->isSizeOf();
 

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=72134&r1=72133&r2=72134&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp Tue May 19 15:55:31 2009
@@ -69,3 +69,15 @@
 
 template struct StatementExpr0<int>;
 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>;





More information about the cfe-commits mailing list