r210230 - Bugfix: don't assert if someone manages to declare an operator new/delete template before the builtin operator new/delete.

Richard Smith richard-llvm at metafoo.co.uk
Wed Jun 4 17:43:02 PDT 2014


Author: rsmith
Date: Wed Jun  4 19:43:02 2014
New Revision: 210230

URL: http://llvm.org/viewvc/llvm-project?rev=210230&view=rev
Log:
Bugfix: don't assert if someone manages to declare an operator new/delete template before the builtin operator new/delete.

Modified:
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/new.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=210230&r1=210229&r2=210230&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Jun  4 19:43:02 2014
@@ -1041,8 +1041,9 @@ RValue CodeGenFunction::EmitBuiltinNewDe
   DeclarationName Name = Ctx.DeclarationNames
       .getCXXOperatorName(IsDelete ? OO_Delete : OO_New);
   for (auto *Decl : Ctx.getTranslationUnitDecl()->lookup(Name))
-    if (Ctx.hasSameType(cast<FunctionDecl>(Decl)->getType(), QualType(Type, 0)))
-      return EmitNewDeleteCall(*this, cast<FunctionDecl>(Decl), Type, Args);
+    if (auto *FD = dyn_cast<FunctionDecl>(Decl))
+      if (Ctx.hasSameType(FD->getType(), QualType(Type, 0)))
+        return EmitNewDeleteCall(*this, cast<FunctionDecl>(Decl), Type, Args);
   llvm_unreachable("predeclared global operator new/delete is missing");
 }
 

Modified: cfe/trunk/test/CodeGenCXX/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=210230&r1=210229&r2=210230&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new.cpp Wed Jun  4 19:43:02 2014
@@ -2,6 +2,9 @@
 
 typedef __typeof__(sizeof(0)) size_t;
 
+// Declare an 'operator new' template to tickle a bug in __builtin_operator_new.
+template<typename T> void *operator new(size_t, int (*)(T));
+
 // Ensure that this declaration doesn't cause operator new to lose its
 // 'noalias' attribute.
 void *operator new[](size_t);
@@ -33,7 +36,6 @@ void *operator new[](size_t, const std::
 void operator delete(void *, const std::nothrow_t &) throw();
 void operator delete[](void *, const std::nothrow_t &) throw();
 
-
 void t2(int* a) {
   int* b = new (a) int;
 }





More information about the cfe-commits mailing list