diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2014-11-14 23:55:27 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2014-11-14 23:55:27 +0000 |
commit | 68e79383619e354988deac99d7c6ac6a75e92b33 (patch) | |
tree | 4009033a511ad0160c23a5a2d4df8ec5afea0ab9 | |
parent | c81307af0f07121f9e9f142078c04aeaae8c5eee (diff) | |
download | bcm5719-llvm-68e79383619e354988deac99d7c6ac6a75e92b33.tar.gz bcm5719-llvm-68e79383619e354988deac99d7c6ac6a75e92b33.zip |
This patch fixes couple of bugs for predefined expression
used inside blocks. It fixes a crash in naming code
for __func__ etc. when used in a block declared globally.
It also brings back old naming convention for
predefined expression which was broken. rdar://18961148
llvm-svn: 222065
-rw-r--r-- | clang/lib/AST/Mangle.cpp | 24 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 5 | ||||
-rw-r--r-- | clang/test/CodeGen/block-with-perdefinedexpr.c | 14 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/predefined-expr-cxx14.cpp | 4 |
4 files changed, 33 insertions, 14 deletions
diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index ae6c5f296d7..53ee442bd84 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -234,17 +234,19 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD, if (isa<BlockDecl>(DC)) for (; DC && isa<BlockDecl>(DC); DC = DC->getParent()) (void) getBlockId(cast<BlockDecl>(DC), true); - assert(isa<NamedDecl>(DC) && "expected a NamedDecl"); - const NamedDecl *ND = cast<NamedDecl>(DC); - if (!shouldMangleDeclName(ND) && ND->getIdentifier()) - Stream << ND->getIdentifier()->getName(); - else { - // FIXME: We were doing a mangleUnqualifiedName() before, but that's - // a private member of a class that will soon itself be private to the - // Itanium C++ ABI object. What should we do now? Right now, I'm just - // calling the mangleName() method on the MangleContext; is there a - // better way? - mangleName(ND, Stream); + assert((isa<TranslationUnitDecl>(DC) || isa<NamedDecl>(DC)) && + "expected a TranslationUnitDecl or a NamedDecl"); + if (auto ND = dyn_cast<NamedDecl>(DC)) { + if (!shouldMangleDeclName(ND) && ND->getIdentifier()) + Stream << ND->getIdentifier()->getName(); + else { + // FIXME: We were doing a mangleUnqualifiedName() before, but that's + // a private member of a class that will soon itself be private to the + // Itanium C++ ABI object. What should we do now? Right now, I'm just + // calling the mangleName() method on the MangleContext; is there a + // better way? + mangleName(ND, Stream); + } } } Stream.flush(); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 0b8caa1e11a..1a3a61a76dd 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -2081,7 +2081,10 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { StringRef NameItems[] = { PredefinedExpr::getIdentTypeName(E->getIdentType()), FnName}; std::string GVName = llvm::join(NameItems, NameItems + 2, "."); - + if (CurCodeDecl && isa<BlockDecl>(CurCodeDecl)) { + auto C = CGM.GetAddrOfConstantCString(FnName, GVName.c_str(), 1); + return MakeAddrLValue(C, E->getType()); + } auto C = CGM.GetAddrOfConstantStringFromLiteral(SL, GVName); return MakeAddrLValue(C, E->getType()); } diff --git a/clang/test/CodeGen/block-with-perdefinedexpr.c b/clang/test/CodeGen/block-with-perdefinedexpr.c new file mode 100644 index 00000000000..68fdea60f37 --- /dev/null +++ b/clang/test/CodeGen/block-with-perdefinedexpr.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -fblocks -triple x86_64-apple-darwin10 | FileCheck %s +// rdar://18961148 + +void syslog(const char *, ...); + +void handler( ); + +static void (^spd)() = ^() +{ + handler( ^(){ syslog("%s", __FUNCTION__); } ); +}; +// CHECK: @__FUNCTION__.spd_block_invoke_2 = private unnamed_addr constant [19 x i8] c"spd_block_invoke_2\00" +// CHECK: define internal void @spd_block_invoke_2 +// CHECK: @__FUNCTION__.spd_block_invoke_2 diff --git a/clang/test/CodeGenCXX/predefined-expr-cxx14.cpp b/clang/test/CodeGenCXX/predefined-expr-cxx14.cpp index 0b10fe5e022..1f035757dea 100644 --- a/clang/test/CodeGenCXX/predefined-expr-cxx14.cpp +++ b/clang/test/CodeGenCXX/predefined-expr-cxx14.cpp @@ -17,8 +17,8 @@ // CHECK-DAG: @__func__._ZN24ClassInTopLevelNamespace25topLevelNamespaceFunctionEv = private unnamed_addr constant [26 x i8] c"topLevelNamespaceFunction\00" // CHECK-DAG: @__PRETTY_FUNCTION__._ZN24ClassInTopLevelNamespace25topLevelNamespaceFunctionEv = private unnamed_addr constant [60 x i8] c"auto *ClassInTopLevelNamespace::topLevelNamespaceFunction()\00" -// CHECK-DAG: @__func__.___ZN16ClassBlockConstrD2Ev_block_invoke = private unnamed_addr constant [41 x i8] c"___ZN16ClassBlockConstrD1Ev_block_invoke\00" -// CHECK-DAG: @__func__.___ZN16ClassBlockConstrC2Ev_block_invoke = private unnamed_addr constant [41 x i8] c"___ZN16ClassBlockConstrC1Ev_block_invoke\00" +// CHECK-DAG: @__func__.___ZN16ClassBlockConstrD2Ev_block_invoke = private unnamed_addr constant [41 x i8] c"___ZN16ClassBlockConstrD2Ev_block_invoke\00" +// CHECK-DAG: @__func__.___ZN16ClassBlockConstrC2Ev_block_invoke = private unnamed_addr constant [41 x i8] c"___ZN16ClassBlockConstrC2Ev_block_invoke\00" int printf(const char * _Format, ...); |