public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gaius at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug modula2/111675] New: Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter
Date: Tue, 03 Oct 2023 10:35:25 +0000	[thread overview]
Message-ID: <bug-111675-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111675

            Bug ID: 111675
           Summary: Incorrect parameter value passed when attempting to
                    pass a field of a packed record as a parameter
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: modula2
          Assignee: gaius at gcc dot gnu.org
          Reporter: gaius at gcc dot gnu.org
  Target Milestone: ---

Summary cannot pass a packed field by value to a procedure as it results in a
garbled value.

Consider the example below, if compiled and run we get:

$ gm2 -g packedrecord3.mod
$ ./a.out
failed to pass 0 into test
$ gdb ./a.out
(gdb) break printf
(gdb) run
Breakpoint 3, __printf (format=0x402008 "failed to pass %d into test\n") 
(gdb) where
#0  __printf (format=0x402008 "failed to pass %d into test\n") at printf.c:28
#1  0x0000000000401387 in test (s=36893488147419103232, level=0) at
packedrecord3.mod:25
#2  0x00000000004012ce in _M2_packedrecord3_init (argc=1, argv=0x7fffffffe448,
envp=0x7fffffffe458) at packedrecord3.mod:47

oddly print sizeof s gives 16 !  


module packedrecord3 ;  (*!m2iso+gm2*)

from libc import printf, exit ;

type
   subrange = [0..63] ;

   packedrec = record
                  <* bytealignment (0) *>
                  bool: boolean ;
                  col : (white, black) ;
                  sub : subrange ;
               end ;


var
   global: subrange ;
   pr    : packedrec ;


procedure test (s: subrange; level: cardinal) ;
begin
   if s # global
   then
      printf ("failed to pass %d into test\n", ord (s)) ;
      exit (1)
   end ;
   if level > 0
   then
      test (s, level-1)
   end
end test ;


begin
   if size (pr) # 1
   then
      printf ("test failed as size (pr) should be 1 not %d\n", size (pr)) ;
      exit (1)
   end ;
   for global := min (subrange) to max (subrange) do
      test (global, 2)
   end ;
   for global := min (subrange) to max (subrange) do
      pr.bool := false ;
      pr.sub := global ;
      test (pr.sub, 2)
   end
end packedrecord3.

             reply	other threads:[~2023-10-03 10:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03 10:35 gaius at gcc dot gnu.org [this message]
2023-10-03 10:35 ` [Bug modula2/111675] " gaius at gcc dot gnu.org
2023-10-11 12:27 ` cvs-commit at gcc dot gnu.org
2023-10-11 12:28 ` gaius at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-111675-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).