Skip to content

Commit

Permalink
Add more unit tests for math expression casting fix ups
Browse files Browse the repository at this point in the history
(taken from #3)
  • Loading branch information
dkl committed Jan 6, 2021
1 parent 4cc0291 commit d594c50
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/highlevel/math-casts.bi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

extern "C"

type E as long
enum
ENUMCONST1 = 0
Expand Down Expand Up @@ -43,3 +45,12 @@ const B20 = culng(0u - 100u)
#define B31 culng(B30 - 1)
#define B32 culng(B31 - 1)
const B30 = culng(0u - 100u)
type UINT as ulong
const C00_MAX_UINT32 = cuint(culng(not 0u))
const C01_MAX_UINT32 = cuint(culng(not culng(0)))
const C02_MAX_UINT32 = cuint(not cast(UINT, 0))
const C03_MAX_UINTPTR = cuint(not 0)
dim shared C04(0 to cuint(not cast(UINT, 0)) - 1) as uinteger = {cuint(not cast(UINT, 0))}
declare sub C05(byval param as uinteger = cuint(not cast(UINT, 0)))

end extern
8 changes: 8 additions & 0 deletions tests/highlevel/math-casts.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ enum E {
#define B31 (B30 - 1)
#define B32 (B31 - 1) // isn't a fwdref itself, but refers to one
#define B30 (0u - 100u)

typedef unsigned int UINT;
#define C00_MAX_UINT32 ((size_t)~0u)
#define C01_MAX_UINT32 ((size_t)~(unsigned int)0)
#define C02_MAX_UINT32 ((size_t)~(UINT)0)
#define C03_MAX_UINTPTR ((size_t)~0) // ~0 gives a 32bit -1, which (on a 64bit system) will be sign-extended to 64bit size_t before being converted to unsigned
static size_t C04[(size_t)~(UINT)0] = {(size_t)~(UINT)0};
void C05(size_t param = (size_t)~((UINT)0));
2 changes: 1 addition & 1 deletion tests/highlevel/math-casts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
[22/23] cygwin-x86_64
[23/23] dos
tests/highlevel/math-casts.h
emitting: tests/highlevel/math-casts.bi (34 declarations, 0 TODOs)
emitting: tests/highlevel/math-casts.bi (41 declarations, 0 TODOs)

0 comments on commit d594c50

Please sign in to comment.