Right now, when two variables from different lexical scopes have the same name they are lumped together in the routine scope.
This can cause Visual Studio to display both variables simultaneously in the locals window and report "Variable is optimized away and not available" when referencing one of these variables in the watch window. For example:
if (...) { int local = ...; } else { int local = ...; }
This patch adds initial CodeView support for emitting S_BLOCK32 symbols to describe the lexical scopes containing these variables. Because the CodeView encoding of this symbol only permits a single begin and end location it is not possible to describe lexical scopes with multiple address ranges. Furthermore, this patch makes no attempt to sort variables into lexical blocks originating from inline functions as this functionality is better implemented incrementally.
This patch includes a new test, lexicalblock.ll, which demonstrates what the CodeView output will look like.
The test register-variables.ll required a minor update to change the order in which variables 'a' and 'c' are emitted due to the emission of the lexical blocks.
The same scope can appear multiple times in the same function after inlining:
They key here isn't quite right. This is replicating some of the functionality of the LexicalScopes class.