diff --git a/src/qthread.c b/src/qthread.c index fe02148df..a016bd1bb 100644 --- a/src/qthread.c +++ b/src/qthread.c @@ -1291,11 +1291,17 @@ API_FUNC void *qthread_bos(void) { } size_t API_FUNC qthread_stackleft(void) { /*{{{ */ +#if defined(__NVCOMPILER) + qthread_t const volatile *f = qthread_internal_self(); +#else qthread_t const *f = qthread_internal_self(); +#endif if ((f != NULL) && (f->rdata->stack != NULL)) { -#ifdef __INTEL_COMPILER +#if defined(__INTEL_COMPILER) size_t current = (size_t)&f; +#elif defined(__NVCOMPILER) + volatile size_t current = (size_t)&f; #else size_t current = (size_t)__builtin_frame_address(0); #endif diff --git a/test/basics/qthread_stackleft.c b/test/basics/qthread_stackleft.c index 24b96b0cb..36f679a13 100644 --- a/test/basics/qthread_stackleft.c +++ b/test/basics/qthread_stackleft.c @@ -14,7 +14,9 @@ static aligned_t alldone; #ifdef __clang__ #define STACKLEFT_NOINLINE __attribute__((optnone)) -#elif __GNUC__ +#elif defined(__NVCOMPILER) +#define STACKLEFT_NOINLINE __attribute__((noinline)) +#elif defined(__GNUC__) #define STACKLEFT_NOINLINE __attribute__((optimize(0))) #else #define STACKLEFT_NOINLINE @@ -35,6 +37,11 @@ static aligned_t alldone; #define QT_SKIP_THREAD_SANITIZER #endif +#ifdef __NVCOMPILER +#pragma GCC push_options +#pragma GCC optimize("O0") +#endif + static STACKLEFT_NOINLINE size_t thread2(size_t left, size_t depth) { size_t foo = qthread_stackleft(); iprintf("leveli%i: %zu bytes left\n", (int)depth, foo); @@ -43,6 +50,10 @@ static STACKLEFT_NOINLINE size_t thread2(size_t left, size_t depth) { return 1; } +#ifdef __NVCOMPILER +#pragma GCC pop_options +#endif + static QT_SKIP_THREAD_SANITIZER aligned_t thread(void *arg) { int me = qthread_id(); size_t foo = qthread_stackleft();