[clang] [clang][bytecode] Support compile-time exceptions (PR #189410)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 10 10:57:50 PDT 2026


Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/189410 at github.com>


================
@@ -0,0 +1,56 @@
+//===-------------------------- Exceptions.cpp ------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Exceptions.h"
+#include "clang/AST/ASTContext.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+bool ExceptionTableEntry::canCatch(const Type *ThrowType) const {
+  const Type *CatchType = this->CatchType;
+
+  if (!CatchType || ASTContext::hasSameType(CatchType, ThrowType))
+    return true;
+
+  assert(CatchType);
+
+  // nullptr_t can be caught by any pointer type.
+  if (ThrowType->isNullPtrType() && CatchType->isPointerType())
+    return true;
+
+  // void* can catch all thown pointer types.
+  if (ThrowType->isPointerType() && CatchType->isVoidPointerType())
+    return true;
+
+  if (CatchType->isPointerType() && !ThrowType->isPointerType())
+    return false;
+
+  if (CatchType->isPointerOrReferenceType())
+    CatchType = CatchType->getPointeeType().getTypePtr();
+  if (ThrowType->isPointerOrReferenceType())
+    ThrowType = ThrowType->getPointeeType().getTypePtr();
----------------
efriedma-quic wrote:

This still looks wrong?

https://github.com/llvm/llvm-project/pull/189410


More information about the cfe-commits mailing list