Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7957 Discussions

variable attribute cleanup support?

semenu
Beginner
1,253 Views
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
1,253 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

0 Kudos
8 Replies
SergeyKostrov
Valued Contributor II
1,253 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
0 Kudos
semenu
Beginner
1,253 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.
0 Kudos
Om_S_Intel
Employee
1,253 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.

0 Kudos
SergeyKostrov
Valued Contributor II
1,253 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.

0 Kudos
semenu
Beginner
1,253 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.
0 Kudos
semenu
Beginner
1,253 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
0 Kudos
Judith_W_Intel
Employee
1,254 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
0 Kudos
semenu
Beginner
1,253 Views

This settles my question indeed. Thanks Judy et al!

0 Kudos
Reply