[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-20 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan marked 4 inline comments as done.
jackoalan added a comment.

Thank you @teemperor, your comments and changes in D81471 
 are very informative. I didn't realise DWARF 
had similar issues with static const members.

Curiously, I am able to resolve direct variable expressions without your 
`ASTResultSynthesizer` changes. I'm guessing this is due to differences in the 
MS linking convention for the IR module.

If you're interested, here are lldb.expr logs comparing member evaluation with 
and without the synthesizer change:
without: https://gist.github.com/jackoalan/f70f223c5e9ec25d6c8e3a5e09940a71
with: https://gist.github.com/jackoalan/e33c878c545c5b270e6f3da44ef57320

Your changes are definitely preferred. The IR execution takes a much more 
roundabout approach originally, and the change noticeably speeds up evaluation.




Comment at: lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp:27
+  static constexpr float ClassStaticConstexprFloat = 9.f;
+  static constexpr double ClassStaticConstexprDouble = 10.0;
 

teemperor wrote:
> You might want to also add some static const (not `constexpr`) integer and 
> enum members to this test.
> 
> Also I'm curious what happens if you put a `long double` as a member? From 
> what I can see the expected behavior is that PDB will not emit that as a 
> constant (as the current code asserts if it encounters `long double` 
> anywhere).
`long double` is aliased to `double` according to MS docs. The constant can be 
extracted in the same manner.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160



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


[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-20 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan updated this revision to Diff 272287.
jackoalan added a comment.

Review changes from @teemperor.

Base on `TypeSystemClang::SetIntegerInitializerForVariable` from D81471 
, and add associated 
`TypeSystemClang::SetFloatingInitializerForVariable`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  llvm/include/llvm/DebugInfo/PDB/PDBTypes.h

Index: llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
===
--- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
+++ llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
 
+#include "llvm/ADT/APFloat.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
@@ -464,6 +465,88 @@
 char *String;
   } Value;
 
+  bool isIntegralType() const {
+switch (Type) {
+case Bool:
+case Int8:
+case Int16:
+case Int32:
+case Int64:
+case UInt8:
+case UInt16:
+case UInt32:
+case UInt64:
+  return true;
+default:
+  return false;
+}
+  }
+
+#define VARIANT_WIDTH(Enum, NumBits)   \
+  case PDB_VariantType::Enum:  \
+return NumBits;
+
+  unsigned getBitWidth() const {
+switch (Type) {
+  VARIANT_WIDTH(Bool, 1u)
+  VARIANT_WIDTH(Int8, 8u)
+  VARIANT_WIDTH(Int16, 16u)
+  VARIANT_WIDTH(Int32, 32u)
+  VARIANT_WIDTH(Int64, 64u)
+  VARIANT_WIDTH(Single, 32u)
+  VARIANT_WIDTH(Double, 64u)
+  VARIANT_WIDTH(UInt8, 8u)
+  VARIANT_WIDTH(UInt16, 16u)
+  VARIANT_WIDTH(UInt32, 32u)
+  VARIANT_WIDTH(UInt64, 64u)
+default:
+  assert(false && "Variant::toAPSInt called on non-numeric type");
+  return 0u;
+}
+  }
+
+#undef VARIANT_WIDTH
+
+#define VARIANT_APSINT(Enum, NumBits, IsUnsigned)  \
+  case PDB_VariantType::Enum:  \
+return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
+
+  APSInt toAPSInt() const {
+switch (Type) {
+  VARIANT_APSINT(Bool, 1u, true)
+  VARIANT_APSINT(Int8, 8u, false)
+  VARIANT_APSINT(Int16, 16u, false)
+  VARIANT_APSINT(Int32, 32u, false)
+  VARIANT_APSINT(Int64, 64u, false)
+  VARIANT_APSINT(UInt8, 8u, true)
+  VARIANT_APSINT(UInt16, 16u, true)
+  VARIANT_APSINT(UInt32, 32u, true)
+  VARIANT_APSINT(UInt64, 64u, true)
+default:
+  assert(false && "Variant::toAPSInt called on non-integral type");
+  return APSInt();
+}
+  }
+
+#undef VARIANT_APSINT
+
+  APFloat toAPFloat() const {
+// Float constants may be tagged as integers.
+switch (Type) {
+case PDB_VariantType::Single:
+case PDB_VariantType::UInt32:
+case PDB_VariantType::Int32:
+  return APFloat(Value.Single);
+case PDB_VariantType::Double:
+case PDB_VariantType::UInt64:
+case PDB_VariantType::Int64:
+  return APFloat(Value.Double);
+default:
+  assert(false && "Variant::toAPFloat called on non-floating-point type");
+  return APFloat::getZero(APFloat::IEEEsingle());
+}
+  }
+
 #define VARIANT_EQUAL_CASE(Enum)   \
   case PDB_VariantType::Enum:  \
 return Value.Enum == Other.Value.Enum;
Index: lldb/test/Shell/SymbolFile/PDB/ast-restore.test
===
--- lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -46,6 +46,12 @@
 CLASS: class Class : public N0::N1::Base {
 CLASS-DAG: const N0::N1::(anonymous namespace)::Enum m_ce;
 CLASS-DAG: static int ClassStatic;
+CLASS-DAG: static const int ClassStaticConst = 8;
+CLASS-DAG: static const int ClassStaticConstexpr = 9;
+CLASS-DAG: static const float ClassStaticConstexprFloat = 10.F;
+CLASS-DAG: static const double ClassStaticConstexprDouble = 11.;
+CLASS-DAG: static const double ClassStaticConstexprLongDouble = 12.;
+CLASS-DAG: static const N0::N1::(anonymous namespace)::Enum ClassStaticConstEnum = 8;
 CLASS-DAG: N0::N1::Class::Inner m_inner;
 C

[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-21 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan updated this revision to Diff 272288.
jackoalan marked an inline comment as done.
jackoalan added a comment.

Fix ternary to use corresponding float/double overloaded constructors of APFloat


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  llvm/include/llvm/DebugInfo/PDB/PDBTypes.h

Index: llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
===
--- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
+++ llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
 
+#include "llvm/ADT/APFloat.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
@@ -464,6 +465,88 @@
 char *String;
   } Value;
 
+  bool isIntegralType() const {
+switch (Type) {
+case Bool:
+case Int8:
+case Int16:
+case Int32:
+case Int64:
+case UInt8:
+case UInt16:
+case UInt32:
+case UInt64:
+  return true;
+default:
+  return false;
+}
+  }
+
+#define VARIANT_WIDTH(Enum, NumBits)   \
+  case PDB_VariantType::Enum:  \
+return NumBits;
+
+  unsigned getBitWidth() const {
+switch (Type) {
+  VARIANT_WIDTH(Bool, 1u)
+  VARIANT_WIDTH(Int8, 8u)
+  VARIANT_WIDTH(Int16, 16u)
+  VARIANT_WIDTH(Int32, 32u)
+  VARIANT_WIDTH(Int64, 64u)
+  VARIANT_WIDTH(Single, 32u)
+  VARIANT_WIDTH(Double, 64u)
+  VARIANT_WIDTH(UInt8, 8u)
+  VARIANT_WIDTH(UInt16, 16u)
+  VARIANT_WIDTH(UInt32, 32u)
+  VARIANT_WIDTH(UInt64, 64u)
+default:
+  assert(false && "Variant::toAPSInt called on non-numeric type");
+  return 0u;
+}
+  }
+
+#undef VARIANT_WIDTH
+
+#define VARIANT_APSINT(Enum, NumBits, IsUnsigned)  \
+  case PDB_VariantType::Enum:  \
+return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
+
+  APSInt toAPSInt() const {
+switch (Type) {
+  VARIANT_APSINT(Bool, 1u, true)
+  VARIANT_APSINT(Int8, 8u, false)
+  VARIANT_APSINT(Int16, 16u, false)
+  VARIANT_APSINT(Int32, 32u, false)
+  VARIANT_APSINT(Int64, 64u, false)
+  VARIANT_APSINT(UInt8, 8u, true)
+  VARIANT_APSINT(UInt16, 16u, true)
+  VARIANT_APSINT(UInt32, 32u, true)
+  VARIANT_APSINT(UInt64, 64u, true)
+default:
+  assert(false && "Variant::toAPSInt called on non-integral type");
+  return APSInt();
+}
+  }
+
+#undef VARIANT_APSINT
+
+  APFloat toAPFloat() const {
+// Float constants may be tagged as integers.
+switch (Type) {
+case PDB_VariantType::Single:
+case PDB_VariantType::UInt32:
+case PDB_VariantType::Int32:
+  return APFloat(Value.Single);
+case PDB_VariantType::Double:
+case PDB_VariantType::UInt64:
+case PDB_VariantType::Int64:
+  return APFloat(Value.Double);
+default:
+  assert(false && "Variant::toAPFloat called on non-floating-point type");
+  return APFloat::getZero(APFloat::IEEEsingle());
+}
+  }
+
 #define VARIANT_EQUAL_CASE(Enum)   \
   case PDB_VariantType::Enum:  \
 return Value.Enum == Other.Value.Enum;
Index: lldb/test/Shell/SymbolFile/PDB/ast-restore.test
===
--- lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -46,6 +46,12 @@
 CLASS: class Class : public N0::N1::Base {
 CLASS-DAG: const N0::N1::(anonymous namespace)::Enum m_ce;
 CLASS-DAG: static int ClassStatic;
+CLASS-DAG: static const int ClassStaticConst = 8;
+CLASS-DAG: static const int ClassStaticConstexpr = 9;
+CLASS-DAG: static const float ClassStaticConstexprFloat = 10.F;
+CLASS-DAG: static const double ClassStaticConstexprDouble = 11.;
+CLASS-DAG: static const double ClassStaticConstexprLongDouble = 12.;
+CLASS-DAG: static const N0::N1::(anonymous namespace)::Enum ClassStaticConstEnum = 8;
 CLASS-DAG: N0::N1::Class::Inner m_inner;
 CLASS-DAG: {{(inline )?}}Class(N0::N1::(anonymous namespace)::Enum);
 CLASS-DAG

[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-21 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan updated this revision to Diff 272297.
jackoalan added a comment.

Apply formatting fixes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  llvm/include/llvm/DebugInfo/PDB/PDBTypes.h

Index: llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
===
--- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
+++ llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
 
+#include "llvm/ADT/APFloat.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
@@ -464,6 +465,88 @@
 char *String;
   } Value;
 
+  bool isIntegralType() const {
+switch (Type) {
+case Bool:
+case Int8:
+case Int16:
+case Int32:
+case Int64:
+case UInt8:
+case UInt16:
+case UInt32:
+case UInt64:
+  return true;
+default:
+  return false;
+}
+  }
+
+#define VARIANT_WIDTH(Enum, NumBits)   \
+  case PDB_VariantType::Enum:  \
+return NumBits;
+
+  unsigned getBitWidth() const {
+switch (Type) {
+  VARIANT_WIDTH(Bool, 1u)
+  VARIANT_WIDTH(Int8, 8u)
+  VARIANT_WIDTH(Int16, 16u)
+  VARIANT_WIDTH(Int32, 32u)
+  VARIANT_WIDTH(Int64, 64u)
+  VARIANT_WIDTH(Single, 32u)
+  VARIANT_WIDTH(Double, 64u)
+  VARIANT_WIDTH(UInt8, 8u)
+  VARIANT_WIDTH(UInt16, 16u)
+  VARIANT_WIDTH(UInt32, 32u)
+  VARIANT_WIDTH(UInt64, 64u)
+default:
+  assert(false && "Variant::toAPSInt called on non-numeric type");
+  return 0u;
+}
+  }
+
+#undef VARIANT_WIDTH
+
+#define VARIANT_APSINT(Enum, NumBits, IsUnsigned)  \
+  case PDB_VariantType::Enum:  \
+return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
+
+  APSInt toAPSInt() const {
+switch (Type) {
+  VARIANT_APSINT(Bool, 1u, true)
+  VARIANT_APSINT(Int8, 8u, false)
+  VARIANT_APSINT(Int16, 16u, false)
+  VARIANT_APSINT(Int32, 32u, false)
+  VARIANT_APSINT(Int64, 64u, false)
+  VARIANT_APSINT(UInt8, 8u, true)
+  VARIANT_APSINT(UInt16, 16u, true)
+  VARIANT_APSINT(UInt32, 32u, true)
+  VARIANT_APSINT(UInt64, 64u, true)
+default:
+  assert(false && "Variant::toAPSInt called on non-integral type");
+  return APSInt();
+}
+  }
+
+#undef VARIANT_APSINT
+
+  APFloat toAPFloat() const {
+// Float constants may be tagged as integers.
+switch (Type) {
+case PDB_VariantType::Single:
+case PDB_VariantType::UInt32:
+case PDB_VariantType::Int32:
+  return APFloat(Value.Single);
+case PDB_VariantType::Double:
+case PDB_VariantType::UInt64:
+case PDB_VariantType::Int64:
+  return APFloat(Value.Double);
+default:
+  assert(false && "Variant::toAPFloat called on non-floating-point type");
+  return APFloat::getZero(APFloat::IEEEsingle());
+}
+  }
+
 #define VARIANT_EQUAL_CASE(Enum)   \
   case PDB_VariantType::Enum:  \
 return Value.Enum == Other.Value.Enum;
Index: lldb/test/Shell/SymbolFile/PDB/ast-restore.test
===
--- lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -46,6 +46,12 @@
 CLASS: class Class : public N0::N1::Base {
 CLASS-DAG: const N0::N1::(anonymous namespace)::Enum m_ce;
 CLASS-DAG: static int ClassStatic;
+CLASS-DAG: static const int ClassStaticConst = 8;
+CLASS-DAG: static const int ClassStaticConstexpr = 9;
+CLASS-DAG: static const float ClassStaticConstexprFloat = 10.F;
+CLASS-DAG: static const double ClassStaticConstexprDouble = 11.;
+CLASS-DAG: static const double ClassStaticConstexprLongDouble = 12.;
+CLASS-DAG: static const N0::N1::(anonymous namespace)::Enum ClassStaticConstEnum = 8;
 CLASS-DAG: N0::N1::Class::Inner m_inner;
 CLASS-DAG: {{(inline )?}}Class(N0::N1::(anonymous namespace)::Enum);
 CLASS-DAG: static {{(inline )?}}int StaticFunc(const N0::N1::Class &);
Index: lldb/test/Shell/Symbo

[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-22 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan updated this revision to Diff 272597.
jackoalan added a comment.

- Added a test for scoped enums (works as-is but still worth testing).
- Less frivolous use of `auto`
- Made the floating point vars constexpr to maintain validity in clang's 
internals.
- AstRestoreTest CLASS tests run for both DIA and Native. A pure NativePDB test 
that does not depend on MSVC would require extending `s_constant.cpp` 
(`S_CONSTANT` not generated by clang-cl) but I'm not certain how to regenerate 
the listing file with comments (unless that's done by hand). For now, this 
change should only be considered relevant for MSVC.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  llvm/include/llvm/DebugInfo/PDB/PDBTypes.h

Index: llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
===
--- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
+++ llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
 
+#include "llvm/ADT/APFloat.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
@@ -464,6 +465,88 @@
 char *String;
   } Value;
 
+  bool isIntegralType() const {
+switch (Type) {
+case Bool:
+case Int8:
+case Int16:
+case Int32:
+case Int64:
+case UInt8:
+case UInt16:
+case UInt32:
+case UInt64:
+  return true;
+default:
+  return false;
+}
+  }
+
+#define VARIANT_WIDTH(Enum, NumBits)   \
+  case PDB_VariantType::Enum:  \
+return NumBits;
+
+  unsigned getBitWidth() const {
+switch (Type) {
+  VARIANT_WIDTH(Bool, 1u)
+  VARIANT_WIDTH(Int8, 8u)
+  VARIANT_WIDTH(Int16, 16u)
+  VARIANT_WIDTH(Int32, 32u)
+  VARIANT_WIDTH(Int64, 64u)
+  VARIANT_WIDTH(Single, 32u)
+  VARIANT_WIDTH(Double, 64u)
+  VARIANT_WIDTH(UInt8, 8u)
+  VARIANT_WIDTH(UInt16, 16u)
+  VARIANT_WIDTH(UInt32, 32u)
+  VARIANT_WIDTH(UInt64, 64u)
+default:
+  assert(false && "Variant::toAPSInt called on non-numeric type");
+  return 0u;
+}
+  }
+
+#undef VARIANT_WIDTH
+
+#define VARIANT_APSINT(Enum, NumBits, IsUnsigned)  \
+  case PDB_VariantType::Enum:  \
+return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
+
+  APSInt toAPSInt() const {
+switch (Type) {
+  VARIANT_APSINT(Bool, 1u, true)
+  VARIANT_APSINT(Int8, 8u, false)
+  VARIANT_APSINT(Int16, 16u, false)
+  VARIANT_APSINT(Int32, 32u, false)
+  VARIANT_APSINT(Int64, 64u, false)
+  VARIANT_APSINT(UInt8, 8u, true)
+  VARIANT_APSINT(UInt16, 16u, true)
+  VARIANT_APSINT(UInt32, 32u, true)
+  VARIANT_APSINT(UInt64, 64u, true)
+default:
+  assert(false && "Variant::toAPSInt called on non-integral type");
+  return APSInt();
+}
+  }
+
+#undef VARIANT_APSINT
+
+  APFloat toAPFloat() const {
+// Float constants may be tagged as integers.
+switch (Type) {
+case PDB_VariantType::Single:
+case PDB_VariantType::UInt32:
+case PDB_VariantType::Int32:
+  return APFloat(Value.Single);
+case PDB_VariantType::Double:
+case PDB_VariantType::UInt64:
+case PDB_VariantType::Int64:
+  return APFloat(Value.Double);
+default:
+  assert(false && "Variant::toAPFloat called on non-floating-point type");
+  return APFloat::getZero(APFloat::IEEEsingle());
+}
+  }
+
 #define VARIANT_EQUAL_CASE(Enum)   \
   case PDB_VariantType::Enum:  \
 return Value.Enum == Other.Value.Enum;
Index: lldb/test/Shell/SymbolFile/PDB/ast-restore.test
===
--- lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -4,7 +4,8 @@
 RUN: env LLDB_USE_NATIVE_PDB_READER=1 lldb-test symbols -dump-ast %t.exe | FileCheck --check-prefix=ENUM %s
 RUN: lldb-test symbols -dump-ast %t.exe | FileCheck --check-prefix=GLOBAL %s
 RUN: lldb-test symbols -dump-ast %t.exe | FileCheck --check-prefix=BASE %s
-RUN: lldb-test symbols -dump-ast %t.exe | FileCheck --check-prefix=CLASS %s
+RUN: env LLDB_USE_NATIVE

[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-22 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan marked 4 inline comments as done.
jackoalan added inline comments.



Comment at: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:7324-7331
+  // If the variable is an enum type, take the underlying integer type as
+  // the type of the integer literal.
+  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+const EnumDecl *enum_decl = enum_type->getDecl();
+qt = enum_decl->getIntegerType();
+  }
+  var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),

aleksandr.urakov wrote:
> teemperor wrote:
> > aleksandr.urakov wrote:
> > > I'm not sure, can we initialize a member this way if it has a scoped enum 
> > > type?
> > (That code is from D81471 so I think I should answer that)
> > 
> > Well, it works and but it relies on CodeGen/Sema not double-checking that 
> > we get the enum type (and not the underlying int type). I can inject a 
> > CXXStaticCastExpr too and will update D81471. Thanks!
> Ok, thank you!
Added a test just in case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160



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


[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-23 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan added a comment.

Thank you! I do not have commit access, so I will need some help with that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82160/new/

https://reviews.llvm.org/D82160



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


[Lldb-commits] [PATCH] D82160: [lldb][PDB] Constexpr static member values as AST literals

2020-06-23 Thread Jack Andersen via Phabricator via lldb-commits
jackoalan created this revision.
jackoalan added reviewers: aleksandr.urakov, jasonmolenda, zturner.
jackoalan added a project: LLDB.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, lldb-commits, sstefan1.
Herald added a project: LLVM.

When evaluating an expression referencing a constexpr static member variable, 
an error is issued because the PDB does not specify a symbol with an address 
that can be relocated against.

Rather than attempt to resolve the variable's value within the IR execution, 
the values of all constants can be looked up and incorporated into the AST of 
the record type as a literal, mirroring the original compiler AST.

This change applies to DIA and native PDB loaders.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82160

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  llvm/include/llvm/DebugInfo/PDB/PDBTypes.h

Index: llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
===
--- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
+++ llvm/include/llvm/DebugInfo/PDB/PDBTypes.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
 
+#include "llvm/ADT/APFloat.h"
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
@@ -464,6 +465,73 @@
 char *String;
   } Value;
 
+  bool isIntegralType() const {
+switch (Type) {
+case Bool:
+case Int8:
+case Int16:
+case Int32:
+case Int64:
+case UInt8:
+case UInt16:
+case UInt32:
+case UInt64:
+  return true;
+default:
+  return false;
+}
+  }
+
+  bool isFloatingPointType() const {
+switch (Type) {
+case Single:
+case Double:
+  return true;
+default:
+  return false;
+}
+  }
+
+#define VARIANT_APSINT(Enum, NumBits, IsUnsigned)  \
+  case PDB_VariantType::Enum:  \
+return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
+
+  APSInt toAPSInt() const {
+switch (Type) {
+  VARIANT_APSINT(Bool, 1, true)
+  VARIANT_APSINT(Int8, 8, false)
+  VARIANT_APSINT(Int16, 16, false)
+  VARIANT_APSINT(Int32, 32, false)
+  VARIANT_APSINT(Int64, 64, false)
+  VARIANT_APSINT(UInt8, 8, true)
+  VARIANT_APSINT(UInt16, 16, true)
+  VARIANT_APSINT(UInt32, 32, true)
+  VARIANT_APSINT(UInt64, 64, true)
+default:
+  assert(false && "Variant::toAPSInt called on non-integral type");
+  return APSInt();
+}
+  }
+
+#undef VARIANT_APSINT
+
+  APFloat toAPFloat() const {
+// Float constants may be tagged as integers
+switch (Type) {
+case PDB_VariantType::Single:
+case PDB_VariantType::UInt32:
+case PDB_VariantType::Int32:
+  return APFloat(Value.Single);
+case PDB_VariantType::Double:
+case PDB_VariantType::UInt64:
+case PDB_VariantType::Int64:
+  return APFloat(Value.Double);
+default:
+  assert(false && "Variant::toAPFloat called on non-floating-point type");
+  return APFloat::getZero(APFloat::IEEEsingle());
+}
+  }
+
 #define VARIANT_EQUAL_CASE(Enum)   \
   case PDB_VariantType::Enum:  \
 return Value.Enum == Other.Value.Enum;
Index: lldb/test/Shell/SymbolFile/PDB/ast-restore.test
===
--- lldb/test/Shell/SymbolFile/PDB/ast-restore.test
+++ lldb/test/Shell/SymbolFile/PDB/ast-restore.test
@@ -46,6 +46,9 @@
 CLASS: class Class : public N0::N1::Base {
 CLASS-DAG: const N0::N1::(anonymous namespace)::Enum m_ce;
 CLASS-DAG: static int ClassStatic;
+CLASS-DAG: static constexpr int ClassStaticConstexpr = 8;
+CLASS-DAG: static constexpr float ClassStaticConstexprFloat = 9.F;
+CLASS-DAG: static constexpr double ClassStaticConstexprDouble = 10.;
 CLASS-DAG: N0::N1::Class::Inner m_inner;
 CLASS-DAG: {{(inline )?}}Class(N0::N1::(anonymous namespace)::Enum);
 CLASS-DAG: static {{(inline )?}}int StaticFunc(const N0::N1::Class &);
Index: lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
===
--- lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
+++ lldb/test/Shell/SymbolFile/PDB/Inputs/AstRestoreTest.cpp
@@ -22,6 +22,9 @@
   const Enum m_ce