2
votes

I am working with code from the GNU core utils, and find that the void usage() function is apparently set with the attribute "noreturn". Well, I am modifying the function, and I wish it to return (I removed the call to exit()). The compiler still complains that a "noreturn" function returns, and when using the Eclipse CDT debugger, stepping thorugh the code is anomolous - I skip over lines of code. I do not see the function be set in the .c file, and there is no .h file for this .c file.

The file is df.c. I have renamed the file df_call.c. How can the compiler be finding this attribute? How can I unset it?

Thanks.

======= Thanks to all contributors for their help! The short answer is "the usage() function found in GNUutils 7.4 is prototyped in system.h as 'void usage (int status) ATTRIBUTE_NORETURN'. Changing to 'void usage (int status); /ATTRIBUTE_NORETURN;/' resolved the issue for me, but leaves the problem of a modified system.h.

The long answer is: The GNU c compiler supports assigning attributes to functions (see http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) one of which is "noreturn". The syntax is "attribute ((noreturn))" (see http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax) but is often macro'd to ATTRIBUTE_NORETURN. If the attribute is set, and in this case one tries to return from the function, the executable compiles with a complaint, but compiles and runs. It will, however, behave unexpectedly (skipping over src lines in my case, maybe due to the optimization). The debugger in Eclipse CDT actually jumps past lines of code, leading the developer to doubt his senses.

2
Did you try grepping through the source for noreturn (or ATTRIBUTE_NORETURN, which is is typedef'ed to in the versions of coreutils I can find on google codesearch)?Tyler McHenry
Er, that should be __noreturn__, damn markdown.Tyler McHenry
I recommend doing a "grep" for usage in that directory :)Johannes Schaub - litb
Well, I tried grepping for noreturn in lib and src, which are the directories where the .c and .h files are located. There is a macro definition for noreturn as NORETURN, so I did a grep -i with no results related to my quest. Now, there are numerous usage() functions, about one per utility, so that is not effective. I have downloaded coreutils-7.4, and that is what I ma looking in.cvsdave

2 Answers

1
votes

I would suggest preprocessing the source file so you have the entire contents of the translation unit available to you. From there I would search for usage to see where the gcc attribute may be coming from. You should also check possible gcc command line arguments and/or macros that may be affecting your function declaration.

0
votes

run gcc -E instead of gcc -c and have a look at the results. With luck it will be clear there the noreturn attribute is coming from.

Another alternative would be to do what I do, which is avoid using gcc-specific extensions.

gcc -std=c99 -pedantic

may tame the beast.