Opened 10 months ago

Last modified 5 weeks ago

#1340 new defect

Unable to compile a mathh gama instruction at or above optimize-level 3

Reported by: rca Owned by:
Priority: minor Milestone: 5.1
Component: unknown Version: 4.11.0
Keywords: Cc:
Estimated difficulty: medium

Description

Compiling the following code at or above optimize-level 3 results in an error.

{{{(use mathh)

(define (factorial x)

(gamma (+ 1 x)) )

(factorial 9)}}}

csc -optimize-level 3 test.scm
test.c:213:4: warning: implicit declaration of function

'stub177' is invalid in C99
[-Wimplicit-function-declaration]

t6=stub177(t4,t5);


1 warning generated.

Change History (7)

comment:1 Changed 10 months ago by rca

Did some checking and it impacts more than just gamma… nothing in mathh seems to
compile at level 3.

comment:2 Changed 10 months ago by kooda

The undefined C functions seem to be part of the mathh.c file when compiling mathh.scm, but for some reason these are declared static there, thus making it impossible to use them while inlining.

For example, the mathh.c file contains the mentioned stub177 function:

C_regparm static C_word C_fcall stub177(C_word C_buf,C_word C_a0){
C_word C_r=C_SCHEME_UNDEFINED,*C_a=(C_word*)C_buf;
double t0=(double )C_c_double(C_a0);
C_r=C_flonum(&C_a,tgamma(t0));
return C_r;}
Last edited 10 months ago by kooda (previous) (diff)

comment:3 Changed 10 months ago by rca

Error persists with version 4.12rc1.

comment:4 Changed 9 months ago by LemonBoy

This happens because all the functions are defined using foreign-lambda which in turn does nothing but generate a stub (see create-foreign-stub) that serves as a trampoline for calling the real C function: the stub that gets generated in that phase is the ones you're seeing in the .inline file.
But there's more: all the stub does is preparing the environment and then it just calls another stub which in turn calls the C function and this part is missing from the inline file as it's generated much later (in c-backend.scm generate-foreign-stubs, the stub name is the variable named f-id in create-foreign-stub).

comment:5 Changed 3 months ago by sjamaan

  • Estimated difficulty set to medium
  • Milestone changed from someday to 4.13.0

Is this fixable?

comment:6 Changed 2 months ago by kon

rmvd gen of mathh.inline in 3.2.2 so cannot generate error.

comment:7 Changed 5 weeks ago by sjamaan

  • Milestone changed from 4.13.0 to 5.1

This is not trivially fixed, except by not generating inline files (as Kon has done). I think a proper fix will have to wait for 5.1 or later.

Note: See TracTickets for help on using tickets.