Author: Alexis Engelke
Date: 2026-03-31T12:50:25Z
New Revision: 74e84c0cf5f1f0df9671090c2e73714f6730ec16

URL: 
https://github.com/llvm/llvm-project/commit/74e84c0cf5f1f0df9671090c2e73714f6730ec16
DIFF: 
https://github.com/llvm/llvm-project/commit/74e84c0cf5f1f0df9671090c2e73714f6730ec16.diff

LOG: [Clang] Fix getTerminator() use for -fasync-exceptions (#189644)

Added: 
    clang/test/CodeGen/async-exceptions.c

Modified: 
    clang/lib/CodeGen/CGException.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 9d1fe3654573c..a83a05d01121f 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1711,8 +1711,7 @@ void CodeGenFunction::VolatilizeTryBlocks(
       }
     }
   }
-  const llvm::Instruction *TI = BB->getTerminator();
-  if (TI) {
+  if (const llvm::Instruction *TI = BB->getTerminatorOrNull()) {
     unsigned N = TI->getNumSuccessors();
     for (unsigned I = 0; I < N; I++)
       VolatilizeTryBlocks(TI->getSuccessor(I), V);

diff  --git a/clang/test/CodeGen/async-exceptions.c 
b/clang/test/CodeGen/async-exceptions.c
new file mode 100644
index 0000000000000..b00f8fd5661ce
--- /dev/null
+++ b/clang/test/CodeGen/async-exceptions.c
@@ -0,0 +1,37 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions 
-fms-compatibility %s -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: define dso_local i32 @a(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] personality ptr @__C_specific_handler {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    [[B:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    [[__EXCEPTION_CODE:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    invoke void @llvm.seh.try.begin()
+// CHECK-NEXT:            to label %[[INVOKE_CONT:.*]] unwind label 
%[[CATCH_DISPATCH:.*]]
+// CHECK:       [[INVOKE_CONT]]:
+// CHECK-NEXT:    [[TMP0:%.*]] = load volatile i32, ptr [[B]], align 4
+// CHECK-NEXT:    invoke void @llvm.seh.try.end()
+// CHECK-NEXT:            to label %[[INVOKE_CONT1:.*]] unwind label 
%[[CATCH_DISPATCH]]
+// CHECK:       [[CATCH_DISPATCH]]:
+// CHECK-NEXT:    [[TMP1:%.*]] = catchswitch within none [label 
%[[__EXCEPT_RET:.*]]] unwind to caller
+// CHECK:       [[__EXCEPT_RET]]:
+// CHECK-NEXT:    [[TMP2:%.*]] = catchpad within [[TMP1]] [ptr 
@"?filt$0@0@a@@"]
+// CHECK-NEXT:    catchret from [[TMP2]] to label %[[__EXCEPT:.*]]
+// CHECK:       [[__EXCEPT]]:
+// CHECK-NEXT:    [[TMP3:%.*]] = call i32 @llvm.eh.exceptioncode(token 
[[TMP2]])
+// CHECK-NEXT:    store i32 [[TMP3]], ptr [[__EXCEPTION_CODE]], align 4
+// CHECK-NEXT:    br label %[[__TRY_CONT:.*]]
+// CHECK:       [[__TRY_CONT]]:
+// CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[RETVAL]], align 4
+// CHECK-NEXT:    ret i32 [[TMP4]]
+// CHECK:       [[INVOKE_CONT1]]:
+// CHECK-NEXT:    br label %[[__TRY_CONT]]
+//
+long a() {
+  long b;
+  __try {
+    b;
+  } __except (a()) {
+  }
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to