diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-05-31 00:29:40 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-06-01 03:27:20 +0200 |
| commit | da29278349ab3fdda107b10264941c7370b92c1c (patch) | |
| tree | 4e572f2912fbc1e9701e7f5d5d57455cca1d9ab3 /validation/expand | |
| parent | ed5dcc156b3651d089059c4f93c70229490c086c (diff) | |
| download | sparse-dev-da29278349ab3fdda107b10264941c7370b92c1c.tar.gz | |
fix typing of __builtin_expect()
Typewisely, sparse process __builtin_expect() as:
1) returning 'int'
2) taking any type in first & second arg
3) returning exactly its first argument, silently, even
if this conflicts with 1).
but this doesn't match with how gcc declare it:
long __builtin_expect(long, long);
Fix this by giving the proper prototype to this builtin
and removing the bogus 'returns an int'.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/expand')
| -rw-r--r-- | validation/expand/builtin-expect.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/validation/expand/builtin-expect.c b/validation/expand/builtin-expect.c new file mode 100644 index 00000000..a80176a5 --- /dev/null +++ b/validation/expand/builtin-expect.c @@ -0,0 +1,101 @@ +int flia(long a) +{ + return __builtin_expect(a, 1); +} + +int flic(void) +{ + return __builtin_expect(1L << 32 | 1, 1); +} + +long fila(int a) +{ + return __builtin_expect(a, 1); +} + +long filc(void) +{ + return __builtin_expect(1L << 32 | 1, 1); +} + +long filu(void) +{ + return __builtin_expect(0x80000000U, 1); +} + +long fils(void) +{ + return __builtin_expect((int)0x80000000, 1); +} + +void *fptr(void *a) +{ + return __builtin_expect(a, a); +} + +/* + * check-name: builtin-expect + * check-command: test-linearize -m64 -Wno-decl $file + * + * check-output-start +flia: +.L0: + <entry-point> + scast.32 %r2 <- (64) %arg1 + ret.32 %r2 + + +flic: +.L2: + <entry-point> + ret.32 $1 + + +fila: +.L4: + <entry-point> + scast.64 %r6 <- (32) %arg1 + ret.64 %r6 + + +filc: +.L6: + <entry-point> + ret.64 $0x100000001 + + +filu: +.L8: + <entry-point> + ret.64 $0x80000000 + + +fils: +.L10: + <entry-point> + ret.64 $0xffffffff80000000 + + +fptr: +.L12: + <entry-point> + cast.64 %r12 <- (64) %arg1 + scast.64 %r13 <- (64) %r12 + ret.64 %r13 + + + * check-output-end + * + * check-error-start +expand/builtin-expect.c:33:33: warning: incorrect type in argument 1 (different base types) +expand/builtin-expect.c:33:33: expected long [signed] <noident> +expand/builtin-expect.c:33:33: got void *a +expand/builtin-expect.c:33:36: warning: incorrect type in argument 2 (different base types) +expand/builtin-expect.c:33:36: expected long [signed] <noident> +expand/builtin-expect.c:33:36: got void *a +expand/builtin-expect.c:33:32: warning: incorrect type in return expression (different base types) +expand/builtin-expect.c:33:32: expected void * +expand/builtin-expect.c:33:32: got long +expand/builtin-expect.c:8:42: warning: cast truncates bits from constant value (100000001 becomes 1) + * check-error-end + */ |
