public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/111675] New: Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter
@ 2023-10-03 10:35 gaius at gcc dot gnu.org
  2023-10-03 10:35 ` [Bug modula2/111675] " gaius at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-10-03 10:35 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug modula2/111675] Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter
  2023-10-03 10:35 [Bug modula2/111675] New: Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter gaius at gcc dot gnu.org
@ 2023-10-03 10:35 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-10-03 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-10-03
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Confirmed this is a bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug modula2/111675] Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter
  2023-10-03 10:35 [Bug modula2/111675] New: Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter gaius at gcc dot gnu.org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-11 12:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:

https://gcc.gnu.org/g:2b783fe2e8103d97db7c5d6c1514ba16091f39f6

commit r14-4556-g2b783fe2e8103d97db7c5d6c1514ba16091f39f6
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Wed Oct 11 13:26:47 2023 +0100

    PR modula2/111675 Incorrect packed record field value passed to a procedure

    This patch allows a packed field to be extracted and passed to a
    procedure.  It ensures that the subrange type is the same for both the
    procedure and record field.  It also extends the <* bytealignment (0) *>
    to cover packed subrange types.

    gcc/m2/ChangeLog:

            PR modula2/111675
            * gm2-compiler/M2CaseList.mod (appendTree): Replace
            InitStringCharStar with InitString.
            * gm2-compiler/M2GCCDeclare.mod: Import AreConstantsEqual.
            (DeclareSubrange): Add zero alignment test and call
            BuildSmallestTypeRange if necessary.
            (WalkSubrangeDependants): Walk the align expression.
            (IsSubrangeDependants): Test the align expression.
            * gm2-compiler/M2Quads.mod (BuildStringAdrParam): Correct end name.
            * gm2-compiler/P2SymBuild.mod (BuildTypeAlignment): Allow subranges
            to be zero aligned (packed).
            * gm2-compiler/SymbolTable.mod (Subrange): Add Align field.
            (MakeSubrange): Set Align to NulSym.
            (PutAlignment): Assign Subrange.Align to align.
            (GetAlignment): Return Subrange.Align.
            * gm2-gcc/m2expr.cc (noBitsRequired): Rewrite.
            (calcNbits): Rename ...
            (m2expr_calcNbits): ... to this and test for negative values.
            (m2expr_BuildTBitSize): Replace calcNBits with m2expr_calcNbits.
            * gm2-gcc/m2expr.def (calcNbits): Export.
            * gm2-gcc/m2expr.h (m2expr_calcNbits): New prototype.
            * gm2-gcc/m2type.cc (noBitsRequired): Remove.
            (m2type_BuildSmallestTypeRange): Call m2expr_calcNbits.
            (m2type_BuildSubrangeType): Create range_type from
            build_range_type (type, lowval, highval).

    gcc/testsuite/ChangeLog:

            PR modula2/111675
            * gm2/extensions/run/pass/packedrecord3.mod: New test.

    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug modula2/111675] Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter
  2023-10-03 10:35 [Bug modula2/111675] New: Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter gaius at gcc dot gnu.org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-10-11 12:28 UTC (permalink / raw)
  To: gcc-bugs

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

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #3 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing now that the patch has been applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-11 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-03 10:35 [Bug modula2/111675] New: Incorrect parameter value passed when attempting to pass a field of a packed record as a parameter gaius at gcc dot gnu.org
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

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).