Commit f9c6d53f authored by Simon Marlow's avatar Simon Marlow Committed by Ben Gamari

Tag the FUN before making a PAP (#13767)

Pointers to FUNs are not guaranteed to be tagged in general, because
the compiler doesn't always know the arity of a FUN when it needs to
reference it, e.g. with -O0 when the function is in another module.

However, there's one case where we can put the correct tag on a FUN:
when it is referenced by a PAP, because when building the PAP we know
the arity and we can tag the pointer correctly.  The AutoApply code
does this, and the sanity checker checks it, but the interpreter did
not respect this invariant.  This patch fixes it.

Test Plan:
(cd ghc && make 2 GhcDebugged=YES)
./inplace/bin/ghc-stage2 --interpreter +RTS -DS

Reviewers: niteria, bgamari, austin, erikd

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13767

Differential Revision:
parent 1a9c3c44
......@@ -406,8 +406,18 @@ eval_obj:
#if defined(PROFILING)
if (cap->r.rCCCS != obj-> {
int arity = get_fun_itbl(obj)->f.arity;
// Tag the function correctly. We guarantee that pap->fun
// is correctly tagged (this is checked by
// Sanity.c:checkPAP()), but we don't guarantee that every
// pointer to a FUN is tagged on the stack or elsewhere,
// so we fix the tag here. (#13767)
// For full details of the invariants on tagging, see
tagged_obj =
newEmptyPAP(cap, tagged_obj, get_fun_itbl(obj)->f.arity);
arity <= TAG_MASK ? obj + arity : obj,
......@@ -424,7 +434,7 @@ eval_obj:
ASSERT(((StgBCO *)obj)->arity > 0);
#if defined(PROFILING)
if (cap->r.rCCCS != obj-> {
tagged_obj = newEmptyPAP(cap, tagged_obj, ((StgBCO *)obj)->arity);
tagged_obj = newEmptyPAP(cap, obj, ((StgBCO *)obj)->arity);
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment