Does this match how msvc emits S_LDATA32?<br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 5, 2018 at 12:15 PM Brock Wyma via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">bwyma created this revision.<br>
bwyma added reviewers: rnk, zturner.<br>
<br>
Currently, global variables with local visibility such as the following...<br>
<br>
  void foo() {<br>
    static int local = 1;<br>
  }<br>
<br>
  void bar() {<br>
    static int local = 3;<br>
  }<br>
<br>
...  are emitted in CodeView as global S_LDATA32 entries outside of any routine:<br>
<br>
  CodeViewDebugInfo [<br>
    Section: .debug$S (5)<br>
    Subsection [<br>
      GlobalProcIdSym {<br>
        Kind: S_GPROC32_ID (0x1147)<br>
        DisplayName: foo                              # Routine foo()<br>
      }<br>
      ProcEnd {<br>
        Kind: S_PROC_ID_END (0x114F)<br>
      }<br>
    ]<br>
    Subsection [<br>
      GlobalProcIdSym {<br>
        Kind: S_GPROC32_ID (0x1147)<br>
        DisplayName: bar                              # Routine bar()<br>
      }<br>
      ProcEnd {<br>
        Kind: S_PROC_ID_END (0x114F)<br>
      }<br>
    ]<br>
    Subsection [<br>
      DataSym {<br>
        Kind: S_LDATA32 (0x110C)<br>
        DisplayName: local                            # "local" inside "foo"<br>
        LinkageName: ?local@?1??foo@@YAXXZ@4HA<br>
      }<br>
      DataSym {<br>
        Kind: S_LDATA32 (0x110C)<br>
        DisplayName: local                            # "local" inside "bar"<br>
        LinkageName: ?local@?1??bar@@YAXXZ@4HA<br>
      }<br>
    ]<br>
  ]<br>
<br>
When debugging routines foo() and bar(), Visual Studio 2017 will locate whichever value for "local" it finds first, which may not be the correct one, and happily display the potentially incorrect value.<br>
<br>
This change builds upon the lexical block support added in rL327620 <<a href="https://reviews.llvm.org/rL327620" rel="noreferrer" target="_blank">https://reviews.llvm.org/rL327620</a>> to sort global variables according to lexical scope. The result for the example above after this patch looks like this:<br>
<br>
  CodeViewDebugInfo [<br>
    Section: .debug$S (5)<br>
    Subsection [<br>
      SubSectionType: Symbols (0xF1)<br>
      GlobalProcIdSym {<br>
        Kind: S_GPROC32_ID (0x1147)<br>
        DisplayName: foo                              # Routine foo()<br>
      }<br>
      DataSym {<br>
        Kind: S_LDATA32 (0x110C)<br>
        DisplayName: local                            # "local" inside "foo"<br>
        LinkageName: ?local@?1??foo@@YAXXZ@4HA<br>
      }<br>
      ProcEnd {<br>
        Kind: S_PROC_ID_END (0x114F)<br>
      }<br>
    ]<br>
    Subsection [<br>
      SubSectionType: Symbols (0xF1)<br>
      GlobalProcIdSym {<br>
        Kind: S_GPROC32_ID (0x1147)<br>
        DisplayName: bar                              # Routine bar()<br>
      }<br>
      DataSym {<br>
        Kind: S_LDATA32 (0x110C)<br>
        DisplayName: local                            # "local" inside "bar"<br>
        LinkageName: ?local@?1??bar@@YAXXZ@4HA<br>
      }<br>
      ProcEnd {<br>
        Kind: S_PROC_ID_END (0x114F)<br>
      }<br>
    ]<br>
  ]<br>
<br>
The changes to the test type-quals.ll are index adjustments because of a minor change in the order in which the entries appear. I added the test global_visibility.ll to validate the new scoping behavior.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D55336" rel="noreferrer" target="_blank">https://reviews.llvm.org/D55336</a><br>
<br>
Files:<br>
  lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
  lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
  test/DebugInfo/COFF/global_visibility.ll<br>
  test/DebugInfo/COFF/type-quals.ll<br>
<br>
</blockquote></div>