[RISC-V] Avoid unnecessary extensions when value is already extended
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / imprecise-floating-point-1.c
blobb093a3c4d2ab98a6ab5ff5219d4485c6657133b4
1 /* { dg-require-effective-target alloca } */
2 /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
4 #include <stdlib.h>
6 /* Tests warn on use of floating-point operands inside the calculation
7 of an allocation size.
9 The test cases here only test for warnings. The test cases inside
10 allocation-size-X.c should be plently enough to test for false positives. */
12 void test_1 (float f)
14 int *ptr = (int *)malloc (sizeof (int) * f); /* { dg-line test_1 } */
15 free (ptr);
17 /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_1 } */
18 /* { dg-message "operand 'f' is of type 'float'" "note" { target *-*-* } test_1 } */
19 /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_1 } */
22 void test_2 (int n)
24 int *ptr = (int *)malloc (n * 3.1); /* { dg-line test_2 } */
25 free (ptr);
27 /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_2 } */
28 /* { dg-message "operand '\(\\d|e|f|l|\\.|\\+|\)+' is of type '\(long \)?double'" "note" { target *-*-* } test_2 } */
29 /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_2 } */
32 void *alloc_me (size_t size)
34 return malloc (size); /* { dg-line test_3 } */
36 /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_3 } */
37 /* { dg-message "operand 'f' is of type 'float'" "note" { target *-*-* } test_3 } */
38 /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_3 } */
41 void test_3 (float f)
43 void *ptr = alloc_me (f); /* { dg-message "calling 'alloc_me' from 'test_3'" } */
44 free (ptr);
47 void test_4 (int n)
49 int *ptr = (int *)calloc(1.7 * n, sizeof (int)); /* { dg-line test_4 } */
50 free (ptr);
52 /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_4 } */
53 /* { dg-message "operand '\(\\d|e|f|l|\\.|\\+|\)+' is of type '\(long \)?double'" "note" { target *-*-* } test_4 } */
54 /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_4 } */
57 int test_5 (float f)
59 int *ptr = (int *)__builtin_alloca (sizeof (int) * f); /* { dg-line test_5 } */
60 *ptr = 4;
61 return *ptr;
63 /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_5 } */
64 /* { dg-message "operand 'f' is of type 'float'" "note" { target *-*-* } test_5 } */
65 /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_5 } */
68 int test_6 (float f)
70 int *ptr = (int *)__builtin_alloca (1.7f * f * 2.3f); /* { dg-line test_6 } */
71 *ptr = 4;
72 return *ptr;
74 /* { dg-warning "use of floating-point arithmetic here might yield unexpected results" "warning" { target *-*-* } test_6 } */
75 /* { dg-message "operand 'f' is of type 'float'" "note" { target *-*-* } test_6 } */
76 /* { dg-message "only use operands of an integer type inside the size argument" "note" { target *-*-* } test_6 } */