[llvm] r294488 - Fix bitcode upgrade for DIGlobalVariables with a var: field.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 8 09:44:44 PST 2017


Author: adrian
Date: Wed Feb  8 11:44:43 2017
New Revision: 294488

URL: http://llvm.org/viewvc/llvm-project?rev=294488&view=rev
Log:
Fix bitcode upgrade for DIGlobalVariables with a var: field.

This is a follow-up to https://reviews.llvm.org/D29349.  It turns out
that NeedUpgradeToDIGlobalVariableExpression is always necessary when
we encountered a version==0 record because it may always be referenced
via a list of globals in a DICompileUnit. My tests weren't good enough
to catch this though. To trigger this case, we need much older bitcode
produced by LLVM around version 3.7.

<rdar://problem/30404262>

Differential Revision: https://reviews.llvm.org/D29693

Added:
    llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll
    llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll.bc
Modified:
    llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp

Modified: llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp?rev=294488&r1=294487&r2=294488&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp Wed Feb  8 11:44:43 2017
@@ -1437,6 +1437,7 @@ Error MetadataLoader::MetadataLoaderImpl
     } else if (Version == 0) {
       // Upgrade old metadata, which stored a global variable reference or a
       // ConstantInt here.
+      NeedUpgradeToDIGlobalVariableExpression = true;
       Metadata *Expr = getMDOrNull(Record[9]);
       uint32_t AlignInBits = 0;
       if (Record.size() > 11) {
@@ -1467,8 +1468,6 @@ Error MetadataLoader::MetadataLoaderImpl
       DIGlobalVariableExpression *DGVE = nullptr;
       if (Attach || Expr)
         DGVE = DIGlobalVariableExpression::getDistinct(Context, DGV, Expr);
-      else
-        NeedUpgradeToDIGlobalVariableExpression = true;
       if (Attach)
         Attach->addDebugInfo(DGVE);
 

Added: llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll?rev=294488&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll (added)
+++ llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll Wed Feb  8 11:44:43 2017
@@ -0,0 +1,31 @@
+; RUN: llvm-dis -o - %s.bc | FileCheck %s
+
+; CHECK: @g = common global i32 0, align 4, !dbg ![[G:[0-9]+]]
+; CHECK-DAG: ![[G]] = distinct !DIGlobalVariableExpression(var: ![[GVAR:[0-9]+]])
+; CHECK-DAG: distinct !DICompileUnit({{.*}}, globals: ![[GLOBS:[0-9]+]]
+; CHECK-DAG: ![[GLOBS]] = !{![[GEXPR:[0-9]+]]}
+; CHECK-DAG: ![[GEXPR]] = distinct !DIGlobalVariableExpression(var: ![[GVAR]])
+; CHECK-DAG: ![[GVAR]] = !DIGlobalVariable(name: "g",
+
+; Test the bitcode upgrade for DIGlobalVariable -> DIGlobalVariableExpression.
+
+; ModuleID = 'a.c'
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.12.0"
+
+ at g = common global i32 0, align 4
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!6, !7, !8}
+!llvm.ident = !{!9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (clang-stage1-configure-RA_build 241111)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !2, globals: !3, imports: !2)
+!1 = !DIFile(filename: "a.c", directory: "/tmp")
+!2 = !{}
+!3 = !{!4}
+!4 = !DIGlobalVariable(name: "g", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, variable: i32* @g)
+!5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!6 = !{i32 2, !"Dwarf Version", i32 2}
+!7 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = !{i32 1, !"PIC Level", i32 2}
+!9 = !{!"clang version 3.7.0 (clang-stage1-configure-RA_build 241111)"}

Added: llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll.bc?rev=294488&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll.bc (added) and llvm/trunk/test/Bitcode/DIGlobalVariableExpression2.ll.bc Wed Feb  8 11:44:43 2017 differ




More information about the llvm-commits mailing list