Mark variables as initialized [cleaned up version] #14403
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The compiler often cannot see through the tangle of code to make
100% correct deduction about whether a variable is initialized or
not. It usually errs on the side of caution and emits a warning.
One example is in codegen.cpp:emit_function where the variable SP
is only ever used when at the same time ctx.debug_enabled is set
to true. The compiler (at least gcc 5.x) doesn't keep track of
this relationship.
From my experience this kind of problem often appears in large
code bases which is why I'm kind of surprised I couldn't find a
framework to handle them. This is why I'm proposing the following
change.
Instead of adding one kludgy workaround here a macro JL_MARK_INITIALIZED
is introduced. When correctly defined (as I do it for gcc) this macro
creates no additional cost in the generated code while preventing the
warning. Definitions for other compilers should be added appropriately.