Community
cancel
Showing results for 
Search instead for 
Did you mean: 
semenu
Beginner
281 Views

variable attribute cleanup support?

Jump to solution
Does ICC support GCC's __attribute__((cleanup(..)))?

The documentation (http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/cpp/lin/bldaps_cls/common/bldaps_gcc_compat_comm.htm) calims "Specifying Attributes of Variables" is supported.

The following code compiles cleanly with 12.0.5.225. But the "cleanup" doesn't really work.

The 10.1.026 compiler gives out a warning that the attribute is ignored.

slon.c(11): warning #1292: attribute "cleanup" ignored
int __attribute__((cleanup(check_finished))) finished = 0;

Is this a dead-end or am i missing some switch/pragma to enable the support?


#include
#include

void check_finished(int *p) {
if (!*p)
printf("aborted.\\n");
}

int main(int argc, char *argv[]) {
do {
int __attribute__((cleanup(check_finished))) finished = 0;

printf("Begin...");

if (argc > 1 && !strcmp("boo", argv[1]))
break;

printf("end.\\n");
finished = 1;
} while (0);

return 0;
}
0 Kudos
1 Solution
Judith_W_Intel
Employee
281 Views

I see the bug with the cleanup attribute in 12.0 but it is fixed in 12.1, i.e.:


12.0:

sptxl8-329> icc t.c && ./a.out boo
Begin...sptxl8-330>

12.1:

sptxl8-336> icc t.c && ./a.out boo
Begin...aborted.
sptxl8-337>

Judy

View solution in original post

8 Replies
SergeyKostrov
Valued Contributor II
281 Views
The Intel C++ Compiler User and Reference Guidedoesn'thave any referencesfor the "cleanup" attribute.

>>...But the "cleanup" doesn't really work...

I wonder if thesetwo highlyportablesolutionsto "cleanup-something"could work for you:

- in case of a C program use 'atexit' CRT function

- in case of a C++ program use adestructor of a static object or 'atexit' CRT function
semenu
Beginner
281 Views
The documentation does not appear to be specific on which attributes are actually supported. All I can find is that one may specify them, but that does not appear to mean they are honored. Please, advise if there is in fact a list of supported attributes.
Unfortunately, the task at my hands is C, not C++. And the atexit()-based process-level cleanup is too coarse, I do need it at the scope-level.
More specifically, I need a way to detect/disallow jumping out of the scope with goto, break, continue or return.
I also tried to embark on the documentation's claim on that branching out of the expression statement is not allowed (same page i mentioned above), but that does not seem to match my experiments. Returning and goto-ing out from an expression statement seems to be accepted by the icc.
Om_S_Intel
Employee
281 Views
The gcc and icc behaviour is same.

$ gcc -fexceptions tstcase.c

$ ./a.out

Begin...end.

$ icc -fexceptions tstcase.c

$ ./a.out

Begin...end.

I am using icc version Version 12.1.3.293 and gcc 4.1.

SergeyKostrov
Valued Contributor II
281 Views
Quoting semenu
...if there is in fact a list of supported attributes.

No, I have not seen it.

Unfortunately, the task at my hands is C, not C++. And the atexit()-based process-level cleanup is too coarse, I do need it at the scope-level.

I see.

semenu
Beginner
281 Views
I apologize my example is not self-explanatory. The difference is observed when invoked with "boo" as the first argument. E.g.:

$ gcc slon.c -fexceptions
$ ./a.out
Begin...end.
$ ./a.out boo
Begin...aborted.
$
$ icc slon.c -fexceptions
$ ./a.out
Begin...end.
$ ./a.out boo
Begin...$
$

icc 12.0.5.225. gcc 4.1.2.
semenu
Beginner
281 Views
What makes me think the support for the "cleanup" attribute is in fact present in the compiler is that the "icc" binary appears to contain the error strings related to the "cleanup" attribute:

$ strings `which icc` | grep cleanup | grep attribute
attribute_cleanup_requires_automatic_storage
attribute "cleanup" requires automatic storage duration
attribute_cleanup_for_parameter
attribute "cleanup" does not apply to parameters
Judith_W_Intel
Employee
282 Views

I see the bug with the cleanup attribute in 12.0 but it is fixed in 12.1, i.e.:


12.0:

sptxl8-329> icc t.c && ./a.out boo
Begin...sptxl8-330>

12.1:

sptxl8-336> icc t.c && ./a.out boo
Begin...aborted.
sptxl8-337>

Judy

View solution in original post

semenu
Beginner
281 Views

This settles my question indeed. Thanks Judy et al!

Reply