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

2016-12-08 Thread David Gross via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289094: [DebugInfo] Add support for __fp16, float, and 
double constants. (authored by dgross).

Changed prior to commit:
  https://reviews.llvm.org/D27549?vs=80683=80806#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27549

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


Index: cfe/trunk/test/CodeGen/debug-info-static-const-fp.c
===
--- cfe/trunk/test/CodeGen/debug-info-static-const-fp.c
+++ cfe/trunk/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 ()
+
+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)
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/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),


Index: cfe/trunk/test/CodeGen/debug-info-static-const-fp.c
===
--- cfe/trunk/test/CodeGen/debug-info-static-const-fp.c
+++ cfe/trunk/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 ()
+
+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)
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/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, 

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

2016-12-07 Thread Paul Robinson via Phabricator via cfe-commits
probinson accepted this revision.
probinson added a reviewer: probinson.
probinson added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: lib/CodeGen/CGDebugInfo.cpp:3765
+InitExpr =
+
DBuilder.createConstantValueExpression(Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(

dgross wrote:
> probinson wrote:
> > This line exceeds 80 columns.  clang-format is your friend.
> Done.  Is clang-format mentioned in any of the documentation that describes 
> the development process?  I might have missed it (not that that's an excuse 
> for a needless violation of the coding guidelines).
I would have thought the coding guidelines would mention clang-format, but I'm 
not finding it there (or in the stuff about submitting a patch).


https://reviews.llvm.org/D27549



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-12-07 Thread David Gross via Phabricator via cfe-commits
dgross added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:3765
+InitExpr =
+
DBuilder.createConstantValueExpression(Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(

probinson wrote:
> This line exceeds 80 columns.  clang-format is your friend.
Done.  Is clang-format mentioned in any of the documentation that describes the 
development process?  I might have missed it (not that that's an excuse for a 
needless violation of the coding guidelines).



Comment at: test/CodeGen/debug-info-static-const-fp.c:19
+// 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)

probinson wrote:
> Checking for the entire exact line for the variable is a bit fragile.  Really 
> what you want to do is associate the variable with the correct expression, 
> and ignore all the irrelevant details.  Something like this:
> ```
> // CHECK: DIGlobalVariable(name: "hVal", {{.*}} expr: ![[HEXPR:{{[0-9]+}}]]
> // CHECK: ![[HEXPR] = ! DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
> ```
> And similar pairs for the other variables.  I'd use a different FileCheck 
> variable for each case.
> 
Thanks for the suggestion.  I didn't realize FileCheck had variable support.


https://reviews.llvm.org/D27549



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-12-07 Thread David Gross via Phabricator via cfe-commits
dgross updated this revision to Diff 80683.
dgross added a comment.

Incorporate code review feedback.

- Reformat source.
- Make test pattern more general.


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,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 ()
+
+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)
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),


Index: test/CodeGen/debug-info-static-const-fp.c
===
--- /dev/null
+++ 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 ()
+
+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)
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),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-12-07 Thread Paul Robinson via Phabricator via cfe-commits
probinson added subscribers: cfe-commits, probinson.
probinson added a comment.

Hi David!
As this is a Clang patch, you should subscribe cfe-commits rather than 
llvm-commits.  I've done that for you.
See also inline comments.




Comment at: lib/CodeGen/CGDebugInfo.cpp:3765
+InitExpr =
+
DBuilder.createConstantValueExpression(Init.getFloat().bitcastToAPInt().getZExtValue());
   GV.reset(DBuilder.createGlobalVariable(

This line exceeds 80 columns.  clang-format is your friend.



Comment at: test/CodeGen/debug-info-static-const-fp.c:19
+// 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)

Checking for the entire exact line for the variable is a bit fragile.  Really 
what you want to do is associate the variable with the correct expression, and 
ignore all the irrelevant details.  Something like this:
```
// CHECK: DIGlobalVariable(name: "hVal", {{.*}} expr: ![[HEXPR:{{[0-9]+}}]]
// CHECK: ![[HEXPR] = ! DIExpression(DW_OP_constu, 16502, DW_OP_stack_value)
```
And similar pairs for the other variables.  I'd use a different FileCheck 
variable for each case.



https://reviews.llvm.org/D27549



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits