Skip to content

Commit 1140d27

Browse files
committed
C++: Add tests for newly supported builtin operations
1 parent 2410321 commit 1140d27

File tree

4 files changed

+230
-2
lines changed

4 files changed

+230
-2
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// semmle-extractor-options: --clang --clang_version 100000
2+
3+
struct S {
4+
void f() {}
5+
int o;
6+
};
7+
8+
using f_type = decltype(&S::f);
9+
using o_type = decltype(&S::o);
10+
11+
struct T;
12+
13+
bool b_is_same1 = __is_same(int, int);
14+
bool b_is_same2 = __is_same(int, float);
15+
16+
bool b_is_function1 = __is_function(void(int));
17+
bool b_is_function2 = __is_function(int);
18+
19+
bool b_is_array1 = __is_array(int[]);
20+
bool b_is_array2 = __is_array(int);
21+
22+
unsigned long b_array_rank1 = __array_rank(int[42][42]);
23+
unsigned long b_array_rank2 = __array_rank(int);
24+
25+
unsigned long b_array_extent1 = __array_extent(int[42][42], 1);
26+
unsigned long b_array_extent2 = __array_extent(int[42][42], 2);
27+
unsigned long b_array_extent3 = __array_extent(int, 0);
28+
29+
bool bok_is_arithmetic1 = __is_arithmetic(S);
30+
bool bok_is_arithmetic2 = __is_arithmetic(int);
31+
32+
bool bok_is_complete_type1 = __is_complete_type(S);
33+
bool bok_is_complete_type2 = __is_complete_type(T);
34+
35+
bool bok_is_compound1 = __is_compound(S);
36+
bool bok_is_compound2 = __is_compound(int);
37+
38+
bool bok_is_const1 = __is_const(const int);
39+
bool bok_is_const2 = __is_const(int);
40+
41+
bool bok_is_floating_point1 = __is_floating_point(int);
42+
bool bok_is_floating_point2 = __is_floating_point(float);
43+
44+
bool bok_is_fundamental1 = __is_fundamental(S);
45+
bool bok_is_fundamental2 = __is_fundamental(int);
46+
47+
bool bok_is_integral1 = __is_integral(float);
48+
bool bok_is_integral2 = __is_integral(int);
49+
50+
bool bok_is_lvalue_reference1 = __is_lvalue_reference(int&);
51+
bool bok_is_lvalue_reference2 = __is_lvalue_reference(int);
52+
53+
bool bok_is_member_function_pointer1 = __is_member_function_pointer(f_type);
54+
bool bok_is_member_function_pointer2 = __is_member_function_pointer(o_type);
55+
56+
bool bok_is_member_object_pointer1 = __is_member_object_pointer(f_type);
57+
bool bok_is_member_object_pointer2 = __is_member_object_pointer(o_type);
58+
59+
bool bok_is_member_pointer1 = __is_member_pointer(f_type);
60+
bool bok_is_member_pointer2 = __is_member_pointer(o_type);
61+
bool bok_is_member_pointer3 = __is_member_pointer(int);
62+
63+
bool bok_is_object1 = __is_object(int);
64+
bool bok_is_object2 = __is_object(int&);
65+
66+
bool bok_is_pointer1 = __is_pointer(int);
67+
bool bok_is_pointer2 = __is_pointer(int*);
68+
69+
bool bok_is_reference1 = __is_reference(int);
70+
bool bok_is_reference2 = __is_reference(int&);
71+
72+
bool bok_is_rvalue_reference1 = __is_rvalue_reference(int&&);
73+
bool bok_is_rvalue_reference2 = __is_rvalue_reference(int);
74+
75+
bool bok_is_scalar1 = __is_scalar(int);
76+
bool bok_is_scalar2 = __is_scalar(int[]);
77+
78+
bool bok_is_signed1 = __is_signed(int);
79+
bool bok_is_signed2 = __is_signed(unsigned int);
80+
81+
bool bok_is_unsigned1 = __is_unsigned(int);
82+
bool bok_is_unsigned2 = __is_unsigned(unsigned int);
83+
84+
bool bok_is_void1 = __is_void(void);
85+
bool bok_is_void2 = __is_void(int);
86+
87+
bool bok_is_volatile1 = __is_volatile(volatile int);
88+
bool bok_is_volatile2 = __is_volatile(int);

cpp/ql/test/library-tests/builtins/type_traits/expr.expected

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,126 @@
1+
| clang.cpp:8:25:8:29 | f | | <none> |
2+
| clang.cpp:9:25:9:29 | o | | <none> |
3+
| clang.cpp:13:19:13:37 | __is_same | int,int | 1 |
4+
| clang.cpp:13:19:13:37 | int | | <none> |
5+
| clang.cpp:13:19:13:37 | int | | <none> |
6+
| clang.cpp:14:19:14:39 | __is_same | int,float | 0 |
7+
| clang.cpp:14:19:14:39 | float | | <none> |
8+
| clang.cpp:14:19:14:39 | int | | <none> |
9+
| clang.cpp:16:23:16:46 | ..()(..) | | <none> |
10+
| clang.cpp:16:23:16:46 | __is_function | ..()(..) | 1 |
11+
| clang.cpp:17:23:17:40 | __is_function | int | 0 |
12+
| clang.cpp:17:23:17:40 | int | | <none> |
13+
| clang.cpp:19:20:19:36 | __is_array | int[] | 1 |
14+
| clang.cpp:19:20:19:36 | int[] | | <none> |
15+
| clang.cpp:20:20:20:34 | __is_array | int | 0 |
16+
| clang.cpp:20:20:20:34 | int | | <none> |
17+
| clang.cpp:22:31:22:55 | __array_rank | int[42][42] | 2 |
18+
| clang.cpp:22:31:22:55 | int[42][42] | | <none> |
19+
| clang.cpp:22:48:22:49 | 42 | | 42 |
20+
| clang.cpp:22:48:22:49 | (unsigned long)... | | 42 |
21+
| clang.cpp:22:52:22:53 | 42 | | 42 |
22+
| clang.cpp:22:52:22:53 | (unsigned long)... | | 42 |
23+
| clang.cpp:23:31:23:47 | __array_rank | int | 0 |
24+
| clang.cpp:23:31:23:47 | int | | <none> |
25+
| clang.cpp:25:33:25:62 | __array_extent | int[42][42],1 | 42 |
26+
| clang.cpp:25:33:25:62 | int[42][42] | | <none> |
27+
| clang.cpp:25:52:25:53 | 42 | | 42 |
28+
| clang.cpp:25:52:25:53 | (unsigned long)... | | 42 |
29+
| clang.cpp:25:56:25:57 | 42 | | 42 |
30+
| clang.cpp:25:56:25:57 | (unsigned long)... | | 42 |
31+
| clang.cpp:25:61:25:61 | 1 | | 1 |
32+
| clang.cpp:26:33:26:62 | __array_extent | int[42][42],2 | 0 |
33+
| clang.cpp:26:33:26:62 | int[42][42] | | <none> |
34+
| clang.cpp:26:52:26:53 | 42 | | 42 |
35+
| clang.cpp:26:52:26:53 | (unsigned long)... | | 42 |
36+
| clang.cpp:26:56:26:57 | 42 | | 42 |
37+
| clang.cpp:26:56:26:57 | (unsigned long)... | | 42 |
38+
| clang.cpp:26:61:26:61 | 2 | | 2 |
39+
| clang.cpp:27:33:27:54 | __array_extent | int,0 | 0 |
40+
| clang.cpp:27:33:27:54 | int | | <none> |
41+
| clang.cpp:27:53:27:53 | 0 | | 0 |
42+
| clang.cpp:29:27:29:44 | S | | <none> |
43+
| clang.cpp:29:27:29:44 | __is_arithmetic | S | 0 |
44+
| clang.cpp:30:27:30:46 | __is_arithmetic | int | 1 |
45+
| clang.cpp:30:27:30:46 | int | | <none> |
46+
| clang.cpp:32:30:32:50 | S | | <none> |
47+
| clang.cpp:32:30:32:50 | __is_complete_type | S | 1 |
48+
| clang.cpp:33:30:33:50 | T | | <none> |
49+
| clang.cpp:33:30:33:50 | __is_complete_type | T | 0 |
50+
| clang.cpp:35:25:35:40 | S | | <none> |
51+
| clang.cpp:35:25:35:40 | __is_compound | S | 1 |
52+
| clang.cpp:36:25:36:42 | __is_compound | int | 0 |
53+
| clang.cpp:36:25:36:42 | int | | <none> |
54+
| clang.cpp:38:22:38:42 | __is_const | const int | 1 |
55+
| clang.cpp:38:22:38:42 | const int | | <none> |
56+
| clang.cpp:39:22:39:36 | __is_const | int | 0 |
57+
| clang.cpp:39:22:39:36 | int | | <none> |
58+
| clang.cpp:41:31:41:54 | __is_floating_point | int | 0 |
59+
| clang.cpp:41:31:41:54 | int | | <none> |
60+
| clang.cpp:42:31:42:56 | __is_floating_point | float | 1 |
61+
| clang.cpp:42:31:42:56 | float | | <none> |
62+
| clang.cpp:44:28:44:46 | S | | <none> |
63+
| clang.cpp:44:28:44:46 | __is_fundamental | S | 0 |
64+
| clang.cpp:45:28:45:48 | __is_fundamental | int | 1 |
65+
| clang.cpp:45:28:45:48 | int | | <none> |
66+
| clang.cpp:47:25:47:44 | __is_integral | float | 0 |
67+
| clang.cpp:47:25:47:44 | float | | <none> |
68+
| clang.cpp:48:25:48:42 | __is_integral | int | 1 |
69+
| clang.cpp:48:25:48:42 | int | | <none> |
70+
| clang.cpp:50:33:50:59 | __is_lvalue_reference | int & | 1 |
71+
| clang.cpp:50:33:50:59 | int & | | <none> |
72+
| clang.cpp:51:33:51:58 | __is_lvalue_reference | int | 0 |
73+
| clang.cpp:51:33:51:58 | int | | <none> |
74+
| clang.cpp:53:40:53:75 | __is_member_function_pointer | f_type | 1 |
75+
| clang.cpp:53:40:53:75 | f_type | | <none> |
76+
| clang.cpp:54:40:54:75 | __is_member_function_pointer | o_type | 0 |
77+
| clang.cpp:54:40:54:75 | o_type | | <none> |
78+
| clang.cpp:56:38:56:71 | __is_member_object_pointer | f_type | 0 |
79+
| clang.cpp:56:38:56:71 | f_type | | <none> |
80+
| clang.cpp:57:38:57:71 | __is_member_object_pointer | o_type | 1 |
81+
| clang.cpp:57:38:57:71 | o_type | | <none> |
82+
| clang.cpp:59:31:59:57 | __is_member_pointer | f_type | 1 |
83+
| clang.cpp:59:31:59:57 | f_type | | <none> |
84+
| clang.cpp:60:31:60:57 | __is_member_pointer | o_type | 1 |
85+
| clang.cpp:60:31:60:57 | o_type | | <none> |
86+
| clang.cpp:61:31:61:54 | __is_member_pointer | int | 0 |
87+
| clang.cpp:61:31:61:54 | int | | <none> |
88+
| clang.cpp:63:23:63:38 | __is_object | int | 1 |
89+
| clang.cpp:63:23:63:38 | int | | <none> |
90+
| clang.cpp:64:23:64:39 | __is_object | int & | 0 |
91+
| clang.cpp:64:23:64:39 | int & | | <none> |
92+
| clang.cpp:66:24:66:40 | __is_pointer | int | 0 |
93+
| clang.cpp:66:24:66:40 | int | | <none> |
94+
| clang.cpp:67:24:67:41 | __is_pointer | int * | 1 |
95+
| clang.cpp:67:24:67:41 | int * | | <none> |
96+
| clang.cpp:69:26:69:44 | __is_reference | int | 0 |
97+
| clang.cpp:69:26:69:44 | int | | <none> |
98+
| clang.cpp:70:26:70:45 | __is_reference | int & | 1 |
99+
| clang.cpp:70:26:70:45 | int & | | <none> |
100+
| clang.cpp:72:33:72:60 | __is_rvalue_reference | int && | 1 |
101+
| clang.cpp:72:33:72:60 | int && | | <none> |
102+
| clang.cpp:73:33:73:58 | __is_rvalue_reference | int | 0 |
103+
| clang.cpp:73:33:73:58 | int | | <none> |
104+
| clang.cpp:75:23:75:38 | __is_scalar | int | 1 |
105+
| clang.cpp:75:23:75:38 | int | | <none> |
106+
| clang.cpp:76:23:76:40 | __is_scalar | int[] | 0 |
107+
| clang.cpp:76:23:76:40 | int[] | | <none> |
108+
| clang.cpp:78:23:78:38 | __is_signed | int | 1 |
109+
| clang.cpp:78:23:78:38 | int | | <none> |
110+
| clang.cpp:79:23:79:47 | __is_signed | unsigned int | 0 |
111+
| clang.cpp:79:23:79:47 | unsigned int | | <none> |
112+
| clang.cpp:81:25:81:42 | __is_unsigned | int | 0 |
113+
| clang.cpp:81:25:81:42 | int | | <none> |
114+
| clang.cpp:82:25:82:51 | __is_unsigned | unsigned int | 1 |
115+
| clang.cpp:82:25:82:51 | unsigned int | | <none> |
116+
| clang.cpp:84:21:84:35 | __is_void | void | 1 |
117+
| clang.cpp:84:21:84:35 | void | | <none> |
118+
| clang.cpp:85:21:85:34 | __is_void | int | 0 |
119+
| clang.cpp:85:21:85:34 | int | | <none> |
120+
| clang.cpp:87:25:87:51 | __is_volatile | volatile int | 1 |
121+
| clang.cpp:87:25:87:51 | volatile int | | <none> |
122+
| clang.cpp:88:25:88:42 | __is_volatile | int | 0 |
123+
| clang.cpp:88:25:88:42 | int | | <none> |
1124
| file://:0:0:0:0 | 0 | | 0 |
2125
| file://:0:0:0:0 | 1 | | 1 |
3126
| file://:0:0:0:0 | 2 | | 2 |
@@ -313,3 +436,15 @@
313436
| ms.cpp:265:49:265:88 | int | | <none> |
314437
| ms.cpp:266:49:266:90 | __has_unique_object_representations | float | 0 |
315438
| ms.cpp:266:49:266:90 | float | | <none> |
439+
| ms.cpp:268:36:268:68 | __is_layout_compatible | int,long | 0 |
440+
| ms.cpp:268:36:268:68 | int | | <none> |
441+
| ms.cpp:268:36:268:68 | long | | <none> |
442+
| ms.cpp:269:36:269:75 | __is_layout_compatible | int *,int *const | 1 |
443+
| ms.cpp:269:36:269:75 | int * | | <none> |
444+
| ms.cpp:269:36:269:75 | int *const | | <none> |
445+
| ms.cpp:271:51:271:101 | __is_pointer_interconvertible_base_of | empty,empty | 1 |
446+
| ms.cpp:271:51:271:101 | empty | | <none> |
447+
| ms.cpp:271:51:271:101 | empty | | <none> |
448+
| ms.cpp:272:51:272:104 | __is_pointer_interconvertible_base_of | empty,abstract | 0 |
449+
| ms.cpp:272:51:272:104 | abstract | | <none> |
450+
| ms.cpp:272:51:272:104 | empty | | <none> |

cpp/ql/test/library-tests/builtins/type_traits/ms.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
// semmle-extractor-options: --microsoft --microsoft_version 1600
22
class empty {
33
};
44

@@ -264,4 +264,10 @@ void f(void) {
264264

265265
bool b_has_unique_object_representations1 = __has_unique_object_representations(int);
266266
bool b_has_unique_object_representations2 = __has_unique_object_representations(float);
267+
268+
bool b_is_layout_compatible1 = __is_layout_compatible(int, long);
269+
bool b_is_layout_compatible2 = __is_layout_compatible(int*, int* const);
270+
271+
bool b_is_pointer_interconvertible_base_of1 = __is_pointer_interconvertible_base_of(empty, empty);
272+
bool b_is_pointer_interconvertible_base_of2 = __is_pointer_interconvertible_base_of(empty, abstract);
267273
}

cpp/ql/test/library-tests/builtins/type_traits/options

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)