Skip to content

Commit 9255580

Browse files
authored
[clang] fix skipped parsing of late parsed attributes (#153558)
1 parent 9315d70 commit 9255580

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ Bug Fixes to Attribute Support
192192

193193
- ``[[nodiscard]]`` is now respected on Objective-C and Objective-C++ methods.
194194
(#GH141504)
195+
- Fixes some late parsed attributes, when applied to function definitions, not being parsed
196+
in function try blocks, and some situations where parsing of the function body
197+
is skipped, such as error recovery and code completion. (#GH153551)
195198
- Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with
196199
``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520)
197200

clang/lib/Parse/Parser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,10 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
14181418
// parameter list was specified.
14191419
CurTemplateDepthTracker.addDepth(1);
14201420

1421+
// Late attributes are parsed in the same scope as the function body.
1422+
if (LateParsedAttrs)
1423+
ParseLexedAttributeList(*LateParsedAttrs, Res, false, true);
1424+
14211425
if (SkipFunctionBodies && (!Res || Actions.canSkipFunctionBody(Res)) &&
14221426
trySkippingFunctionBody()) {
14231427
BodyScope.Exit();
@@ -1442,10 +1446,6 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
14421446
} else
14431447
Actions.ActOnDefaultCtorInitializers(Res);
14441448

1445-
// Late attributes are parsed in the same scope as the function body.
1446-
if (LateParsedAttrs)
1447-
ParseLexedAttributeList(*LateParsedAttrs, Res, false, true);
1448-
14491449
return ParseFunctionStatementBody(Res, BodyScope);
14501450
}
14511451

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Trivial check to ensure skip-function-bodies flag is propagated.
22
//
3-
// RUN: %clang_cc1 -verify -skip-function-bodies -pedantic-errors %s
4-
// expected-no-diagnostics
3+
// RUN: %clang_cc1 -verify -skip-function-bodies %s
54

65
int f() {
76
// normally this should emit some diags, but we're skipping it!
87
this is garbage;
98
}
109

10+
void g() __attribute__((__diagnose_if__(baz))) {}
11+
// expected-error@-1 {{use of undeclared identifier 'baz'}}
12+
1113
// Make sure we only accept it as a cc1 arg.
1214
// RUN: not %clang -skip-function-bodies %s 2>&1 | FileCheck %s
1315
// CHECK: clang: error: unknown argument '-skip-function-bodies'; did you mean '-Xclang -skip-function-bodies'?

clang/test/Parser/diagnose_if.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 %s -fsyntax-only -fcxx-exceptions -verify
2+
3+
void t1() __attribute__((__diagnose_if__(baz))) try {} catch(...) {}
4+
// expected-error@-1 {{use of undeclared identifier 'baz'}}
5+
6+
struct A {
7+
A();
8+
};
9+
10+
A::A() __attribute__((__diagnose_if__(baz))) :;
11+
// expected-error@-1 {{expected class member or base class name}}
12+
// expected-error@-2 {{use of undeclared identifier 'baz'}}

0 commit comments

Comments
 (0)