From 0e60e4ed9d10d5ef2623c79f9a3a3e854b78e212 Mon Sep 17 00:00:00 2001 From: "John F. Carr" Date: Fri, 30 Aug 2024 12:30:10 -0400 Subject: [PATCH] Only pop a cleanup scope in ~TaskFrameScope if one was pushed in TaskFrameScope. --- clang/lib/CodeGen/CGCilk.cpp | 2 +- clang/test/Cilk/266.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 clang/test/Cilk/266.cpp diff --git a/clang/lib/CodeGen/CGCilk.cpp b/clang/lib/CodeGen/CGCilk.cpp index ce842f895a3f..72a9faaf66e8 100644 --- a/clang/lib/CodeGen/CGCilk.cpp +++ b/clang/lib/CodeGen/CGCilk.cpp @@ -371,7 +371,7 @@ CodeGenFunction::TaskFrameScope::TaskFrameScope(CodeGenFunction &CGF) CodeGenFunction::TaskFrameScope::~TaskFrameScope() { if (LangOptions::Cilk_none == CGF.getLangOpts().getCilk()) return; - if (!CGF.CurSyncRegion) + if (!TaskFrame) return; // Pop the taskframe. diff --git a/clang/test/Cilk/266.cpp b/clang/test/Cilk/266.cpp new file mode 100644 index 000000000000..3287ce9480b8 --- /dev/null +++ b/clang/test/Cilk/266.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx14.0.0 -emit-llvm -S -fopencilk -disable-llvm-passes -fcxx-exceptions -fexceptions -x c++ %s -o /dev/null +// expected-no-diagnostics +// Bug 266: unnecessary sync in catch block crashes compiler + +extern int f(); + +// Nothing really to check here. If it compiles, great. +void try_catch() { + try { + f(); + } catch (int x) { + _Cilk_sync; + } +} +