Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/aniso.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ int main(int argc, char *argv[])

glBegin( GL_TRIANGLE_STRIP );
void (*f)(int, int) = glVertex2i;
if ((int)f % 16 == 4) f(5, 7);
if ((long)f % 16 == 4) f(5, 7);
void (*g)(int, int) = glVertex3f;
if ((int)g % 16 == 4) g(5, 7);
return (int)f + (int)g;
if ((long)g % 16 == 4) g(5, 7);
return (int)((long)f + (long)g);
}

6 changes: 3 additions & 3 deletions tests/browser/async_virtual_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DOS_Device {
DOS_Device *Devices[10];

bool __attribute__((noinline)) DOS_Device::Read(unsigned char * data,unsigned short * size) {
printf("DOS_Device::Read (this = %i)\n", (int)this);
printf("DOS_Device::Read (this = %ld)\n", (long)this);

@sbc100 sbc100 Jul 11, 2021

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be %p with no cast, no? Same wherever we want to printf a pointer.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that be better.. I was just trying to fix the existing style which seems to like to cast to int.
411 results for %ld (most of which "pointers", only 115 of which from PR) - might want to leave this improvement for another PR though.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe lets land that first? That would make this PR a lot smaller. I can have a go at it if you like?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that produce a ton of conflicts with this PR?
I don't think we should mix trying to make things 64-bit compatible with general large scale cleanup of tests. I am sure if you go look at the tests you can find a lot of things to clean up.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its good to do such cleanups when it becomes apparent that they are useful/needed. In this case doing the cleanup ahead of time will significantly reduce the size of, and churn generated by, this PR.

Yes it will conflict with this PR but it should be trivial to just run git checkout --thiers to accept the upstream changes since we know we want to basically revert all the conflicting parts of this PR, right?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i.e. there should be no manual conflict resolution needed I think)

return Devices[devnum]->Read(data,size);
}

Expand All @@ -26,7 +26,7 @@ class device_CON : public DOS_Device {
};

bool device_CON::Read(unsigned char * data,unsigned short * size) {
printf("device_CON::Read (this = %i) Sleep--> \n", (int)this);
printf("device_CON::Read (this = %ld) Sleep--> \n", (long)this);
EM_ASM({
Module.the_this = $0;
out('first this ' + Module.the_this);
Expand All @@ -36,7 +36,7 @@ bool device_CON::Read(unsigned char * data,unsigned short * size) {
out('second this ' + $0);
assert(Module.the_this === $0, 'this must be unchanged');
}, this);
printf("<--Sleep (this = %i)\n", (int)this);
printf("<--Sleep (this = %ld)\n", (long)this);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/browser_gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void *global;
int freed = 0;

void finalizer(void *ptr, void *arg) {
printf("finalizing %d (global == %d)\n", (int)arg, ptr == global);
printf("finalizing %ld (global == %d)\n", (long)arg, ptr == global);
freed++;
if (ptr == global) global = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/core/pthread/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void *ThreadMain(void *arg) {

pthread_t thread[NUM_THREADS];

void CreateThread(int i)
void CreateThread(long i)
{
int rc = pthread_create(&thread[i], nullptr, ThreadMain, (void*)i);
assert(rc == 0);
Expand All @@ -48,7 +48,7 @@ void mainn() {

int main() {
// Create initial threads.
for(int i = 0; i < NUM_THREADS; ++i) {
for(long i = 0; i < NUM_THREADS; ++i) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can leave this as int, no?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just trying to make the code work with as few casts as possible. Since the thread id is stored as a long/pointer, it seemed nicer to make this loop use long instead of int.

CreateThread(i);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/core/stack_overflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
#include <stdint.h>
#include <emscripten.h>

void recurse(unsigned int x);
void recurse(unsigned long x);

void act(volatile unsigned int *a) {
printf("act %d\n", *a);
unsigned int b = (int)(intptr_t)(alloca(*a));
void act(volatile unsigned long *a) {
printf("act %ld\n", *a);
unsigned long b = (long)(intptr_t)(alloca(*a));
if (b < *a) *a--;
recurse(*a);
}

void recurse(volatile unsigned int x) {
printf("recurse %d\n", x);
volatile unsigned int a = x;
void recurse(volatile unsigned long x) {
printf("recurse %ld\n", x);
volatile unsigned long a = x;
volatile char buffer[1000*1000];
buffer[x/2] = 0;
buffer[(x-1)/2] = 0;
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_alloca.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ int main(int argc, char **argv) {
char *pc, *pc2;
assert(argc == 1);
pc = (char *)alloca(4+argc);
assert(((int)pc) % 4 == 0);
assert(((long)pc) % 4 == 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case needed? Can't it just be removed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just trying to fix the existing test for 64-bit. It probably shouldn't be removed since this also still runs for 32-bit.

pc2 = (char *)alloca(4+argc);
assert(((int)pc2) % 4 == 0);
printf("z:%d*%d*%d*\n", (int)pc > 0, (int)pc, (int)pc2);
assert(((long)pc2) % 4 == 0);
printf("z:%d*%p*%p*\n", (long)pc > 0, pc, pc2);
return 0;
}
3 changes: 2 additions & 1 deletion tests/core/test_asan_memchr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string.h>
#include <stdint.h>

int main() {
return (int)memchr("hello", 'z', 7);
return (int)(intptr_t)memchr("hello", 'z', 7);
}
2 changes: 1 addition & 1 deletion tests/core/test_atexit_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj, void *dso_s

static void cleanA() { printf("A\n"); }
static void cleanB() { printf("B\n"); }
static void cleanCarg(void* x) { printf("C %d\n", (int)x); }
static void cleanCarg(void* x) { printf("C %ld\n", (long)x); }

int main() {
atexit(cleanA);
Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const char *get_string() { return "hello world"; }
void print_int(int x) { printf("%d\n", x); }
void print_float(float x) { printf("%.2f\n", x); }
void print_string(char *x) { printf("%s\n", x); }
void print_bool(bool x) {
if (x) printf("true\n");
void print_bool(bool x) {
if (x) printf("true\n");
else if (!x) printf("false\n");
}
int multi(int x, float y, int z, char *str) {
Expand All @@ -36,11 +36,11 @@ int *pointer(int *in) {
struct test_struct {
int arg1, arg2, arg3;
};
static int* stackChecker = 0;
static intptr_t* stackChecker = 0;
__attribute__((noinline))
int get_stack() { int i; return (int)&i; }
intptr_t get_stack() { int i; return (intptr_t)&i; }
int uses_stack(test_struct* t1) {
if (stackChecker == 0) stackChecker = (int*)malloc(sizeof(int));
if (stackChecker == 0) stackChecker = (intptr_t*)malloc(sizeof(intptr_t));
*stackChecker = get_stack();
EM_ASM(Module['ccall']('get_int', 'number'));
printf("stack is %s.\n", *stackChecker == get_stack() ? "ok" : "messed up");
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_emmalloc_memory_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main()
void *ptr3 = malloc(64*1024*1024);
void *ptr4 = malloc(16*1024);
void *ptr5 = malloc(2*1024*1024);
printf("%d\n", (int)(ptr && ptr2 && ptr3 && ptr4 && ptr5));
printf("%ld\n", (long)(ptr && ptr2 && ptr3 && ptr4 && ptr5));
free(ptr2);
free(ptr4);
printf("%d\n", emmalloc_validate_memory_regions());
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_emscripten_async_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void myatexit() {
void callback(void *arg) {
printf("callback\n");
doneCallback = true;
assert((int)arg == 42);
assert(arg == (void *)42);
// Runtime should exit after this callback returns
}

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_funcptr_namecollide.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ void do_call(void (*puts)(const char *), const char *str);

void do_print(const char *str) {
if (!str) do_call(NULL, "delusion");
if ((int)str == -1) do_print(str + 10);
if ((long)str == -1) do_print(str + 10);
puts("====");
puts(str);
puts("====");
}

void do_call(void (*puts)(const char *), const char *str) {
if (!str) do_print("confusion");
if ((int)str == -1) do_call(NULL, str - 10);
if ((long)str == -1) do_call(NULL, str - 10);
(*puts)(str);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_i64_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int main(int argc, char **argv)
uint64_t a = 5;
double b = 6.8;
uint64_t c = a * b;
if (truthy()) printf("*%d,%d,%d*\n", (int)&a, (int)&b, (int)&c); // printing addresses prevents optimizations
if (truthy()) printf("*%ld,%ld,%ld*\n", (long)&a, (long)&b, (long)&c); // printing addresses prevents optimizations
printf("*prod:%llu*\n", c);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_longjmp_stacked.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdlib.h>
#include <string.h>

int bottom, top;
intptr_t bottom, top;

int run(int y) {
// confuse stack
Expand All @@ -19,7 +19,7 @@ int run(int y) {
s[y] = y;
s[y / 2] = y * 2;
volatile int x = s[y];
top = (int)alloca(4);
top = (intptr_t)alloca(4);
if (x <= 2) return x;
jmp_buf buf;
printf("setjmp of %d\n", x);
Expand All @@ -35,7 +35,7 @@ int run(int y) {
int main(int argc, char **argv) {
int sum = 0;
for (int i = 0; i < argc * 2; i++) {
bottom = (int)alloca(4);
bottom = (intptr_t)alloca(4);
sum += run(10);
// scorch the earth
if (bottom < top) {
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_longjmp_unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ volatile void* temp;
__attribute__((noinline)) void foo()
{
temp = alloca(MAJOR);
printf("major allocation at: %d\n", (int)temp);
assert(abs(emscripten_stack_get_current() - (int)temp) >= MAJOR);
printf("major allocation at: %ld\n", (long)temp);
assert(abs(emscripten_stack_get_current() - (long)temp) >= MAJOR);
bar();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_memorygrowth.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ int main(int argc, char **argv)

int totalMemory = EM_ASM_INT({ return HEAP8.length });
char *buf3 = (char*)malloc(totalMemory+1);
buf3[argc] = (int)buf2;
if (argc % 7 == 6) printf("%d\n", (int)memcpy(buf3, buf1, argc));
buf3[argc] = (long)buf2;
if (argc % 7 == 6) printf("%ld\n", (long)memcpy(buf3, buf1, argc));
char *buf4 = (char*)malloc(100);
float *buf5 = (float*)malloc(100);
//printf("totalMemory: %d bufs: %d,%d,%d,%d,%d\n", totalMemory, buf1, buf2, buf3, buf4, buf5);
assert((int)buf4 > (int)totalMemory && (int)buf5 > (int)totalMemory);
assert((long)buf4 > (long)totalMemory && (long)buf5 > (long)totalMemory);

printf("*%s,%.3f*\n", buf1, buf2[0]); // the old heap data should still be there

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_memorygrowth_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ int main(int argc, char **argv)
char *buf3;
for (int i = 0; i < (totalMemory/chunk)+1; i++) {
buf3 = (char*)malloc(chunk);
buf3[argc] = (int)buf2;
buf3[argc] = (long)buf2;
}
if (argc % 7 == 6) printf("%p\n", memcpy(buf3, buf1, argc));
char *buf4 = (char*)malloc(100);
float *buf5 = (float*)malloc(100);
//printf("totalMemory: %d bufs: %d,%d,%d,%d,%d\n", totalMemory, buf1, buf2, buf3, buf4, buf5);
assert((int)buf4 > (int)totalMemory && (int)buf5 > (int)totalMemory);
assert((long)buf4 > (long)totalMemory && (long)buf5 > (long)totalMemory);

printf("*%s,%.3f*\n", buf1, buf2[0]); // the old heap data should still be there

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_memorygrowth_memory_growth_step.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main() {
for (int i = 0; 1; i++) {

printf("%d %d %d\n", i, get_memory_size(), get_memory_size() / MB);
volatile int sink = (int)malloc(MB);
volatile long sink = (long)malloc(MB);

if (!sink) {
printf("failed at %d %d %d\n", i, get_memory_size(), get_memory_size() / MB);
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_memorygrowth_wasm_mem_max.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main() {
// higher can prove we stop at the right point.
for (int i = 0; 1; i++) {
printf("%d\n", i);
volatile int sink = (int)malloc(MB);
volatile long sink = (long)malloc(MB);
if (!sink) {
printf("failed at %d\n", i);
assert(i > 70);
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main(int argc, char* argv[]) {
int* map = (int*)mmap(0, 5000, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANON, -1, 0);
assert(map != MAP_FAILED);
assert(((int)map) % 65536 == 0); // aligned
assert(((long)map) % 65536 == 0); // aligned
assert(munmap(map, 5000) == 0);
}

Expand Down
24 changes: 12 additions & 12 deletions tests/core/test_set_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,49 @@

#include <stdio.h>
#include <emscripten.h>

volatile char data[16];

__attribute__((noinline)) void *get_aligned(int align)
{
char *ptr = (char*)(((int)(data + 7)) & ~7); // Make 8-byte aligned
char *ptr = (char*)(((long)(data + 7)) & ~7); // Make 8-byte aligned
ptr += align; // Now 'align' aligned
return (void*)ptr;
}

int main()
{
emscripten_align4_double *d4 = (emscripten_align4_double*)get_aligned(4);
*d4 = 17.0;
printf("addr: %d, value: %f\n", ((int)d4) % 8, *d4);
printf("addr: %ld, value: %f\n", ((long)d4) % 8, *d4);

emscripten_align2_double *d2 = (emscripten_align2_double*)get_aligned(2);
*d2 = 18.0;
printf("addr: %d, value: %f\n", ((int)d2) % 8, *d2);
printf("addr: %ld, value: %f\n", ((long)d2) % 8, *d2);

emscripten_align1_double *d1 = (emscripten_align1_double*)get_aligned(1);
*d1 = 19.0;
printf("addr: %d, value: %f\n", ((int)d1) % 8, *d1);
printf("addr: %ld, value: %f\n", ((long)d1) % 8, *d1);

emscripten_align2_float *f2 = (emscripten_align2_float*)get_aligned(2);
*f2 = 20.0;
printf("addr: %d, value: %f\n", ((int)f2) % 4, *f2);
printf("addr: %ld, value: %f\n", ((long)f2) % 4, *f2);

emscripten_align1_float *f1 = (emscripten_align1_float*)get_aligned(1);
*f1 = 21.0;
printf("addr: %d, value: %f\n", ((int)f1) % 4, *f1);
printf("addr: %ld, value: %f\n", ((long)f1) % 4, *f1);

emscripten_align2_int *i2 = (emscripten_align2_int*)get_aligned(2);
*i2 = 22;
printf("addr: %d, value: %d\n", ((int)i2) % 4, *i2);
printf("addr: %ld, value: %d\n", ((long)i2) % 4, *i2);

emscripten_align1_int *i1 = (emscripten_align1_int*)get_aligned(1);
*i1 = 23;
printf("addr: %d, value: %d\n", ((int)i1) % 4, *i1);
printf("addr: %ld, value: %d\n", ((long)i1) % 4, *i1);

emscripten_align1_short *s1 = (emscripten_align1_short*)get_aligned(1);
*s1 = 24;
printf("addr: %d, value: %d\n", ((int)s1) % 4, (int)*s1);
printf("addr: %ld, value: %d\n", ((long)s1) % 4, (int)*s1);

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/core/test_sintvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ int main() {

s->match_start = (char *)32522;
s->strstart = (char *)(32780);
printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start,
(int)(s->strstart - s->match_start));
printf("*%ld,%ld,%ld*\n", (long)s->strstart, (long)s->match_start,
(long)(s->strstart - s->match_start));
sh = s->strstart - s->match_start;
printf("*%d,%d*\n", sh, sh >> 7);

s->match_start = (char *)32999;
s->strstart = (char *)(32780);
printf("*%d,%d,%d*\n", (int)s->strstart, (int)s->match_start,
(int)(s->strstart - s->match_start));
printf("*%ld,%ld,%ld*\n", (long)s->strstart, (long)s->match_start,
(long)(s->strstart - s->match_start));
sh = s->strstart - s->match_start;
printf("*%d,%d*\n", sh, sh >> 7);
}
4 changes: 2 additions & 2 deletions tests/core/test_sup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ int main()
#define TEST(struc) \
{ \
struc *s = 0; \
printf("*%s: %d,%d,%d,%d<%zu*\n", #struc, (int)&(s->a), (int)&(s->b), (int)&(s->c), (int)&(s->later), sizeof(struc)); \
printf("*%s: %ld,%ld,%ld,%ld<%zu*\n", #struc, (long)&(s->a), (long)&(s->b), (long)&(s->c), (long)&(s->later), sizeof(struc)); \
}
#define TEST_ARR(struc) \
{ \
struc *s = 0; \
printf("*%s: %d,%d,%d,%d<%zu*\n", #struc, (int)&(s->a[0]), (int)&(s->a[1]), (int)&(s->a[2]), (int)&(s->later), sizeof(struc)); \
printf("*%s: %ld,%ld,%ld,%ld<%zu*\n", #struc, (long)&(s->a[0]), (long)&(s->a[1]), (long)&(s->a[2]), (long)&(s->later), sizeof(struc)); \
}
printf("sizeofs:%zu,%zu\n", sizeof(S6), sizeof(S6z));
TEST(C___);
Expand Down
Loading