| 1 |
// RUN: %clang_cc1 -fexperimental-strict-floating-point \ |
| 2 |
// RUN: -triple x86_64-linux-gnu -emit-llvm -o - -verify %s |
| 3 |
// |
| 4 |
// RUN: %clang_cc1 -fexperimental-strict-floating-point \ |
| 5 |
// RUN: -triple x86_64-linux-gnu -emit-llvm -o - -verify %s \ |
| 6 |
// RUN: -ffp-eval-method=source |
| 7 |
// |
| 8 |
// RUN: %clang_cc1 -fexperimental-strict-floating-point \ |
| 9 |
// RUN: -triple x86_64-linux-gnu -emit-llvm -o - -verify %s \ |
| 10 |
// RUN: -ffp-eval-method=double |
| 11 |
|
| 12 |
extern "C" int printf(const char *, ...); |
| 13 |
|
| 14 |
void foo1() { |
| 15 |
printf("FP: %d\n", __FLT_EVAL_METHOD__); |
| 16 |
} |
| 17 |
|
| 18 |
void apply_pragma() { |
| 19 |
// expected-note@+1{{#pragma entered here}} |
| 20 |
#pragma clang fp eval_method(double) |
| 21 |
// expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}} |
| 22 |
printf("FP: %d\n", __FLT_EVAL_METHOD__); |
| 23 |
} |
| 24 |
|
| 25 |
int foo2() { |
| 26 |
apply_pragma(); |
| 27 |
return 0; |
| 28 |
} |
| 29 |
|
| 30 |
void apply_pragma_with_wrong_value() { |
| 31 |
// expected-error@+1{{unexpected argument 'value' to '#pragma clang fp eval_method'; expected 'source', 'double' or 'extended'}} |
| 32 |
#pragma clang fp eval_method(value) |
| 33 |
} |
| 34 |
|
| 35 |
int foo3() { |
| 36 |
apply_pragma_with_wrong_value(); |
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
void foo() { |
| 41 |
auto a = __FLT_EVAL_METHOD__; |
| 42 |
{ |
| 43 |
// expected-note@+1{{#pragma entered here}} |
| 44 |
#pragma clang fp eval_method(double) |
| 45 |
// expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}} |
| 46 |
auto b = __FLT_EVAL_METHOD__; |
| 47 |
} |
| 48 |
auto c = __FLT_EVAL_METHOD__; |
| 49 |
} |
| 50 |
|
| 51 |
void func() { |
| 52 |
{ |
| 53 |
{ |
| 54 |
#pragma clang fp eval_method(source) |
| 55 |
} |
| 56 |
int i = __FLT_EVAL_METHOD__; // ok, not in a scope changed by the pragma |
| 57 |
} |
| 58 |
{ |
| 59 |
// expected-note@+1{{#pragma entered here}} |
| 60 |
#pragma clang fp eval_method(source) |
| 61 |
// expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}} |
| 62 |
int i = __FLT_EVAL_METHOD__; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
float G; |
| 67 |
|
| 68 |
int f(float x, float y, float z) { |
| 69 |
G = x * y + z; |
| 70 |
return __FLT_EVAL_METHOD__; |
| 71 |
} |
| 72 |
|
| 73 |
int foo(int flag, float x, float y, float z) { |
| 74 |
if (flag) { |
| 75 |
// expected-note@+1{{#pragma entered here}} |
| 76 |
#pragma clang fp eval_method(double) |
| 77 |
G = x + y + z; |
| 78 |
// expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}} |
| 79 |
return __FLT_EVAL_METHOD__; |
| 80 |
} else { |
| 81 |
// expected-note@+1{{#pragma entered here}} |
| 82 |
#pragma clang fp eval_method(extended) |
| 83 |
G = x + y + z; |
| 84 |
// expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}} |
| 85 |
return __FLT_EVAL_METHOD__; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
#if __FLT_EVAL_METHOD__ == 1 |
| 90 |
#endif |
| 91 |
#pragma clang fp eval_method(source) |
| 92 |
|
| 93 |
// expected-note@+1{{#pragma entered here}} |
| 94 |
#pragma clang fp eval_method(double) |
| 95 |
// expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}} |
| 96 |
#if __FLT_EVAL_METHOD__ == 1 |
| 97 |
#endif |