There is an ongoing issue within gcc as to where warnings should be issued. The question is whether warnings should be issued only by the frontend, or whether it is also OK for the optimizers to issue them.
The advantage of issuing warnings in the frontend are that warnings are independent of optimization level. Also, the warnings are issued much closer to the user’s code, which means that it is easier for the user to understand what they mean, and it is easier to give very good location information.
The advantage of issuing warnings from the optimizers is that some warnings require the data structures built by the optimizers. A good example in gcc is the new strict aliasing warning. This warns about code which may violate the type aliasing restrictions in the language standard. Detecting this requires tracking how pointers are used in the program.
Some other warnings that gcc emits after the frontend are:
- Warnings about large stack frames.
- Warnings about optimizations which rely on undefined signed overflow.
- Warnings about variables which may be changed by setjmp.
- Some warnings about comparisons which are always true or false.
- Warnings about unsafe loop optimizations.
- Warnings about unused values.
- Warnings about unreachable code.
- Warnings about uninitialized variables.
The last two in this list are particularly troublesome. They are simple warnings, but whether they are issued changes based on the optimization level and changes from one compiler release to another. This is confusing and frustrating for users: a new compiler release can mean a new set of warnings.
On the other hand, the optimizers can do a better job. For example, the uninitialized variable warning can warn about uninitialized fields in a structure. It can also warn about variables which are passed to an inlined function by address, but are never initialized by that function. It would be possible to do these in the frontend, but harder.
The right choice may be to separate the warnings: do some basic checking in the frontend, and use different options for the warnings issued by the optimizers.
Leave a Reply
You must be logged in to post a comment.