diff options
author | Adam Nemet <anemet@apple.com> | 2017-04-04 21:18:36 +0000 |
---|---|---|
committer | Adam Nemet <anemet@apple.com> | 2017-04-04 21:18:36 +0000 |
commit | 6abfe5cfd2160d5c1c8594673ae995151afad6f5 (patch) | |
tree | c38661f2d72b5a066293aedfdeb3321063c03d80 /test/Parser | |
parent | a51d8c8b113f752e56cb46d32ce9ce41e452be33 (diff) |
Add #pragma clang fp
This adds the new pragma and the first variant, contract(on/off/fast).
The pragma has the same block scope rules as STDC FP_CONTRACT, i.e. it can be
placed at the beginning of a compound statement or at file scope.
Similarly to STDC FP_CONTRACT there is no need to use attributes. First an
annotate token is inserted with the parsed details of the pragma. Then the
annotate token is parsed in the proper contexts and the Sema is updated with
the corresponding FPOptions using the shared ActOn function with STDC
FP_CONTRACT.
After this the FPOptions from the Sema is propagated into the AST expression
nodes. There is no change here.
I was going to add a 'default' option besides 'on/off/fast' similar to STDC
FP_CONTRACT but then decided against it. I think that we'd have to make option
uppercase then to avoid using 'default' the keyword. Also because of the
scoped activation of pragma I am not sure there is really a need a for this.
Differential Revision: https://reviews.llvm.org/D31276
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299470 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Parser')
-rw-r--r-- | test/Parser/cxx11-stmt-attributes.cpp | 1 | ||||
-rw-r--r-- | test/Parser/pragma-fp.cpp | 64 |
2 files changed, 65 insertions, 0 deletions
diff --git a/test/Parser/cxx11-stmt-attributes.cpp b/test/Parser/cxx11-stmt-attributes.cpp index 9374b58b1f..75fb37ea9f 100644 --- a/test/Parser/cxx11-stmt-attributes.cpp +++ b/test/Parser/cxx11-stmt-attributes.cpp @@ -80,5 +80,6 @@ void foo(int i) { { [[ ]] // expected-error {{an attribute list cannot appear here}} #pragma STDC FP_CONTRACT ON // expected-error {{can only appear at file scope or at the start of a compound statement}} +#pragma clang fp contract(fast) // expected-error {{can only appear at file scope or at the start of a compound statement}} } } diff --git a/test/Parser/pragma-fp.cpp b/test/Parser/pragma-fp.cpp new file mode 100644 index 0000000000..00547bfb54 --- /dev/null +++ b/test/Parser/pragma-fp.cpp @@ -0,0 +1,64 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +void test_0(int *List, int Length) { +/* expected-error@+1 {{missing option; expected contract}} */ +#pragma clang fp + for (int i = 0; i < Length; i++) { + List[i] = i; + } +} +void test_1(int *List, int Length) { +/* expected-error@+1 {{invalid option 'blah'; expected contract}} */ +#pragma clang fp blah + for (int i = 0; i < Length; i++) { + List[i] = i; + } +} + +void test_3(int *List, int Length) { +/* expected-error@+1 {{expected '('}} */ +#pragma clang fp contract on + for (int i = 0; i < Length; i++) { + List[i] = i; + } +} + +void test_4(int *List, int Length) { +/* expected-error@+1 {{unexpected argument 'while' to '#pragma clang fp contract'; expected 'on', 'fast' or 'off'}} */ +#pragma clang fp contract(while) + for (int i = 0; i < Length; i++) { + List[i] = i; + } +} + +void test_5(int *List, int Length) { +/* expected-error@+1 {{unexpected argument 'maybe' to '#pragma clang fp contract'; expected 'on', 'fast' or 'off'}} */ +#pragma clang fp contract(maybe) + for (int i = 0; i < Length; i++) { + List[i] = i; + } +} + +void test_6(int *List, int Length) { +/* expected-error@+1 {{expected ')'}} */ +#pragma clang fp contract(fast + for (int i = 0; i < Length; i++) { + List[i] = i; + } +} + +void test_7(int *List, int Length) { +/* expected-warning@+1 {{extra tokens at end of '#pragma clang fp' - ignored}} */ +#pragma clang fp contract(fast) * + for (int i = 0; i < Length; i++) { + List[i] = i; + } +} + +void test_8(int *List, int Length) { + for (int i = 0; i < Length; i++) { + List[i] = i; +/* expected-error@+1 {{'#pragma clang fp' can only appear at file scope or at the start of a compound statement}} */ +#pragma clang fp contract(fast) + } +} |