summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Gross <dgross@google.com>2016-12-08 20:02:46 +0000
committerDavid Gross <dgross@google.com>2016-12-08 20:02:46 +0000
commit1118d591dc3f2e0499ac2fdd61f934cab895283b (patch)
treed0c2521b4dfbb2173b3fb5a7596f86259e1c547b
parent6c06a6f48a10ab242f64cd9a95942abb87117832 (diff)
downloadbcm5719-llvm-1118d591dc3f2e0499ac2fdd61f934cab895283b.tar.gz
bcm5719-llvm-1118d591dc3f2e0499ac2fdd61f934cab895283b.zip
[DebugInfo] Add support for __fp16, float, and double constants.
Summary: 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). Reviewers: llvm-commits Differential Revision: https://reviews.llvm.org/D27549 llvm-svn: 289094
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp3
-rw-r--r--clang/test/CodeGen/debug-info-static-const-fp.c27
2 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index ec4c6e35840..c51a1d406ff 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3760,6 +3760,9 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
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),
diff --git a/clang/test/CodeGen/debug-info-static-const-fp.c b/clang/test/CodeGen/debug-info-static-const-fp.c
new file mode 100644
index 00000000000..64b63096bda
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-static-const-fp.c
@@ -0,0 +1,27 @@
+// 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: !DIGlobalVariable(name: "hVal", {{.*}}, isLocal: true, isDefinition: true, expr: ![[HEXPR:[0-9]+]]
+// CHECK: ![[HEXPR]] = !DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "fVal", {{.*}}, isLocal: true, isDefinition: true, expr: ![[FEXPR:[0-9]+]]
+// CHECK: ![[FEXPR]] = !DIExpression(DW_OP_constu, 3238681178, DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "dVal", {{.*}}, isLocal: true, isDefinition: true, expr: ![[DEXPR:[0-9]+]]
+// CHECK: ![[DEXPR]] = !DIExpression(DW_OP_constu, 4658387303597904457, DW_OP_stack_value)
+
+// CHECK: !DIGlobalVariable(name: "ldVal", {{.*}}, isLocal: true, isDefinition: true)
OpenPOWER on IntegriCloud