[llvm] r311217 - Filter out non-constant DIGlobalVariableExpressions reachable via the CU

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 18:20:41 PDT 2017


> On Aug 22, 2017, at 5:51 PM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Fri., 18 Aug. 2017, 6:16 pm Adrian Prantl via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
> Author: adrian
> Date: Fri Aug 18 18:15:06 2017
> New Revision: 311217
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=311217&view=rev <http://llvm.org/viewvc/llvm-project?rev=311217&view=rev>
> Log:
> Filter out non-constant DIGlobalVariableExpressions reachable via the CU
> 
> They won't affect the DWARF output, but they will mess with the
> sorting of the fragments. This fixes the crash reported in PR34159.
> 
> https://bugs.llvm.org/show_bug.cgi?id=34159 <https://bugs.llvm.org/show_bug.cgi?id=34159>
> 
> Modified:
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>     llvm/trunk/test/DebugInfo/X86/split-global.ll
> 
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=311217&r1=311216&r2=311217&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=311217&r1=311216&r2=311217&view=diff>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Fri Aug 18 18:15:06 2017
> @@ -592,8 +592,15 @@ void DwarfDebug::beginModule() {
>      DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(CUNode);
> 
>      // Global Variables.
> -    for (auto *GVE : CUNode->getGlobalVariables())
> -      GVMap[GVE->getVariable()].push_back({nullptr, GVE->getExpression()});
> +    for (auto *GVE : CUNode->getGlobalVariables()) {
> +      // Don't bother adding DIGlobalVariableExpressions listed in the CU if we
> +      // already know about the variable and it isn't adding a constant
> +      // expression.
> +      auto &GVMapEntry = GVMap[GVE->getVariable()];
> +      auto *Expr = GVE->getExpression();
> +      if (!GVMapEntry.size() || (Expr && Expr->isConstant()))
> +        GVMapEntry.push_back({nullptr, Expr});
> +    }
>      DenseSet<DIGlobalVariable *> Processed;
>      for (auto *GVE : CUNode->getGlobalVariables()) {
>        DIGlobalVariable *GV = GVE->getVariable();
> 
> Modified: llvm/trunk/test/DebugInfo/X86/split-global.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/split-global.ll?rev=311217&r1=311216&r2=311217&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/split-global.ll?rev=311217&r1=311216&r2=311217&view=diff>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/X86/split-global.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/split-global.ll Fri Aug 18 18:15:06 2017
> @@ -39,7 +39,7 @@ target triple = "x86_64-apple-macosx10.1
>  !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4)
>  !2 = !DIFile(filename: "g.c", directory: "/")
>  !3 = !{}
> -!4 = !{!12, !13, !14, !15, !17, !18}
> +!4 = !{!12, !13, !14, !15, !17, !18, !20}
>  !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !2, line: 1, size: 64, elements: !6)
>  !6 = !{!7, !9}
>  !7 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !5, file: !2, line: 1, baseType: !8, size: 32)
> @@ -58,3 +58,4 @@ target triple = "x86_64-apple-macosx10.1
>  !18 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression(DW_OP_constu, 2,
>                                               DW_OP_stack_value, DW_OP_LLVM_fragment, 32, 32))
>  !19 = distinct !DIGlobalVariable(name: "full_const", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true)
> +!20 = !DIGlobalVariableExpression(var: !0)
> 
> Should this be/is this valid ir?


I think it is reasonable to support "dangling" global variables in the CU list to represent globals that have been optimized away. Not sure whether we should disallow having them there while they are still attached by global symbols.

--adrian
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170822/62840325/attachment-0001.html>


More information about the llvm-commits mailing list