From fa8ad04dbe2dc284309e6794b4dfcfc70342e9cf Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 5 Jun 2014 00:43:02 +0000 Subject: [PATCH] Bugfix: don't assert if someone manages to declare an operator new/delete template before the builtin operator new/delete. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210230 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprCXX.cpp | 5 +++-- test/CodeGenCXX/new.cpp | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index 0492813f8f..f2332bde5f 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -1041,8 +1041,9 @@ RValue CodeGenFunction::EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, DeclarationName Name = Ctx.DeclarationNames .getCXXOperatorName(IsDelete ? OO_Delete : OO_New); for (auto *Decl : Ctx.getTranslationUnitDecl()->lookup(Name)) - if (Ctx.hasSameType(cast(Decl)->getType(), QualType(Type, 0))) - return EmitNewDeleteCall(*this, cast(Decl), Type, Args); + if (auto *FD = dyn_cast(Decl)) + if (Ctx.hasSameType(FD->getType(), QualType(Type, 0))) + return EmitNewDeleteCall(*this, cast(Decl), Type, Args); llvm_unreachable("predeclared global operator new/delete is missing"); } diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp index d8aa258cbb..862161b193 100644 --- a/test/CodeGenCXX/new.cpp +++ b/test/CodeGenCXX/new.cpp @@ -2,6 +2,9 @@ typedef __typeof__(sizeof(0)) size_t; +// Declare an 'operator new' template to tickle a bug in __builtin_operator_new. +template 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::nothrow_t &) throw(); 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; } -- 2.40.0