Răsfoiți Sursa

Global variables lowered to local variables are classified as arg_variables (#2637)

Adam Yang 5 ani în urmă
părinte
comite
cd7ae78e57

+ 10 - 4
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -6243,6 +6243,9 @@ DIGlobalVariable *FindGlobalVariableFor(const DebugInfoFinder &DbgFinder, Global
   return nullptr;
   return nullptr;
 }
 }
 
 
+// Create a fake local variable for the GlobalVariable GV that has just been
+// lowered to local Alloca.
+//
 static
 static
 void PatchDebugInfo(const DebugInfoFinder &DbgFinder, Function *F, GlobalVariable *GV, AllocaInst *AI) {
 void PatchDebugInfo(const DebugInfoFinder &DbgFinder, Function *F, GlobalVariable *GV, AllocaInst *AI) {
   if (!DbgFinder.compile_unit_count())
   if (!DbgFinder.compile_unit_count())
@@ -6263,16 +6266,19 @@ void PatchDebugInfo(const DebugInfoFinder &DbgFinder, Function *F, GlobalVariabl
 
 
   DITypeIdentifierMap EmptyMap;
   DITypeIdentifierMap EmptyMap;
   DIBuilder DIB(*GV->getParent());
   DIBuilder DIB(*GV->getParent());
-  DIScope *ParentScope = DGV->getScope();
-
-  DIScope *Scope = DIB.createLexicalBlock(Subprogram, ParentScope->getFile(), 0, 0);
+  DIScope *Scope = Subprogram;
   DebugLoc Loc = DebugLoc::get(0, 0, Scope);
   DebugLoc Loc = DebugLoc::get(0, 0, Scope);
 
 
   std::string Name = "global.";
   std::string Name = "global.";
   Name += DGV->getName();
   Name += DGV->getName();
+  // Using arg_variable instead of auto_variable because arg variables can use
+  // Subprogram as its scope, so we don't have to make one up for it.
+  llvm::dwarf::Tag Tag = llvm::dwarf::Tag::DW_TAG_arg_variable;
 
 
   DIType *Ty = DGV->getType().resolve(EmptyMap);
   DIType *Ty = DGV->getType().resolve(EmptyMap);
-  DILocalVariable *ConvertedLocalVar = DIB.createLocalVariable(llvm::dwarf::Tag::DW_TAG_auto_variable, Scope, Name, DGV->getFile(), DGV->getLine(), Ty);
+  DILocalVariable *ConvertedLocalVar =
+    DIB.createLocalVariable(Tag, Scope,
+      Name, DGV->getFile(), DGV->getLine(), Ty);
   DIB.insertDeclare(AI, ConvertedLocalVar, DIB.createExpression(ArrayRef<int64_t>()), Loc, AI->getNextNode());
   DIB.insertDeclare(AI, ConvertedLocalVar, DIB.createExpression(ArrayRef<int64_t>()), Loc, AI->getNextNode());
 }
 }
 
 

+ 3 - 3
tools/clang/test/HLSLFileCheck/dxil/debug/global_vec.hlsl

@@ -16,7 +16,7 @@ float4 main(float4 vec : COLOR, int index : INDEX) : SV_Target {
 // Exclude quoted source file (see readme)
 // Exclude quoted source file (see readme)
 // CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
 // CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
 
 
-// CHECK: !DILocalVariable(tag: DW_TAG_auto_variable, name: "global.MyGlobal
-// CHECK: !DILocalVariable(tag: DW_TAG_auto_variable, name: "global.MyGlobal
-// CHECK: !DILocalVariable(tag: DW_TAG_auto_variable, name: "global.MyGlobal
+// CHECK: !DILocalVariable(tag: DW_TAG_arg_variable, name: "global.MyGlobal
+// CHECK: !DILocalVariable(tag: DW_TAG_arg_variable, name: "global.MyGlobal
+// CHECK: !DILocalVariable(tag: DW_TAG_arg_variable, name: "global.MyGlobal
 
 

+ 1 - 1
tools/clang/test/HLSLFileCheck/dxil/debug/gv_od.hlsl

@@ -8,7 +8,7 @@
 // Exclude quoted source file (see readme)
 // Exclude quoted source file (see readme)
 // CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
 // CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
 
 
-// CHECK: !DILocalVariable(tag: DW_TAG_auto_variable, name: "global.gG"
+// CHECK: !DILocalVariable(tag: DW_TAG_arg_variable, name: "global.gG"
 
 
 static bool gG;
 static bool gG;