Return to problem list

ID: 5982990

URL: rdar://problem/5982990

Title: gcc i386: structs not automatically marked volatile in @synchronized block

Originated Date: 03-Jun-2008

State: Closed

Fixed? Yes

Attachments: volatile.m volatile-NSPoint.m

Description:

Summary: A @synchronized block in Objective-C has an implicit exception handler, which uses setjmp/longjmp. Most variables declared within the scope of @synchronized{} are automatically marked as volatile, but a struct is not, at least not when compiling i386. This can lead to compiler warnings that the variable "might be clobbered by 'longjmp' or 'vfork'". This problem can arise even if you don't declare your own struct variable in @synchronized{}, because a struct is implicitly declared when you use NSMakePoint. Thus, the only way to get rid of the compiler warning on i386 is to turn off -Wextra or stop using NSMakePoint. (This is demonstrated with the attached source file "volatile-NSPoint.m".) Steps to Reproduce: (1) Download the attached source file "volatile.m". (2) In Terminal.app, change to working directory containing "volatile.m" (3) gcc -framework Foundation -fobjc-exceptions -Os -arch i386 -Wextra volatile.m Expected Results: No compiler warnings. Actual Results: volatile.m:36: warning: variable 'thePoint' might be clobbered by 'longjmp' or 'vfork' Regression: This problem occurs only when compiling for Intel architecture, not for PowerPC. I've reproduced it with Xcode 3.0 on Mac OS X 10.5.3 and Xcode 2.5 on Mac OS X 10.4.11. The warning does not occur with the following compiler invocations: gcc -framework Foundation -fobjc-exceptions -Os -arch ppc -Wextra volatile.m gcc -framework Foundation -fobjc-exceptions -Os -arch i386 volatile.m gcc -framework Foundation -fobjc-exceptions -Os -arch i386 -Wextra -D MY_VAR_IS_VOLATILE volatile.m Thus, it's clear that the issue is the volatile qualifier, the warning is from -Wextra, and the problem is 386 only. Notes: Attached Objective-C source files "volatile.m" and "volatile-NSPoint.m".

Return to problem list