Author: smeenai Date: Wed Apr 11 11:17:35 2018 New Revision: 329836 URL: http://llvm.org/viewvc/llvm-project?rev=329836&view=rev Log: [CodeGen] Handle __func__ inside __finally
When we enter a __finally block, the CGF's CurCodeDecl will be null (because CodeGenFunction::StartFunction is given an empty GlobalDecl for a __finally block), and so the dyn_cast here will result in an assertion failure. Change it to dyn_cast_or_null to handle this case. Differential Revision: https://reviews.llvm.org/D45523 Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/test/CodeGen/exceptions-seh-finally.c Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=329836&r1=329835&r2=329836&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Apr 11 11:17:35 2018 @@ -2611,7 +2611,7 @@ LValue CodeGenFunction::EmitPredefinedLV StringRef NameItems[] = { PredefinedExpr::getIdentTypeName(E->getIdentType()), FnName}; std::string GVName = llvm::join(NameItems, NameItems + 2, "."); - if (auto *BD = dyn_cast<BlockDecl>(CurCodeDecl)) { + if (auto *BD = dyn_cast_or_null<BlockDecl>(CurCodeDecl)) { std::string Name = SL->getString(); if (!Name.empty()) { unsigned Discriminator = Modified: cfe/trunk/test/CodeGen/exceptions-seh-finally.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exceptions-seh-finally.c?rev=329836&r1=329835&r2=329836&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/exceptions-seh-finally.c (original) +++ cfe/trunk/test/CodeGen/exceptions-seh-finally.c Wed Apr 11 11:17:35 2018 @@ -268,6 +268,18 @@ void finally_within_finally() { // CHECK-LABEL: define internal void @"?fin$1@0@finally_within_finally@@"({{[^)]*}}) // CHECK-SAME: [[finally_attrs]] +void cleanup_with_func(const char *); +void finally_with_func() { + __try { + might_crash(); + } __finally { + cleanup_with_func(__func__); + } +} + +// CHECK-LABEL: define internal void @"?fin$0@0@finally_with_func@@"({{[^)]*}}) +// CHECK: call void @cleanup_with_func(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"??_C@_0BC@COAGBPGM@finally_with_func?$AA@", i32 0, i32 0)) + // Look for the absence of noinline. Enum attributes come first, so check that // a string attribute is the first to verify that no enum attributes are // present. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits