1 /* { dg-require-effective-target alloca } */
2 /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
6 /* Tests warn on use of floating-point operands inside the calculation
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. */
14 int *ptr
= (int *)malloc (sizeof (int) * f
); /* { dg-line test_1 } */
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 } */
24 int *ptr
= (int *)malloc (n
* 3.1); /* { dg-line test_2 } */
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 } */
43 void *ptr
= alloc_me (f
); /* { dg-message "calling 'alloc_me' from 'test_3'" } */
49 int *ptr
= (int *)calloc(1.7 * n
, sizeof (int)); /* { dg-line test_4 } */
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 } */
59 int *ptr
= (int *)__builtin_alloca (sizeof (int) * f
); /* { dg-line test_5 } */
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 } */
70 int *ptr
= (int *)__builtin_alloca (1.7f
* f
* 2.3f
); /* { dg-line test_6 } */
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 } */