Skip to content

Commit

Permalink
[Sema][test] Split format attribute test cases for _Float16
Browse files Browse the repository at this point in the history
  • Loading branch information
Luhaocong committed Jan 8, 2024
1 parent d02c793 commit 442f67c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
16 changes: 16 additions & 0 deletions clang/test/Sema/attr-format-Float16.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc -target-feature +sse2 %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv32 %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv64 %s

void a(const char *a, ...) __attribute__((format(printf, 1, 2))); // no-error

void b(char *a, _Float16 b) __attribute__((format(printf, 1, 2))); // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}

void call_no_default_promotion(void) {
a("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
b("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
}
7 changes: 0 additions & 7 deletions clang/test/Sema/attr-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ typedef const char *xpto;
void j(xpto c, va_list list) __attribute__((format(printf, 1, 0))); // no-error
void k(xpto c) __attribute__((format(printf, 1, 0))); // no-error

void l(char *a, _Float16 b) __attribute__((format(printf, 1, 2))); // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}

void y(char *str) __attribute__((format(strftime, 1, 0))); // no-error
void z(char *str, int c, ...) __attribute__((format(strftime, 1, 2))); // expected-error {{strftime format attribute requires 3rd parameter to be 0}}

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

void call_no_default_promotion(void) {
a("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
l("%f", (_Float16)1.0); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
}

__attribute__((format(printf, 1, 2)))
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}}
forward_fixed(fmt, b, i, j, k, l, m);
Expand Down
24 changes: 24 additions & 0 deletions clang/test/SemaCXX/attr-format-Float16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-pc -target-feature +sse2 %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv32 %s
// RUN: %clang_cc1 -fsyntax-only -verify -triple riscv64 %s

template <typename... Args>
__attribute__((format(printf, 1, 2)))
void format(const char *fmt, Args &&...args); // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}

template<typename... Args>
__attribute__((format(scanf, 1, 2)))
int scan(const char *fmt, Args &&...args); // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}}

void do_format() {
format("%f", (_Float16)123.f); // expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}

_Float16 Float16;
scan("%f", &Float16); // expected-warning{{format specifies type 'float *' but the argument has type '_Float16 *'}}
scan("%lf", &Float16); // expected-warning{{format specifies type 'double *' but the argument has type '_Float16 *'}}
scan("%Lf", &Float16); // expected-warning{{format specifies type 'long double *' but the argument has type '_Float16 *'}}
}
1 change: 0 additions & 1 deletion clang/test/SemaCXX/attr-format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ void do_format() {

format("%c %c %hhd %hd %d\n", (char)'a', 'a', 'a', (short)123, (int)123);
format("%f %f %f\n", (__fp16)123.f, 123.f, 123.);
format("%f", (_Float16)123.f);// expected-warning{{format specifies type 'double' but the argument has type '_Float16'}}
format("%Lf", (__fp16)123.f); // expected-warning{{format specifies type 'long double' but the argument has type '__fp16'}}
format("%Lf", 123.f); // expected-warning{{format specifies type 'long double' but the argument has type 'float'}}
format("%hhi %hhu %hi %hu %i %u", b, b, b, b, b, b);
Expand Down
16 changes: 6 additions & 10 deletions clang/test/SemaCXX/format-strings-scanf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ union bag {
unsigned long long ull;
signed long long sll;
__fp16 f16;
_Float16 Float16;
float ff;
double fd;
long double fl;
Expand Down Expand Up @@ -52,21 +51,18 @@ void test(void) {
// expected-warning@+1{{format specifies type 'int *' but the argument has type 'short *'}}
scan("%hhi %i %li", &b.ss, &b.ss, &b.ss);

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

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

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

0 comments on commit 442f67c

Please sign in to comment.