-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[CIR] Upstream Exception CXXTryStmt #162528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AmrDeveloper
wants to merge
3
commits into
llvm:main
Choose a base branch
from
AmrDeveloper:cir_exception_cxx_try_stmt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -858,4 +858,19 @@ def CIR_TypeInfoAttr : CIR_Attr<"TypeInfo", "typeinfo", [TypedAttrInterface]> { | |
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// CatAllAttr & CatchUnwindAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Represents the unwind region where unwind continues or | ||
// the program std::terminate's. | ||
def CIR_CatchUnwindAttr : CIR_UnitAttr<"CatchUnwind", "unwind"> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to add testcase for this one |
||
let storageType = [{ CatchUnwind }]; | ||
} | ||
|
||
// Represents the catch_all region. | ||
def CIR_CatchAllAttr : CIR_UnitAttr<"CatchAll", "all"> { | ||
let storageType = [{ CatchAllAttr }]; | ||
} | ||
|
||
#endif // CLANG_CIR_DIALECT_IR_CIRATTRS_TD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,21 +14,36 @@ | |
#ifndef CLANG_LIB_CIR_CODEGEN_CIRGENCLEANUP_H | ||
#define CLANG_LIB_CIR_CODEGEN_CIRGENCLEANUP_H | ||
|
||
#include "Address.h" | ||
#include "EHScopeStack.h" | ||
#include "mlir/IR/Value.h" | ||
#include "mlir/IR/BuiltinAttributeInterfaces.h" | ||
#include "clang/CIR/MissingFeatures.h" | ||
|
||
namespace clang::CIRGen { | ||
|
||
/// The MS C++ ABI needs a pointer to RTTI data plus some flags to describe the | ||
/// type of a catch handler, so we use this wrapper. | ||
struct CatchTypeInfo { | ||
mlir::TypedAttr rtti; | ||
unsigned flags; | ||
}; | ||
|
||
/// A protected scope for zero-cost EH handling. | ||
class EHScope { | ||
|
||
class CommonBitFields { | ||
friend class EHScope; | ||
unsigned kind : 3; | ||
}; | ||
enum { NumCommonBits = 3 }; | ||
|
||
protected: | ||
class CatchBitFields { | ||
friend class EHCatchScope; | ||
unsigned : NumCommonBits; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove newline |
||
unsigned numHandlers : 32 - NumCommonBits; | ||
}; | ||
|
||
class CleanupBitFields { | ||
friend class EHCleanupScope; | ||
unsigned : NumCommonBits; | ||
|
@@ -58,6 +73,7 @@ class EHScope { | |
|
||
union { | ||
CommonBitFields commonBits; | ||
CatchBitFields catchBits; | ||
CleanupBitFields cleanupBits; | ||
}; | ||
|
||
|
@@ -67,6 +83,72 @@ class EHScope { | |
EHScope(Kind kind) { commonBits.kind = kind; } | ||
|
||
Kind getKind() const { return static_cast<Kind>(commonBits.kind); } | ||
|
||
bool hasEHBranches() const { | ||
// Traditional LLVM codegen also checks for `!block->use_empty()`, but | ||
// in CIRGen the block content is not important, just used as a way to | ||
// signal `hasEHBranches`. | ||
assert(!cir::MissingFeatures::ehstackBranches()); | ||
return false; | ||
} | ||
}; | ||
|
||
/// A scope which attempts to handle some, possibly all, types of | ||
/// exceptions. | ||
/// | ||
/// Objective C \@finally blocks are represented using a cleanup scope | ||
/// after the catch scope. | ||
|
||
class EHCatchScope : public EHScope { | ||
// In effect, we have a flexible array member | ||
// Handler Handlers[0]; | ||
// But that's only standard in C99, not C++, so we have to do | ||
// annoying pointer arithmetic instead. | ||
|
||
public: | ||
struct Handler { | ||
/// A type info value, or null (C++ null, not an LLVM null pointer) | ||
/// for a catch-all. | ||
CatchTypeInfo type; | ||
|
||
/// The catch handler for this type. | ||
mlir::Block *block; | ||
}; | ||
|
||
private: | ||
friend class EHScopeStack; | ||
|
||
Handler *getHandlers() { return reinterpret_cast<Handler *>(this + 1); } | ||
|
||
public: | ||
static size_t getSizeForNumHandlers(unsigned n) { | ||
return sizeof(EHCatchScope) + n * sizeof(Handler); | ||
} | ||
|
||
EHCatchScope(unsigned numHandlers) : EHScope(Catch) { | ||
catchBits.numHandlers = numHandlers; | ||
assert(catchBits.numHandlers == numHandlers && "NumHandlers overflow?"); | ||
} | ||
|
||
unsigned getNumHandlers() const { return catchBits.numHandlers; } | ||
|
||
void setHandler(unsigned i, CatchTypeInfo type, mlir::Block *block) { | ||
assert(i < getNumHandlers()); | ||
getHandlers()[i].type = type; | ||
getHandlers()[i].block = block; | ||
} | ||
|
||
// Clear all handler blocks. | ||
// FIXME: it's better to always call clearHandlerBlocks in DTOR and have a | ||
// 'takeHandler' or some such function which removes ownership from the | ||
// EHCatchScope object if the handlers should live longer than EHCatchScope. | ||
void clearHandlerBlocks() { | ||
// The blocks are owned by TryOp, nothing to delete. | ||
} | ||
|
||
static bool classof(const EHScope *scope) { | ||
return scope->getKind() == Catch; | ||
} | ||
}; | ||
|
||
/// A cleanup scope which generates the cleanup blocks lazily. | ||
|
@@ -147,5 +229,13 @@ EHScopeStack::find(stable_iterator savePoint) const { | |
return iterator(endOfBuffer - savePoint.size); | ||
} | ||
|
||
inline void EHScopeStack::popCatch() { | ||
assert(!empty() && "popping exception stack when not empty"); | ||
|
||
EHCatchScope &scope = llvm::cast<EHCatchScope>(*begin()); | ||
assert(!cir::MissingFeatures::innermostEHScope()); | ||
deallocate(EHCatchScope::getSizeForNumHandlers(scope.getNumHandlers())); | ||
} | ||
|
||
} // namespace clang::CIRGen | ||
#endif // CLANG_LIB_CIR_CODEGEN_CIRGENCLEANUP_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CatAllAttr -> CatchAllAttr