Skip to content

Commit

Permalink
Fix stackleft on nvc.
Browse files Browse the repository at this point in the history
  • Loading branch information
insertinterestingnamehere committed Oct 7, 2024
1 parent b097998 commit 9f33afa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/qthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ size_t API_FUNC qthread_stackleft(void) { /*{{{ */
qthread_t const *f = qthread_internal_self();

if ((f != NULL) && (f->rdata->stack != NULL)) {
#ifdef __INTEL_COMPILER
#if defined(__INTEL_COMPILER)
size_t current = (size_t)&f;
#else
size_t current = (size_t)__builtin_frame_address(0);
Expand Down
13 changes: 12 additions & 1 deletion test/basics/qthread_stackleft.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ static aligned_t x = 0;

static aligned_t alldone;

// The structure of this test is fairly trivial so we have to use
// various compiler-specific stuff to prevent TCO from kicking in
// and preventing us from testing that the stack behaves as expected.
#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
Expand All @@ -37,6 +42,12 @@ static aligned_t alldone;

static STACKLEFT_NOINLINE size_t thread2(size_t left, size_t depth) {
size_t foo = qthread_stackleft();

#if defined(__NVCOMPILER)
// nvc doesn't currently support enough attributes/pragmas to prevent TCO
// here. This still works though.
asm volatile("" : : "g"(&depth) : "memory");
#endif
iprintf("leveli%i: %zu bytes left\n", (int)depth, foo);
assert(foo < left);
if (depth < 5) { thread2(foo, depth + 1); }
Expand Down

0 comments on commit 9f33afa

Please sign in to comment.