File: fp-eval-pragma.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (97 lines) | stat: -rw-r--r-- 2,874 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// RUN: %clang_cc1 -fexperimental-strict-floating-point \
// RUN: -triple x86_64-linux-gnu -emit-llvm -o - -verify %s
//
// RUN: %clang_cc1 -fexperimental-strict-floating-point \
// RUN: -triple x86_64-linux-gnu -emit-llvm -o - -verify %s \
// RUN: -ffp-eval-method=source
//
// RUN: %clang_cc1 -fexperimental-strict-floating-point \
// RUN: -triple x86_64-linux-gnu -emit-llvm -o - -verify %s \
// RUN: -ffp-eval-method=double

extern "C" int printf(const char *, ...);

void foo1() {
  printf("FP: %d\n", __FLT_EVAL_METHOD__);
}

void apply_pragma() {
  // expected-note@+1{{#pragma entered here}}
#pragma clang fp eval_method(double)
  // expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}}
  printf("FP: %d\n", __FLT_EVAL_METHOD__);
}

int foo2() {
  apply_pragma();
  return 0;
}

void apply_pragma_with_wrong_value() {
  // expected-error@+1{{unexpected argument 'value' to '#pragma clang fp eval_method'; expected 'source', 'double' or 'extended'}}
#pragma clang fp eval_method(value)
}

int foo3() {
  apply_pragma_with_wrong_value();
  return 0;
}

void foo() {
  auto a = __FLT_EVAL_METHOD__;
  {
    // expected-note@+1{{#pragma entered here}}
#pragma clang fp eval_method(double)
    // expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}}
    auto b = __FLT_EVAL_METHOD__;
  }
  auto c = __FLT_EVAL_METHOD__;
}

void func() {
  {
    {
#pragma clang fp eval_method(source)
    }
    int i = __FLT_EVAL_METHOD__; // ok, not in a scope changed by the pragma
  }
  {
    // expected-note@+1{{#pragma entered here}}
#pragma clang fp eval_method(source)
    // expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}}
    int i = __FLT_EVAL_METHOD__;
  }
}

float G;

int f(float x, float y, float z) {
  G = x * y + z;
  return __FLT_EVAL_METHOD__;
}

int foo(int flag, float x, float y, float z) {
  if (flag) {
    // expected-note@+1{{#pragma entered here}}
#pragma clang fp eval_method(double)
    G = x + y + z;
    // expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}}
    return __FLT_EVAL_METHOD__;
  } else {
    // expected-note@+1{{#pragma entered here}}
#pragma clang fp eval_method(extended)
    G = x + y + z;
    // expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}}
    return __FLT_EVAL_METHOD__;
  }
}

#if __FLT_EVAL_METHOD__ == 1
#endif
#pragma clang fp eval_method(source)

// expected-note@+1{{#pragma entered here}}
#pragma clang fp eval_method(double)
// expected-error@+1{{'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing '#pragma clang fp eval_method'}}
#if __FLT_EVAL_METHOD__ == 1
#endif