r222065 - This patch fixes couple of bugs for predefined expression
Fariborz Jahanian
fjahanian at apple.com
Fri Nov 14 15:55:28 PST 2014
Author: fjahanian
Date: Fri Nov 14 17:55:27 2014
New Revision: 222065
URL: http://llvm.org/viewvc/llvm-project?rev=222065&view=rev
Log:
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
Added:
cfe/trunk/test/CodeGen/block-with-perdefinedexpr.c
Modified:
cfe/trunk/lib/AST/Mangle.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/predefined-expr-cxx14.cpp
Modified: cfe/trunk/lib/AST/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Mangle.cpp?rev=222065&r1=222064&r2=222065&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Mangle.cpp (original)
+++ cfe/trunk/lib/AST/Mangle.cpp Fri Nov 14 17:55:27 2014
@@ -234,17 +234,19 @@ void MangleContext::mangleBlock(const De
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();
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=222065&r1=222064&r2=222065&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Nov 14 17:55:27 2014
@@ -2081,7 +2081,10 @@ LValue CodeGenFunction::EmitPredefinedLV
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());
}
Added: cfe/trunk/test/CodeGen/block-with-perdefinedexpr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/block-with-perdefinedexpr.c?rev=222065&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/block-with-perdefinedexpr.c (added)
+++ cfe/trunk/test/CodeGen/block-with-perdefinedexpr.c Fri Nov 14 17:55:27 2014
@@ -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
Modified: cfe/trunk/test/CodeGenCXX/predefined-expr-cxx14.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/predefined-expr-cxx14.cpp?rev=222065&r1=222064&r2=222065&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/predefined-expr-cxx14.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/predefined-expr-cxx14.cpp Fri Nov 14 17:55:27 2014
@@ -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, ...);
More information about the cfe-commits
mailing list