public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X
@ 2011-10-29  5:03 carsomyr at gmail dot com
  2012-05-23 21:35 ` [Bug objc/50909] " carl at lytro dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: carsomyr at gmail dot com @ 2011-10-29  5:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909

             Bug #: 50909
           Summary: Process "#pragma options align=reset" correctly on Mac
                    OS X
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: objc
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: carsomyr@gmail.com


Created attachment 25656
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25656
The patch.

I recently discovered that this program

  #include <IOKit/usb/USB.h>

  #pragma pack(1)
  int main() {
      return 0;
  }
  #pragma options align=reset

doesn't compile and gives the error

  too many #pragma options align=reset

Notice that the program includes "IOKit/usb/USB.h". In that file, pragmas are
used like:

  #pragma pack(1)
  ...
  #pragma options align=reset

This gives the error because "#pragma pack(1)" is invisible to the relevant
logic in "gcc/config/darwin-c.c". As such, I've attached a patch,
"patch-pragmas.diff", that unifies said logic with the main pragma logic in
"gcc/c-family/c-pragma.c".

If the currently observed behavior for the test program is the intended
behavior, please close this bug and ignore the patch.


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
@ 2012-05-23 21:35 ` carl at lytro dot com
  2012-08-08  8:26 ` roman at qubyx dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: carl at lytro dot com @ 2012-05-23 21:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909

Carl Norum <carl at lytro dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |carl at lytro dot com

--- Comment #1 from Carl Norum <carl at lytro dot com> 2012-05-23 20:58:33 UTC ---
This same problem happened to me today on 4.7.0 - is it just expected behaviour
or is this patch worth taking?


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
  2012-05-23 21:35 ` [Bug objc/50909] " carl at lytro dot com
@ 2012-08-08  8:26 ` roman at qubyx dot com
  2013-09-13 18:53 ` dc7000 at att dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: roman at qubyx dot com @ 2012-08-08  8:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909

Roman <roman at qubyx dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |roman at qubyx dot com

--- Comment #2 from Roman <roman at qubyx dot com> 2012-08-08 08:26:07 UTC ---
This patch is works. I tested it on gcc 4.7.1 and 4.6.3. Mac OS version 10.6.8


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
  2012-05-23 21:35 ` [Bug objc/50909] " carl at lytro dot com
  2012-08-08  8:26 ` roman at qubyx dot com
@ 2013-09-13 18:53 ` dc7000 at att dot com
  2013-09-13 19:05 ` dominiq at lps dot ens.fr
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dc7000 at att dot com @ 2013-09-13 18:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909

Dean Churchill <dc7000 at att dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dc7000 at att dot com

--- Comment #3 from Dean Churchill <dc7000 at att dot com> ---
I am trying to apply this patch on OSX Lion (10.8.5) to gcc 4.6.2, but the diff
command on OSX doesn't accept the --git option, and am not sure how to rewrite
the patch for Lion.  Can you help?


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
                   ` (2 preceding siblings ...)
  2013-09-13 18:53 ` dc7000 at att dot com
@ 2013-09-13 19:05 ` dominiq at lps dot ens.fr
  2013-09-13 20:32 ` dc7000 at att dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens.fr @ 2013-09-13 19:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909

--- Comment #4 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> I am trying to apply this patch on OSX Lion (10.8.5) to gcc 4.6.2, 
> but the diff command on OSX doesn't accept the --git option, 
> and am not sure how to rewrite the patch for Lion.  Can you help?

If the patch applies cleanly on 4.6.2, from the source directory

patch -p0 -i patch_name

should work.


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
                   ` (3 preceding siblings ...)
  2013-09-13 19:05 ` dominiq at lps dot ens.fr
@ 2013-09-13 20:32 ` dc7000 at att dot com
  2014-06-23 14:52 ` dominiq at lps dot ens.fr
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dc7000 at att dot com @ 2013-09-13 20:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50909

--- Comment #5 from Dean Churchill <dc7000 at att dot com> ---
That worked. thanks


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
                   ` (4 preceding siblings ...)
  2013-09-13 20:32 ` dc7000 at att dot com
@ 2014-06-23 14:52 ` dominiq at lps dot ens.fr
  2014-06-23 15:48 ` alex.wolf at gmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-06-23 14:52 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2014-06-23
     Ever confirmed|0                           |1

--- Comment #7 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> 3 years later and it still doesn't work... gcc version 4.8.3, installed
> using homebrew on OSX 10.9.3.

Well, you did not fix it, did you?

Reducing the test in comment 0 to

  #include <IOKit/usb/USB.h>

gives

In file included from pr50909_red.c:1:0:
/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:584:9: error: too
many #pragma options align=reset
 #pragma options align=reset
         ^
In file included from pr50909_red.c:1:0:
/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:754:9: error: too
many #pragma options align=reset
 #pragma options align=reset
         ^
/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:806:9: error: too
many #pragma options align=reset
 #pragma options align=reset
         ^
/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:824:9: error: too
many #pragma options align=reset
 #pragma options align=reset
         ^
/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:844:9: error: too
many #pragma options align=reset
 #pragma options align=reset
         ^

Now looking at the gcc manual I found at
https://gcc.gnu.org/onlinedocs/gcc/Darwin-Pragmas.html#Darwin-Pragmas

options align=alignment
This pragma sets the alignment of fields in structures. The values of alignment
may be mac68k, to emulate m68k alignment, or power, to emulate PowerPC
alignment. Uses of this pragma nest properly; to restore the previous setting,
use reset for the alignment. 

in line with the code in gcc/config/darwin-c.c. I also found at
https://gcc.gnu.org/onlinedocs/gcc/Structure-Packing-Pragmas.html

6.57.8 Structure-Packing Pragmas

For compatibility with Microsoft Windows compilers, GCC supports a set of
#pragma directives that change the maximum alignment of members of structures
(other than zero-width bit-fields), unions, and classes subsequently defined.
The n value below always is required to be a small power of two and specifies
the new alignment in bytes.

#pragma pack(n) simply sets the new alignment.
#pragma pack() sets the alignment to the one that was in effect when
compilation started (see also command-line option -fpack-struct[=n] see Code
Gen Options).
#pragma pack(push[,n]) pushes the current alignment setting on an internal
stack and then optionally sets the new alignment.
#pragma pack(pop) restores the alignment setting to the one saved at the top of
the internal stack (and removes that stack entry). Note that #pragma pack([n])
does not influence this internal stack; thus it is possible to have #pragma
pack(push) followed by multiple #pragma pack(n) instances and finalized by a
single #pragma pack(pop).
Some targets, e.g. i386 and PowerPC, support the ms_struct #pragma which lays
out a structure as the documented __attribute__ ((ms_struct)).

#pragma ms_struct on turns on the layout for structures declared.
#pragma ms_struct off turns off the layout for structures declared.
#pragma ms_struct reset goes back to the default layout.

So AFAIU gcc behaves as documented, while the behavior has been changed in
clang (for which the tests compile).

IMO this PR should be closed as INVALID or WONTFIX, unless someone want to
implement the clang behavior.


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
                   ` (5 preceding siblings ...)
  2014-06-23 14:52 ` dominiq at lps dot ens.fr
@ 2014-06-23 15:48 ` alex.wolf at gmail dot com
  2014-06-23 16:30 ` manu at gcc dot gnu.org
  2021-10-25 11:01 ` emmiller at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: alex.wolf at gmail dot com @ 2014-06-23 15:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Alex <alex.wolf at gmail dot com> ---
I am writing cross platform code with some platform specific USB enumeration
functionality. IOKit was just what I needed on the mac, libudev on linux. I
inevitably stumbled over this issue when trying to compile the mac portion. 

I think it would be sad if gcc wouldn't support these deviations from the
standard in the future, considering anybody trying to use IOKit with gcc will
come across this "bug".

Are you saying I should not use gcc on a mac with IOKit?
If I should, then gcc should not give me such an error. It is easy to work
around but why punish the developer when Apple wrote the non-compliant header
that IOKit users must include.
I think this is a clear case where gcc could & should change its leniency for
the sake of its developers. Or, am I supposed to write my own USB library from
the ground up for mac just because the pragmas aren't supported? 


I "fixed" my setup without recompiling gcc:
I made a backup of USB.h and then changed all occurrences of

#pragma options align=reset

to 

#pragma pack()

which seemed to compile and run. 

As to someone implementing clang behavior: I was under the impression that the
attached patch just needed to be applied? That is why I was inquiring as to why
nobody had applied it after 3 years.


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
                   ` (6 preceding siblings ...)
  2014-06-23 15:48 ` alex.wolf at gmail dot com
@ 2014-06-23 16:30 ` manu at gcc dot gnu.org
  2021-10-25 11:01 ` emmiller at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2014-06-23 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #9 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Alex from comment #8)
> As to someone implementing clang behavior: I was under the impression that
> the attached patch just needed to be applied? That is why I was inquiring as
> to why nobody had applied it after 3 years.

Writing a patch is often the easy part. The hard part is getting the patch
approved and following up on reviewer's comments. See
https://gcc.gnu.org/contribute.html and https://gcc.gnu.org/wiki/GCC_Research

The patch doesn't look correct to me anyway, but you will get a better review
from a Darwin maintainer, see the MAINTAINERS file in the gcc sources.
>From gcc-bugs-return-454718-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Jun 23 16:59:01 2014
Return-Path: <gcc-bugs-return-454718-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 22377 invoked by alias); 23 Jun 2014 16:59:01 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 21331 invoked by uid 55); 23 Jun 2014 16:58:23 -0000
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/61553] __atomic_store with non-pointer arg ICE
Date: Mon, 23 Jun 2014 16:59:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: mpolacek at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.10.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-61553-4-cz3lj0u5cS@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61553-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61553-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-06/txt/msg01800.txt.bz2
Content-length: 576

https://gcc.gnu.org/bugzilla/show_bug.cgi?ida553

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Mon Jun 23 16:57:48 2014
New Revision: 211905

URL: https://gcc.gnu.org/viewcvs?rev!1905&root=gcc&view=rev
Log:
    PR c/61553
    * c-common.c (get_atomic_generic_size): Don't segfault if the
    type doesn't have a size.

    * c-c++-common/pr61553.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/pr61553.c
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug objc/50909] Process "#pragma options align=reset" correctly on Mac OS X
  2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
                   ` (7 preceding siblings ...)
  2014-06-23 16:30 ` manu at gcc dot gnu.org
@ 2021-10-25 11:01 ` emmiller at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: emmiller at gmail dot com @ 2021-10-25 11:01 UTC (permalink / raw)
  To: gcc-bugs

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

Evan Miller <emmiller at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |emmiller at gmail dot com

--- Comment #16 from Evan Miller <emmiller at gmail dot com> ---
An unusual but viable workaround for this problem is:

  #pragma options align=power
  #pragma options align=power
  #pragma options align=power
  #pragma options align=power
  #pragma options align=power
  #include <IOKit/usb/USB.h>

This technique pre-loads the "options" alignment stack with five default
values. When

  #pragma pack(1)

is encountered in the header file, the global alignment is set to 1 byte. Then
when

  #pragma options align=reset

is encountered, a value is popped off the options stack and the global
alignment is set to the value at the top of the stack ("power" which is
implemented as the platform default). So the pack and options pragmas inside
the header file end up having the desired effect.

If the number of "align=power" pragmas before the header inclusion equals the
number of "align=reset" pragmas inside the header, then after inclusion, the
alignment stack will be whatever it was before all the "align=power" pragmas.
It probably won't hurt anything to have extra values on the alignment stack, so
you can add a few more to be safe.

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

end of thread, other threads:[~2021-10-25 11:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-29  5:03 [Bug objc/50909] New: Process "#pragma options align=reset" correctly on Mac OS X carsomyr at gmail dot com
2012-05-23 21:35 ` [Bug objc/50909] " carl at lytro dot com
2012-08-08  8:26 ` roman at qubyx dot com
2013-09-13 18:53 ` dc7000 at att dot com
2013-09-13 19:05 ` dominiq at lps dot ens.fr
2013-09-13 20:32 ` dc7000 at att dot com
2014-06-23 14:52 ` dominiq at lps dot ens.fr
2014-06-23 15:48 ` alex.wolf at gmail dot com
2014-06-23 16:30 ` manu at gcc dot gnu.org
2021-10-25 11:01 ` emmiller at gmail dot com

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