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

            Bug ID: 81106
           Summary: gnatchop -r misplaces BOM
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: simon at pushface dot org
  Target Milestone: ---
              Host: x86_64-apple-darwin16

Created attachment 41558
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41558&action=edit
Demonstrator (with BOM)

If gnatchop is given an input file with a UTF8 BOM, it copies the BOM
to the front of each output file.

If the -r switch is given (generate Source_Reference pragmas
referencing original source file), the generated Source_Reference
pragma for the first output file only is output before the BOM, thus
rendering the first output file's BOM ineffective.

I think this is because in gnatchop.adb (Write_Chopped_Files), the BOM
of the first output unit is copied over as part of the beginning of
the input file:

            Write_Unit
              (Source    => Buffer,
               Num       => Unit_Number,
               TS_Time   => TS_Time,
               Write_BOM => BOM_Present and then Unit_Number /= 1,
               Success   => Success);

The attachment (zipped because it contains a BOM), if chopped without -r,
contains

$ od -ctx1 pack1.ads
0000000  357 273 277   p   a   c   k   a   g   e       P   a   c   k   1
           ef  bb  bf  70  61  63  6b  61  67  65  20  50  61  63  6b  31
0000020   \n   w   i   t   h       E   l   a   b   o   r   a   t   e   _
           0a  77  69  74  68  20  45  6c  61  62  6f  72  61  74  65  5f
0000040    B   o   d   y  \n   i   s  \n   e   n   d       P   a   c   k
           42  6f  64  79  0a  69  73  0a  65  6e  64  20  50  61  63  6b
0000060    1   ;  \n                                                    
           31  3b  0a

whereas with -r it contains

0000000    p   r   a   g   m   a       S   o   u   r   c   e   _   R   e
           70  72  61  67  6d  61  20  53  6f  75  72  63  65  5f  52  65
0000020    f   e   r   e   n   c   e       (   0   0   0   0   0   1   ,
           66  65  72  65  6e  63  65  20  28  30  30  30  30  30  31  2c
0000040        "   p   a   c   k   1   .   a   d   a   "   )   ;  \n 273
           20  22  70  61  63  6b  31  2e  61  64  61  22  29  3b  0a  ef
0000060  273 277   p   a   c   k   a   g   e       P   a   c   k   1  \n
           bb  bf  70  61  63  6b  61  67  65  20  50  61  63  6b  31  0a
0000100    w   i   t   h       E   l   a   b   o   r   a   t   e   _   B
           77  69  74  68  20  45  6c  61  62  6f  72  61  74  65  5f  42
0000120    o   d   y  \n   i   s  \n   e   n   d       P   a   c   k   1
           6f  64  79  0a  69  73  0a  65  6e  64  20  50  61  63  6b  31
0000140    ;  \n                                                        
           3b  0a                                                        
0000142

The BOM (ef bb bf) starts at 057.

Reply via email to