Skip to content

Commit 3b2512b

Browse files
authored
[clang] Added a new attribute 'DisableTryStmt'
1 parent 2e4809a commit 3b2512b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

clang/lib/CodeGen/CGException.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
633633

634634
// If try statements are disabled, just emit the try statement as a compound
635635
// stmt.
636-
if (CGM.getCodeGenOpts().DisableTryStmt) {
636+
if (CGM.getCodeGenOpts().DisableTryStmt ||
637+
(CurCodeDecl && CurCodeDecl->hasAttr<DisableTryStmtAttr>())) {
637638
EmitStmt(S.getTryBlock());
638639
return;
639640
}
@@ -1752,7 +1753,8 @@ void CodeGenFunction::EmitSEHTryStmt(const SEHTryStmt &S) {
17521753

17531754
// If try statements are disabled, just emit the try statement as a compound
17541755
// stmt.
1755-
if (CGM.getCodeGenOpts().DisableTryStmt) {
1756+
if (CGM.getCodeGenOpts().DisableTryStmt ||
1757+
(CurCodeDecl && CurCodeDecl->hasAttr<DisableTryStmtAttr>())) {
17561758
EmitStmt(S.getTryBlock());
17571759
return;
17581760
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
408408
if (CurCodeDecl && CurCodeDecl->hasAttr<VolatileAttr>())
409409
CurFn->setVolatileAndAppendToUsed();
410410

411+
// Check 'DisableTryStmt' attribute
412+
if (CurCodeDecl && CurCodeDecl->hasAttr<DisableTryStmtAttr>())
413+
CurFn->addFnAttr("no-try-stmt");
414+
411415
// Reset the debug location to that of the simple 'return' expression, if any
412416
// rather than that of the end of the function's scope '}'.
413417
ApplyDebugLocation AL(*this, Loc);

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,10 @@ static void handleVolatileAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
21992199
D->addAttr(::new (S.Context) UsedAttr(S.Context, AL));
22002200
}
22012201

2202+
static void handleDisableTryStmtAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2203+
D->addAttr(::new (S.Context) DisableTryStmtAttr(S.Context, AL));
2204+
}
2205+
22022206
static void handleNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) {
22032207
if (hasDeclarator(D)) return;
22042208

@@ -9159,6 +9163,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
91599163
case ParsedAttr::AT_Volatile:
91609164
handleVolatileAttr(S, D, AL);
91619165
break;
9166+
case ParsedAttr::AT_DisableTryStmt:
9167+
handleDisableTryStmtAttr(S, D, AL);
9168+
break;
91629169
case ParsedAttr::AT_NoReturn:
91639170
handleNoReturnAttr(S, D, AL);
91649171
break;

0 commit comments

Comments
 (0)