Bug Summary

File:src/lib/libm/src/s_remquof.c
Warning:line 96, column 37
The result of the left shift is undefined because the left operand is negative

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name s_remquof.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/lib/libm/obj -resource-dir /usr/local/llvm16/lib/clang/16 -include namespace.h -I /usr/src/lib/libm/arch/amd64 -I /usr/src/lib/libm/src -I /usr/src/lib/libm/src/ld80 -I /usr/src/lib/libm/hidden -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libm/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fno-jump-tables -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/scan/2024-01-11-140451-98009-1 -x c /usr/src/lib/libm/src/s_remquof.c
1/* @(#)e_fmod.c 1.3 95/01/18 */
2/*-
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 *
6 * Developed at SunSoft, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
9 * is preserved.
10 * ====================================================
11 */
12
13#include "math.h"
14#include "math_private.h"
15
16static const float Zero[] = {0.0, -0.0,};
17
18/*
19 * Return the IEEE remainder and set *quo to the last n bits of the
20 * quotient, rounded to the nearest integer. We choose n=31 because
21 * we wind up computing all the integer bits of the quotient anyway as
22 * a side-effect of computing the remainder by the shift and subtract
23 * method. In practice, this is far more bits than are needed to use
24 * remquo in reduction algorithms.
25 */
26float
27remquof(float x, float y, int *quo)
28{
29 int32_t n,hx,hy,hz,ix,iy,sx,i;
30 u_int32_t q,sxy;
31
32 GET_FLOAT_WORD(hx,x)do { ieee_float_shape_type gf_u; gf_u.value = (x); (hx) = gf_u
.word; } while (0)
;
1
Loop condition is false. Exiting loop
33 GET_FLOAT_WORD(hy,y)do { ieee_float_shape_type gf_u; gf_u.value = (y); (hy) = gf_u
.word; } while (0)
;
2
Loop condition is false. Exiting loop
34 sxy = (hx ^ hy) & 0x80000000;
35 sx = hx&0x80000000; /* sign of x */
36 hx ^=sx; /* |x| */
37 hy &= 0x7fffffff; /* |y| */
38
39 /* purge off exception values */
40 if(hy==0||hx>=0x7f800000||hy>0x7f800000) /* y=0,NaN;or x not finite */
3
Assuming 'hy' is not equal to 0
4
Assuming 'hx' is < 2139095040
5
Assuming 'hy' is <= 2139095040
6
Taking false branch
41 return (x*y)/(x*y);
42 if(hx<hy) {
7
Assuming 'hx' is >= 'hy'
8
Taking false branch
43 q = 0;
44 goto fixup; /* |x|<|y| return x or x-y */
45 } else if(hx==hy) {
9
Assuming 'hx' is not equal to 'hy'
10
Taking false branch
46 *quo = 1;
47 return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
48 }
49
50 /* determine ix = ilogb(x) */
51 if(hx<0x00800000) { /* subnormal x */
11
Assuming 'hx' is >= 8388608
12
Taking false branch
52 for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
53 } else ix = (hx>>23)-127;
54
55 /* determine iy = ilogb(y) */
56 if(hy<0x00800000) { /* subnormal y */
13
Assuming 'hy' is >= 8388608
14
Taking false branch
57 for (iy = -126,i=(hy<<8); i>0; i<<=1) iy -=1;
58 } else iy = (hy>>23)-127;
59
60 /* set up {hx,lx}, {hy,ly} and align y to x */
61 if(ix >= -126)
15
Assuming the condition is false
16
Taking false branch
62 hx = 0x00800000|(0x007fffff&hx);
63 else { /* subnormal x, shift x to normal */
64 n = -126-ix;
65 hx <<= n;
66 }
67 if(iy >= -126)
17
Assuming the condition is false
18
Taking false branch
68 hy = 0x00800000|(0x007fffff&hy);
69 else { /* subnormal y, shift y to normal */
70 n = -126-iy;
71 hy <<= n;
72 }
73
74 /* fix point fmod */
75 n = ix - iy;
76 q = 0;
77 while(n--) {
19
Loop condition is false. Execution continues on line 83
78 hz=hx-hy;
79 if(hz<0) hx = hx << 1;
80 else {hx = hz << 1; q++;}
81 q <<= 1;
82 }
83 hz=hx-hy;
84 if(hz>=0) {hx=hz;q++;}
20
Assuming 'hz' is < 0
21
Taking false branch
85
86 /* convert back to floating value and restore the sign */
87 if(hx==0) { /* return sign(x)*0 */
22
Assuming 'hx' is not equal to 0
23
Taking false branch
88 *quo = (sxy ? -q : q);
89 return Zero[(u_int32_t)sx>>31];
90 }
91 while(hx<0x00800000) { /* normalize x */
24
Assuming 'hx' is < 8388608
25
Loop condition is true. Entering loop body
26
Assuming 'hx' is >= 8388608
27
Loop condition is false. Execution continues on line 95
92 hx <<= 1;
93 iy -= 1;
94 }
95 if(iy>= -126) { /* normalize output */
28
Assuming the condition is true
29
Taking true branch
96 hx = ((hx-0x00800000)|((iy+127)<<23));
30
The result of the left shift is undefined because the left operand is negative
97 } else { /* subnormal output */
98 n = -126 - iy;
99 hx >>= n;
100 }
101fixup:
102 SET_FLOAT_WORD(x,hx)do { ieee_float_shape_type sf_u; sf_u.word = (hx); (x) = sf_u
.value; } while (0)
;
103 y = fabsf(y);
104 if (y < 0x1p-125f) {
105 if (x+x>y || (x+x==y && (q & 1))) {
106 q++;
107 x-=y;
108 }
109 } else if (x>0.5f*y || (x==0.5f*y && (q & 1))) {
110 q++;
111 x-=y;
112 }
113 GET_FLOAT_WORD(hx,x)do { ieee_float_shape_type gf_u; gf_u.value = (x); (hx) = gf_u
.word; } while (0)
;
114 SET_FLOAT_WORD(x,hx^sx)do { ieee_float_shape_type sf_u; sf_u.word = (hx^sx); (x) = sf_u
.value; } while (0)
;
115 q &= 0x7fffffff;
116 *quo = (sxy ? -q : q);
117 return x;
118}