[clang] [clang][bytecode] Support compile-time exceptions (PR #189410)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 13 01:06:01 PDT 2026
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
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,94 @@
+//===-------------------------- 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"
+#include "clang/AST/CXXInheritance.h"
+
+using namespace clang;
+using namespace clang::interp;
+
+static bool isRecordOrPointerToRecordType(const Type *T) {
+ return T->isRecordType() ||
+ (T->isPointerOrReferenceType() && T->getPointeeType()->isRecordType());
+}
+
+bool ExceptionTableEntry::canCatch(const Type *ThrowType,
+ const ASTContext &ASTCtx) 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 (including member pointers)
+ // and references of pointer types.
+ if (ThrowType->isNullPtrType()) {
+ if (CatchType->isPointerType() || CatchType->isMemberPointerType())
+ return true;
+ if (CatchType->isReferenceType() &&
+ CatchType->getPointeeType()->isPointerType())
----------------
tbaederr wrote:
I asked a gcc developer about the nullptr->memberpointer conversion, which doesn't work in gcc: https://godbolt.org/z/dnacEcP38
In my case, there's not really a good point where we could do the pointer -> memberpointer conversion. I added a test case and wrote a comment for it. It's currently failing in `LoadPop()`.
https://github.com/llvm/llvm-project/pull/189410
More information about the cfe-commits
mailing list