[PATCH] D42926: [CodeView] Initial support for emitting S_BLOCK32 symbols for lexical scopes

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 17:58:13 PST 2018


rnk added a comment.

Thanks! So, I guess nesting S_DEFRANGE inside S_BLOCK32 works in VS? I thought we did experiments to show that it didn't, but hey, if it works, great.



================
Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:369
+    // This variable goes into the corresponding lexical scope.
+    ScopeVariables[LS].emplace_back(Var);
   }
----------------
I suspect we'll want to move the logic in `DwarfFile::addScopeVariable` into DebugHandlerBase so that parameters come out in the right order, etc.


================
Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:2311-2314
+  OS.AddComment("PtrParent"); 
+  OS.EmitIntValue(0, 4);                                  // PtrParent 
+  OS.AddComment("PtrEnd"); 
+  OS.EmitIntValue(0, 4);                                  // PtrEnd 
----------------
zturner wrote:
> Shouldn't we be emitting the actual values for `PtrParent` and `PtrEnd` here?
No, these are always zero in the object file.


================
Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:2375
+  const SmallVectorImpl<InsnRange> &Ranges = Scope.getRanges();
+  if (Ranges.size() != 1 || !getLabelAfterInsn(Ranges.front().second)) {
+    // This lexical block scope does not have a valid address range, or has
----------------
I suppose this works. I was going to try widening the scope to include the discontiguous portion in the middle, so the debugger would incorrectly think some extra variables were in scope in that code.

We should get a test case for this. I think you can do some stuff with noreturn or __builtin_expect to get us to sink the cold code to the bottom of the function.


================
Comment at: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h:131
 
+    std::unordered_map<const DILocalScope*, LexicalBlock> LexicalBlocks;
+
----------------
The same scope can appear multiple times in the same function after inlining:
```
int getval();
void useit(int);
static inline void g(int cond) {
  if (cond) {
    int x = getval();
    useit(x);
  }
}
void f() {
  g(1);
  g(2);
}
```

They key here isn't quite right. This is replicating some of the functionality of the LexicalScopes class.


https://reviews.llvm.org/D42926





More information about the llvm-commits mailing list