Skip to content

Commit 442f67c

Browse files
LuhaocongLu Haocong
authored andcommitted
[Sema][test] Split format attribute test cases for _Float16
Fixes #74439 (comment)
1 parent d02c793 commit 442f67c

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

clang/test/Sema/attr-format-Float16.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc -target-feature +sse2 %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
4+
// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
5+
// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
6+
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv32 %s
7+
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv64 %s
8+
9+
void a(const char *a, ...) __attribute__((format(printf, 1, 2))); // no-error
10+
11+
void b(char *a, _Float16 b) __attribute__((format(printf, 1, 2))); // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}
12+
13+
void call_no_default_promotion(void) {
14+
a("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
15+
b("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
16+
}

clang/test/Sema/attr-format.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ typedef const char *xpto;
1616
void j(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error
1717
void k(xpto c) __attribute__((format(printf, 1, 0))); // no-error
1818

19-
void l(char *a, _Float16 b) __attribute__((format(printf, 1, 2))); // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}
20-
2119
void y(char *str) __attribute__((format(strftime, 1, 0))); // no-error
2220
void z(char *str, int c, ...) __attribute__((format(strftime, 1, 2))); // expected-error {{strftime format attribute requires 3rd parameter to be 0}}
2321

@@ -95,11 +93,6 @@ void call_nonvariadic(void) {
9593
d3("%s", 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
9694
}
9795

98-
void call_no_default_promotion(void) {
99-
a("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
100-
l("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
101-
}
102-
10396
__attribute__((format(printf, 1, 2)))
10497
void forward_fixed(const char *fmt, _Bool b, char i, short j, int k, float l, double m) { // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}
10598
forward_fixed(fmt, b, i, j, k, l, m);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc -target-feature +sse2 %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
4+
// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
5+
// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
6+
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv32 %s
7+
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv64 %s
8+
9+
template <typename... Args>
10+
__attribute__((format(printf, 1, 2)))
11+
void format(const char *fmt, Args &&...args); // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}
12+
13+
template<typename... Args>
14+
__attribute__((format(scanf, 1, 2)))
15+
int scan(const char *fmt, Args &&...args); // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}
16+
17+
void do_format() {
18+
format("%f", (_Float16)123.f); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
19+
20+
_Float16 Float16;
21+
scan("%f", &Float16); // expected-warning{{format specifies type 'float *' but the argument has type '_Float16 *'}}
22+
scan("%lf", &Float16); // expected-warning{{format specifies type 'double *' but the argument has type '_Float16 *'}}
23+
scan("%Lf", &Float16); // expected-warning{{format specifies type 'long double *' but the argument has type '_Float16 *'}}
24+
}

clang/test/SemaCXX/attr-format.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ void do_format() {
8181

8282
format("%c %c %hhd %hd %d\n", (char)'a', 'a', 'a', (short)123, (int)123);
8383
format("%f %f %f\n", (__fp16)123.f, 123.f, 123.);
84-
format("%f", (_Float16)123.f);// expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
8584
format("%Lf", (__fp16)123.f); // expected-warning{{format specifies type 'long double' but the argument has type '__fp16'}}
8685
format("%Lf", 123.f); // expected-warning{{format specifies type 'long double' but the argument has type 'float'}}
8786
format("%hhi %hhu %hi %hu %i %u", b, b, b, b, b, b);

clang/test/SemaCXX/format-strings-scanf.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ union bag {
2222
unsigned long long ull;
2323
signed long long sll;
2424
__fp16 f16;
25-
_Float16 Float16;
2625
float ff;
2726
double fd;
2827
long double fl;
@@ -52,21 +51,18 @@ void test(void) {
5251
// expected-warning@+1{{format specifies type 'int *' but the argument has type 'short *'}}
5352
scan("%hhi %i %li", &b.ss, &b.ss, &b.ss);
5453

55-
// expected-warning@+4{{format specifies type 'float *' but the argument has type '__fp16 *'}}
56-
// expected-warning@+3{{format specifies type 'float *' but the argument has type '_Float16 *'}}
54+
// expected-warning@+3{{format specifies type 'float *' but the argument has type '__fp16 *'}}
5755
// expected-warning@+2{{format specifies type 'float *' but the argument has type 'double *'}}
5856
// expected-warning@+1{{format specifies type 'float *' but the argument has type 'long double *'}}
59-
scan("%f %f %f %f", &b.f16, &b.Float16, &b.fd, &b.fl);
57+
scan("%f %f %f", &b.f16, &b.fd, &b.fl);
6058

61-
// expected-warning@+4{{format specifies type 'double *' but the argument has type '__fp16 *'}}
62-
// expected-warning@+3{{format specifies type 'double *' but the argument has type '_Float16 *'}}
59+
// expected-warning@+3{{format specifies type 'double *' but the argument has type '__fp16 *'}}
6360
// expected-warning@+2{{format specifies type 'double *' but the argument has type 'float *'}}
6461
// expected-warning@+1{{format specifies type 'double *' but the argument has type 'long double *'}}
65-
scan("%lf %lf %lf %lf", &b.f16, &b.Float16, &b.ff, &b.fl);
62+
scan("%lf %lf %lf", &b.f16, &b.ff, &b.fl);
6663

67-
// expected-warning@+4{{format specifies type 'long double *' but the argument has type '__fp16 *'}}
68-
// expected-warning@+3{{format specifies type 'long double *' but the argument has type '_Float16 *'}}
64+
// expected-warning@+3{{format specifies type 'long double *' but the argument has type '__fp16 *'}}
6965
// expected-warning@+2{{format specifies type 'long double *' but the argument has type 'float *'}}
7066
// expected-warning@+1{{format specifies type 'long double *' but the argument has type 'double *'}}
71-
scan("%Lf %Lf %Lf %Lf", &b.f16, &b.Float16, &b.ff, &b.fd);
67+
scan("%Lf %Lf %Lf", &b.f16, &b.ff, &b.fd);
7268
}

0 commit comments

Comments
 (0)