From 05834e2d5b0caf4a960570d0e6efe654da1cbb79 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 2 Dec 2014 18:42:51 +0000 Subject: [PATCH] This patch fixes a crash involving use of predefined expressions. It fixes crash when mangling name for block's helper function used inside a constructor/destructor. rdar://19065361. llvm-svn: 223136 --- clang/lib/AST/Mangle.cpp | 6 ++++- clang/test/CodeGenCXX/predefined-expr.cpp | 32 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index 53ee442bd845..1a061c4f6632 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -236,7 +236,11 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD, (void) getBlockId(cast(DC), true); assert((isa(DC) || isa(DC)) && "expected a TranslationUnitDecl or a NamedDecl"); - if (auto ND = dyn_cast(DC)) { + if (const auto *CD = dyn_cast(DC)) + mangleCtorBlock(CD, /*CT*/ Ctor_Complete, BD, Out); + else if (const auto *DD = dyn_cast(DC)) + mangleDtorBlock(DD, /*DT*/ Dtor_Complete, BD, Out); + else if (auto ND = dyn_cast(DC)) { if (!shouldMangleDeclName(ND) && ND->getIdentifier()) Stream << ND->getIdentifier()->getName(); else { diff --git a/clang/test/CodeGenCXX/predefined-expr.cpp b/clang/test/CodeGenCXX/predefined-expr.cpp index f901467c4f4b..6bdc2cec4be8 100644 --- a/clang/test/CodeGenCXX/predefined-expr.cpp +++ b/clang/test/CodeGenCXX/predefined-expr.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++11 %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c++11 -fblocks %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s // CHECK: private unnamed_addr constant [15 x i8] c"externFunction\00" // CHECK: private unnamed_addr constant [26 x i8] c"void NS::externFunction()\00" @@ -537,3 +537,33 @@ int main() { return 0; } + +// rdar://19065361 +class XXX { + XXX(); + ~XXX(); +}; + +void XXLog(const char *functionName) { } + +typedef void (^notify_handler_t)(int token); + +typedef void (^dispatch_block_t)(void); + +void notify_register_dispatch(notify_handler_t handler); + +void _dispatch_once(dispatch_block_t block); + +XXX::XXX() +{ + _dispatch_once(^{ notify_register_dispatch( ^(int token) { XXLog(__FUNCTION__); }); + }); +} +// CHECK: define internal void @___ZN3XXXC2Ev_block_invoke_ + +XXX::~XXX() +{ + _dispatch_once(^{ notify_register_dispatch( ^(int token) { XXLog(__FUNCTION__); }); + }); +} +// CHECK: define internal void @___ZN3XXXD2Ev_block_invoke_