File: enable_if.c

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 (95 lines) | stat: -rw-r--r-- 3,432 bytes parent folder | download
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
// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck %s

// Verifying that we do, in fact, select the correct function in the following
// cases.

void foo(int m) __attribute__((overloadable, enable_if(m > 0, "")));
void foo(int m) __attribute__((overloadable));

// CHECK-LABEL: define{{.*}} void @test1
void test1(void) {
  // CHECK: store void (i32)* @_Z3fooi
  void (*p)(int) = foo;
  // CHECK: store void (i32)* @_Z3fooi
  void (*p2)(int) = &foo;
  // CHECK: store void (i32)* @_Z3fooi
  p = foo;
  // CHECK: store void (i32)* @_Z3fooi
  p = &foo;

  // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*)
  void *vp1 = (void*)&foo;
  // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*)
  void *vp2 = (void*)foo;
  // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*)
  vp1 = (void*)&foo;
  // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*)
  vp1 = (void*)foo;
}

void bar(int m) __attribute__((overloadable, enable_if(m > 0, "")));
void bar(int m) __attribute__((overloadable, enable_if(1, "")));
// CHECK-LABEL: define{{.*}} void @test2
void test2(void) {
  // CHECK: store void (i32)* @_Z3barUa9enable_ifILi1EEi
  void (*p)(int) = bar;
  // CHECK: store void (i32)* @_Z3barUa9enable_ifILi1EEi
  void (*p2)(int) = &bar;
  // CHECK: store void (i32)* @_Z3barUa9enable_ifILi1EEi
  p = bar;
  // CHECK: store void (i32)* @_Z3barUa9enable_ifILi1EEi
  p = &bar;

  // CHECK: store i8* bitcast (void (i32)* @_Z3barUa9enable_ifILi1EEi to i8*)
  void *vp1 = (void*)&bar;
  // CHECK: store i8* bitcast (void (i32)* @_Z3barUa9enable_ifILi1EEi to i8*)
  void *vp2 = (void*)bar;
  // CHECK: store i8* bitcast (void (i32)* @_Z3barUa9enable_ifILi1EEi to i8*)
  vp1 = (void*)&bar;
  // CHECK: store i8* bitcast (void (i32)* @_Z3barUa9enable_ifILi1EEi to i8*)
  vp1 = (void*)bar;
}

void baz(int m) __attribute__((overloadable, enable_if(1, "")));
void baz(int m) __attribute__((overloadable));
// CHECK-LABEL: define{{.*}} void @test3
void test3(void) {
  // CHECK: store void (i32)* @_Z3bazUa9enable_ifILi1EEi
  void (*p)(int) = baz;
  // CHECK: store void (i32)* @_Z3bazUa9enable_ifILi1EEi
  void (*p2)(int) = &baz;
  // CHECK: store void (i32)* @_Z3bazUa9enable_ifILi1EEi
  p = baz;
  // CHECK: store void (i32)* @_Z3bazUa9enable_ifILi1EEi
  p = &baz;
}


enum { TRUEFACTS = 1 };
void qux(int m) __attribute__((overloadable, enable_if(1, ""),
                               enable_if(TRUEFACTS, "")));
void qux(int m) __attribute__((overloadable, enable_if(1, "")));
// CHECK-LABEL: define{{.*}} void @test4
void test4(void) {
  // CHECK: store void (i32)* @_Z3quxUa9enable_ifILi1ELi1EEi
  void (*p)(int) = qux;
  // CHECK: store void (i32)* @_Z3quxUa9enable_ifILi1ELi1EEi
  void (*p2)(int) = &qux;
  // CHECK: store void (i32)* @_Z3quxUa9enable_ifILi1ELi1EEi
  p = qux;
  // CHECK: store void (i32)* @_Z3quxUa9enable_ifILi1ELi1EEi
  p = &qux;
}

// There was a bug where, when enable_if was present, overload resolution
// wouldn't pay attention to lower-priority attributes.
// (N.B. `foo` with pass_object_size should always be preferred)
// CHECK-LABEL: define{{.*}} void @test5
void test5(void) {
  int foo(char *i) __attribute__((enable_if(1, ""), overloadable));
  int foo(char *i __attribute__((pass_object_size(0))))
      __attribute__((enable_if(1, ""), overloadable));

  // CHECK: call i32 @_Z3fooUa9enable_ifILi1EEPcU17pass_object_size0
  foo((void*)0);
}