Skip to content

Commit 25a7180

Browse files
committed
Support more cases of function body
1 parent 07e171e commit 25a7180

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

clang/lib/Parse/ParseStmt.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,10 +2508,6 @@ Decl *Parser::ParseFunctionStatementBody(Decl *Decl, ParseScope &BodyScope) {
25082508
Sema::PragmaStackSentinelRAII
25092509
PragmaStackSentinel(Actions, "InternalPragmaState", IsCXXMethod);
25102510

2511-
// Some function attributes (like OptimizeNoneAttr) affect FP options.
2512-
Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
2513-
Actions.applyFunctionAttributesBeforeParsingBody(Decl);
2514-
25152511
// Do not enter a scope for the brace, as the arguments are in the same scope
25162512
// (the function body) as the body itself. Instead, just read the statement
25172513
// list and put it into a CompoundStmt for safe keeping.

clang/lib/Parse/Parser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,10 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
14971497
return Actions.ActOnFinishFunctionBody(Res, nullptr, false);
14981498
}
14991499

1500+
// Some function attributes (like OptimizeNoneAttr) affect FP options.
1501+
Sema::FPFeaturesStateRAII SaveFPFeatures(Actions);
1502+
Actions.applyFunctionAttributesBeforeParsingBody(Res);
1503+
15001504
if (Tok.is(tok::kw_try))
15011505
return ParseFunctionTryBlock(Res, BodyScope);
15021506

clang/test/AST/ast-dump-fpfeatures.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Test without serialization:
2-
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-linux -std=c++11 -ast-dump %s \
2+
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-linux -std=c++11 -fcxx-exceptions -ast-dump %s \
33
// RUN: | FileCheck --strict-whitespace %s
44

55
// Test with serialization:
6-
// RUN: %clang_cc1 -triple x86_64-pc-linux -emit-pch -o %t %s
7-
// RUN: %clang_cc1 -x c++ -triple x86_64-pc-linux -include-pch %t -ast-dump-all /dev/null \
6+
// RUN: %clang_cc1 -triple x86_64-pc-linux -emit-pch -fcxx-exceptions -o %t %s
7+
// RUN: %clang_cc1 -x c++ -triple x86_64-pc-linux -include-pch %t -fcxx-exceptions -ast-dump-all /dev/null \
88
// RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
99
// RUN: | FileCheck --strict-whitespace %s
1010

@@ -189,6 +189,7 @@ float func_18(float x, float y) {
189189
// CHECK: BinaryOperator {{.*}} ConstRoundingMode=downward
190190

191191
#pragma float_control(precise, off)
192+
192193
__attribute__((optnone))
193194
float func_19(float x, float y) {
194195
return x + y;
@@ -198,3 +199,26 @@ float func_19(float x, float y) {
198199
// CHECK: CompoundStmt {{.*}} MathErrno=1
199200
// CHECK: ReturnStmt
200201
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
202+
203+
__attribute__((optnone))
204+
float func_20(float x, float y) try {
205+
return x + y;
206+
} catch (...) {
207+
return 1.0;
208+
}
209+
210+
// CHECK-LABEL: FunctionDecl {{.*}} func_20 'float (float, float)'
211+
// CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
212+
// CHECK: ReturnStmt
213+
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1
214+
215+
struct C21 {
216+
C21(float x, float y);
217+
float member;
218+
};
219+
220+
__attribute__((optnone)) C21::C21(float x, float y) : member(x + y) {}
221+
222+
// CHECK-LABEL: CXXConstructorDecl {{.*}} C21 'void (float, float)'
223+
// CHECK: CXXCtorInitializer {{.*}} 'member' 'float'
224+
// CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward MathErrno=1

0 commit comments

Comments
 (0)