From 07752225dba0c41f7bb83e1e0154e82b336df457 Mon Sep 17 00:00:00 2001
From: Jim Ursetto <zbigniewsz@gmail.com>
Date: Thu, 12 Jan 2012 18:20:53 -0600
Subject: [PATCH 1/2] Make C_stack_pointer work with LLVM backend
When using LLVM, allocating zero bytes on the stack is legal but
is documented to return an undefined value. In practice, this is
NULL if optimization is enabled, or alloca(1) if not. Work around
this by using alloca(1) to get the stack pointer or, in supported
environments, using inline asm. alloca(1) may waste a machine word,
but does not always; also, llvm uses the stack more efficiently,
so the effects tend to even out.
---
chicken.h | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/chicken.h b/chicken.h
index 7ca7c16..0ca8665 100644
a
|
b
|
extern double trunc(double); |
926 | 926 | #define C_pick(n) (C_temporary_stack[ n ]) |
927 | 927 | #define C_drop(n) (C_temporary_stack += (n)) |
928 | 928 | #define C_alloc(n) ((C_word *)C_alloca((n) * sizeof(C_word))) |
929 | | #define C_stack_pointer ((C_word *)C_alloca(0)) |
| 929 | #if defined (__llvm__) && defined (__GNUC__) |
| 930 | # if defined (__i386__) |
| 931 | # define C_stack_pointer ({C_word *sp; __asm__ __volatile__("movl %%esp,%0":"=r"(sp):);sp;}) |
| 932 | # elif defined (__x86_64__) |
| 933 | # define C_stack_pointer ({C_word *sp; __asm__ __volatile__("movq %%rsp,%0":"=r"(sp):);sp;}) |
| 934 | # else |
| 935 | # define C_stack_pointer ((C_word *)C_alloca(1)) |
| 936 | # endif |
| 937 | #else |
| 938 | # define C_stack_pointer ((C_word *)C_alloca(0)) |
| 939 | #endif |
930 | 940 | #define C_stack_pointer_test ((C_word *)C_alloca(1)) |
931 | 941 | #define C_demand_2(n) (((C_word *)C_fromspace_top + (n)) < (C_word *)C_fromspace_limit) |
932 | 942 | #define C_fix(n) (((C_word)(n) << C_FIXNUM_SHIFT) | C_FIXNUM_BIT) |