[PATCH] D27549: [DebugInfo] Add support for __fp16, float, and double constants.

David Gross via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 15:07:36 PST 2016


dgross created this revision.
dgross added a reviewer: llvm-commits.

Partial fix for PR26619.

Prior to this change, a DIGlobalVariable corresponding to a static
const was marked with an expression corresponding to its constant
value only if it is of integral type.  With this change, we now do the
same if it is of __fp16, float, or double type (that is,
floating-point types that do not exceed 64 bits in size, and hence are
supported easily by the existing LLVM machinery for creating constant
expressions in debug info).


https://reviews.llvm.org/D27549

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-static-const-fp.c


Index: test/CodeGen/debug-info-static-const-fp.c
===================================================================
--- /dev/null
+++ test/CodeGen/debug-info-static-const-fp.c
@@ -0,0 +1,24 @@
+// RUN: %clang -emit-llvm -O0 -S -g %s -o - | FileCheck %s
+
+// Per PR26619, check that for referenced static const of floating-point type,
+// we emit its constant value in debug info.  NOTE that PR26619 is not yet fixed for long double.
+
+static const __fp16 hVal = 29/13.0f;            //    2.2307692307692307692     (2.23046875)
+
+static const float fVal = -147/17.0f;           //   -8.6470588235294117647     (-8.64705849)
+
+static const double dVal = 19637/7.0;           // 2805.2857142857142857        (2805.2857142857142)
+
+static const long double ldVal = 3/1234567.0L;  //    2.4300017739012949479e-06 (<optimized out>)
+
+int main() {
+  return hVal + fVal + dVal + ldVal;
+}
+
+// CHECK: !4 = distinct !DIGlobalVariable(name: "hVal", scope: !0, file: !1, line: 6, type: !5, isLocal: true, isDefinition: true, expr: !7)
+// CHECK: !7 = !DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
+// CHECK: !8 = distinct !DIGlobalVariable(name: "fVal", scope: !0, file: !1, line: 8, type: !9, isLocal: true, isDefinition: true, expr: !11)
+// CHECK: !11 = !DIExpression(DW_OP_constu, 3238681178, DW_OP_stack_value)
+// CHECK: !12 = distinct !DIGlobalVariable(name: "dVal", scope: !0, file: !1, line: 10, type: !13, isLocal: true, isDefinition: true, expr: !15)
+// CHECK: !15 = !DIExpression(DW_OP_constu, 4658387303597904457, DW_OP_stack_value)
+// CHECK: !16 = distinct !DIGlobalVariable(name: "ldVal", scope: !0, file: !1, line: 12, type: !17, isLocal: true, isDefinition: true)
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3760,6 +3760,9 @@
   if (Init.isInt())
     InitExpr =
         DBuilder.createConstantValueExpression(Init.getInt().getExtValue());
+  else if (Init.isFloat() && CGM.getContext().getTypeSize(VD->getType()) <= 64)
+    InitExpr =
+        DBuilder.createConstantValueExpression(Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(
       DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
       true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27549.80674.patch
Type: text/x-patch
Size: 2387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161207/d88cd953/attachment.bin>


More information about the llvm-commits mailing list