clang 22.0.0git
CIRGenException.cpp
Go to the documentation of this file.
1//===--- CIRGenException.cpp - Emit CIR Code for C++ exceptions -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code dealing with C++ exception related code generation.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenCXXABI.h"
14#include "CIRGenFunction.h"
15
17
18using namespace clang;
19using namespace clang::CIRGen;
20
22 const llvm::Triple &triple = getTarget().getTriple();
23 if (cgm.getLangOpts().OpenMPIsTargetDevice &&
24 (triple.isNVPTX() || triple.isAMDGCN())) {
25 cgm.errorNYI("emitCXXThrowExpr OpenMP with NVPTX or AMDGCN Triples");
26 return;
27 }
28
29 if (const Expr *subExpr = e->getSubExpr()) {
30 QualType throwType = subExpr->getType();
31 if (throwType->isObjCObjectPointerType()) {
32 cgm.errorNYI("emitCXXThrowExpr ObjCObjectPointerType");
33 return;
34 }
35
36 cgm.getCXXABI().emitThrow(*this, e);
37 return;
38 }
39
40 cgm.getCXXABI().emitRethrow(*this, /*isNoReturn=*/true);
41}
42
44 // Make sure the exception object is cleaned up if there's an
45 // exception during initialization.
47
48 // __cxa_allocate_exception returns a void*; we need to cast this
49 // to the appropriate type for the object.
50 mlir::Type ty = convertTypeForMem(e->getType());
51 Address typedAddr = addr.withElementType(builder, ty);
52
53 // From LLVM's codegen:
54 // FIXME: this isn't quite right! If there's a final unelided call
55 // to a copy constructor, then according to [except.terminate]p1 we
56 // must call std::terminate() if that constructor throws, because
57 // technically that copy occurs after the exception expression is
58 // evaluated but before the exception is caught. But the best way
59 // to handle that is to teach EmitAggExpr to do the final copy
60 // differently if it can't be elided.
61 emitAnyExprToMem(e, typedAddr, e->getType().getQualifiers(),
62 /*isInitializer=*/true);
63
64 // Deactivate the cleanup block.
66}
67
68mlir::LogicalResult CIRGenFunction::emitCXXTryStmt(const CXXTryStmt &s) {
69 if (s.getTryBlock()->body_empty())
70 return mlir::LogicalResult::success();
71
72 cgm.errorNYI("exitCXXTryStmt: CXXTryStmt with non-empty body");
73 return mlir::LogicalResult::success();
74}
__device__ __2f16 float __ockl_bool s
Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const
Return address with different element type, a bitcast pointer, and the same alignment.
const TargetInfo & getTarget() const
void emitAnyExprToExn(const Expr *e, Address addr)
void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals, bool isInitializer)
Emits the code necessary to evaluate an arbitrary expression into the given memory location.
mlir::Type convertTypeForMem(QualType t)
mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s)
void emitCXXThrowExpr(const CXXThrowExpr *e)
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1209
const Expr * getSubExpr() const
Definition ExprCXX.h:1229
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
This represents one expression.
Definition Expr.h:112
QualType getType() const
Definition Expr.h:144
A (possibly-)qualified type.
Definition TypeBase.h:937
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8330
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool isObjCObjectPointerType() const
Definition TypeBase.h:8696
The JSON file list parser is used to communicate input to InstallAPI.
static bool ehCleanupScope()