Issue Details (XML | Word | Printable)

Key: PCC-467
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Volkmar Klatt
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

Issue with openbsd and functions returning structs

Created: 13/Aug/14 03:38 PM   Updated: 20/Aug/14 09:44 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. Text File tr_20140813_72.c (2 kB)

Environment: pcc 1.1.0.DEVEL 20140807 for i386-unknown-openbsd5.2


 Description  « Hide
PS: complex math is work in progress, so I don't report this; just a short notice:
float _Complex a,b
a * b crashes
---

/* tr_20140813_72.c - test file for pcc - Volkmar Klatt
 
   Issue with openbsd and functions returning structs int or long int.
   Perhaps *not* an issue of standard lib c,
   as with gcc it works fine on openbsd, too.

   OK with: pcc 1.1.0.DEVEL 20140807 for i686-pc-linux-gnu

   usage:
   gcc tr_20140813_72.c -o z
   pcc tr_20140813_72.c -o zz
---
pcc 1.1.0.DEVEL 20140807 for i386-unknown-openbsd5.2:

int:
q: -115648695
r: -3
Q: 3
R: 1
long int:
q: -115648695
r: -3
Q: 3
R: 1
long long int:
q: 3
r: 1
Q: 3
R: 1
imaxdiv:
q: 3
r: 1
Q: 3
R: 1 */
#include <inttypes.h> /* intmax_t */
#include <stdlib.h>
#include <stdio.h>

int main()
{
   int iq, ir, iQ, iR;
   long int lq, lr, lQ, lR;
   long long int llq,llr,llQ,llR;
   intmax_t mq, mr, mQ, mR;
   div_t IDIV;
   ldiv_t LDIV;
   lldiv_t LLDIV;
   imaxdiv_t MAXDIV;


   printf("int:\n");
   IDIV = div(7, 2);
   iq = IDIV.quot;
   ir = IDIV.rem;
   iQ = 7 / 2;
   iR = 7 % 2;
   printf("q: %i\n", iq);
   printf("r: %i\n", ir);
   printf("Q: %i\n", iQ);
   printf("R: %i\n", iR);

   printf("long int:\n");
   LDIV = ldiv(7L, 2L);
   lq = LDIV.quot;
   lr = LDIV.rem;
   lQ = 7L / 2L;
   lR = 7L % 2L;
   printf("q: %li\n", lq);
   printf("r: %li\n", lr);
   printf("Q: %li\n", lQ);
   printf("R: %li\n", lR);

   printf("long long int:\n");
   LLDIV = lldiv(7LL, 2LL);
   llq = LLDIV.quot;
   llr = LLDIV.rem;
   llQ = 7LL / 2LL;
   llR = 7LL % 2LL;
   printf("q: %lli\n", llq);
   printf("r: %lli\n", llr);
   printf("Q: %lli\n", llQ);
   printf("R: %lli\n", llR);

   printf("imaxdiv:\n");
   MAXDIV = imaxdiv(7, 2);
   mq = MAXDIV.quot;
   mr = MAXDIV.rem;
   mQ = (intmax_t)7 / (intmax_t)2;
   mR = (intmax_t)7 % (intmax_t)2;
/* ? is there a format specifier for intmax_t ? */
   printf("q: %lli\n", (long long int)mq);
   printf("r: %lli\n", (long long int)mr);
   printf("Q: %lli\n", (long long int)mQ);
   printf("R: %lli\n", (long long int)mR);


   return 0;
}




 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Iain Hibbert added a comment - 13/Aug/14 09:33 PM
use modifier j, eg "%ji" to print an intmax_t

Anders Magnusson added a comment - 13/Aug/14 10:21 PM
OpenBSD uses its own way of returning small structs, which has always been a problem to support. I thought I had it running, but obviously not.

Anders Magnusson added a comment - 13/Aug/14 10:23 PM
complex mult should work well. How do you get it to crash?

Anders Magnusson added a comment - 20/Aug/14 09:44 PM
Now fixed, it was a check that hadn't followed when funcode() was updated.
Handling the PIE defaults on OpenBSD is another thing though.