[Lldb-commits] [PATCH] D134661: [lldb][TypeSystemClang] Honor DW_AT_rvalue_reference when creating C++ FunctionPrototypes

2022-09-27 Thread Michael Buch via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Michael137 marked an inline comment as done.
Closed by commit rG60eb06be6d23: [lldb][TypeSystemClang] Honor 
DW_AT_rvalue_reference when creating C++… (authored by Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134661

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
  lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
  lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp

Index: lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp
@@ -0,0 +1,19 @@
+#include 
+#include 
+
+struct Foo {
+  uint32_t func() const & { return 0; }
+  int64_t func() const && { return 1; }
+  uint32_t func() & { return 2; }
+  int64_t func() && { return 3; }
+};
+
+int main() {
+  Foo foo;
+  const Foo const_foo;
+  auto res = foo.func() + const_foo.func() + Foo{}.func() +
+ static_cast(Foo{}).func();
+
+  std::puts("Break here");
+  return res;
+}
Index: lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
@@ -0,0 +1,39 @@
+"""
+Tests that C++ expression evaluation can
+disambiguate between rvalue and lvalue
+reference-qualified functions.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+def test(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "Break here", lldb.SBFileSpec("main.cpp"))
+
+# const lvalue
+self.expect_expr("const_foo.func()", result_type="uint32_t", result_value="0")
+
+# const rvalue
+self.expect_expr("static_cast(Foo{}).func()",
+ result_type="int64_t", result_value="1")
+
+# non-const lvalue
+self.expect_expr("foo.func()", result_type="uint32_t", result_value="2")
+
+# non-const rvalue
+self.expect_expr("Foo{}.func()", result_type="int64_t", result_value="3")
+
+self.filecheck("target modules dump ast", __file__)
+# CHECK:  |-CXXMethodDecl {{.*}} func 'uint32_t () const &'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'int64_t () const &&'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'uint32_t () &'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: `-CXXMethodDecl {{.*}} func 'int64_t () &&'
+# CHECK-NEXT:   `-AsmLabelAttr {{.*}}
Index: lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -23,6 +23,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/TemplateBase.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -398,10 +399,11 @@
   llvm::StringRef name, const CompilerType _Type,
   clang::StorageClass storage, bool is_inline);
 
-  CompilerType CreateFunctionType(const CompilerType _type,
-  const CompilerType *args, unsigned num_args,
-  bool is_variadic, unsigned type_quals,
-  clang::CallingConv cc = clang::CC_C);
+  CompilerType
+  CreateFunctionType(const CompilerType _type, const CompilerType *args,
+ unsigned num_args, bool is_variadic, unsigned type_quals,
+ clang::CallingConv cc = clang::CC_C,
+ clang::RefQualifierKind ref_qual = clang::RQ_None);
 
   clang::ParmVarDecl *
   CreateParameterDeclaration(clang::DeclContext *decl_ctx,
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ 

[Lldb-commits] [PATCH] D134661: [lldb][TypeSystemClang] Honor DW_AT_rvalue_reference when creating C++ FunctionPrototypes

2022-09-27 Thread Michael Buch via Phabricator via lldb-commits
Michael137 marked an inline comment as done.
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:41
 #include "llvm/Demangle/Demangle.h"
 
 #include "clang/AST/CXXInheritance.h"

labath wrote:
> I guess the `clang/AST/Type.h` include should be grouped with the other clang 
> includes. I'd recommend deleting this empty line and letting clang-format 
> sort the includes for you.
Thanks, done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134661

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


[Lldb-commits] [PATCH] D134661: [lldb][TypeSystemClang] Honor DW_AT_rvalue_reference when creating C++ FunctionPrototypes

2022-09-27 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 463268.
Michael137 added a comment.

- Fix includes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134661

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
  lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
  lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp

Index: lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp
@@ -0,0 +1,19 @@
+#include 
+#include 
+
+struct Foo {
+  uint32_t func() const & { return 0; }
+  int64_t func() const && { return 1; }
+  uint32_t func() & { return 2; }
+  int64_t func() && { return 3; }
+};
+
+int main() {
+  Foo foo;
+  const Foo const_foo;
+  auto res = foo.func() + const_foo.func() + Foo{}.func() +
+ static_cast(Foo{}).func();
+
+  std::puts("Break here");
+  return res;
+}
Index: lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
@@ -0,0 +1,39 @@
+"""
+Tests that C++ expression evaluation can
+disambiguate between rvalue and lvalue
+reference-qualified functions.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+def test(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "Break here", lldb.SBFileSpec("main.cpp"))
+
+# const lvalue
+self.expect_expr("const_foo.func()", result_type="uint32_t", result_value="0")
+
+# const rvalue
+self.expect_expr("static_cast(Foo{}).func()",
+ result_type="int64_t", result_value="1")
+
+# non-const lvalue
+self.expect_expr("foo.func()", result_type="uint32_t", result_value="2")
+
+# non-const rvalue
+self.expect_expr("Foo{}.func()", result_type="int64_t", result_value="3")
+
+self.filecheck("target modules dump ast", __file__)
+# CHECK:  |-CXXMethodDecl {{.*}} func 'uint32_t () const &'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'int64_t () const &&'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'uint32_t () &'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: `-CXXMethodDecl {{.*}} func 'int64_t () &&'
+# CHECK-NEXT:   `-AsmLabelAttr {{.*}}
Index: lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -23,6 +23,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/TemplateBase.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -398,10 +399,11 @@
   llvm::StringRef name, const CompilerType _Type,
   clang::StorageClass storage, bool is_inline);
 
-  CompilerType CreateFunctionType(const CompilerType _type,
-  const CompilerType *args, unsigned num_args,
-  bool is_variadic, unsigned type_quals,
-  clang::CallingConv cc = clang::CC_C);
+  CompilerType
+  CreateFunctionType(const CompilerType _type, const CompilerType *args,
+ unsigned num_args, bool is_variadic, unsigned type_quals,
+ clang::CallingConv cc = clang::CC_C,
+ clang::RefQualifierKind ref_qual = clang::RQ_None);
 
   clang::ParmVarDecl *
   CreateParameterDeclaration(clang::DeclContext *decl_ctx,
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2168,11 +2168,10 @@
   return func_decl;
 }
 
-CompilerType
-TypeSystemClang::CreateFunctionType(const CompilerType _type,
-

[Lldb-commits] [PATCH] D134661: [lldb][TypeSystemClang] Honor DW_AT_rvalue_reference when creating C++ FunctionPrototypes

2022-09-27 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a subscriber: zequanwu.
labath added a comment.
This revision is now accepted and ready to land.

Looks straight forward enough. Tagging @zequanwu, as he might want to do 
something similar for PDB.




Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:41
 #include "llvm/Demangle/Demangle.h"
 
 #include "clang/AST/CXXInheritance.h"

I guess the `clang/AST/Type.h` include should be grouped with the other clang 
includes. I'd recommend deleting this empty line and letting clang-format sort 
the includes for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134661

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


[Lldb-commits] [PATCH] D134661: [lldb][TypeSystemClang] Honor DW_AT_rvalue_reference when creating C++ FunctionPrototypes

2022-09-26 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, labath.
Herald added a reviewer: shafik.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Currently funciton lookup in the expression evaluator
fails to disambiguate member functions the are overloaded
on lvalue/rvalue reference-qualifiers. This happens because
we unconditionally set a `FunctionPrototype`s
`ExtProtoInfo::RefQualifier` to `RQ_None`. We lose
the ref-qualifiers in the synthesized AST and `clang::Sema`
fails to pick a correct overload candidate.

DWARF emits information about a function's ref-qualifiers
in the form of a boolean `DW_AT_rvalue_reference` (for rvalues)
and `DW_AT_reference` (for lvalues).

This patch sets the `FunctionPrototype::ExtProtoInfo::RefQualifier`
based on the DWARF attributes above.

**Testing**

- Added API test

llvm/llvm-project issue #57866


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134661

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
  lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
  lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp

Index: lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/main.cpp
@@ -0,0 +1,19 @@
+#include 
+#include 
+
+struct Foo {
+  uint32_t func() const & { return 0; }
+  int64_t func() const && { return 1; }
+  uint32_t func() & { return 2; }
+  int64_t func() && { return 3; }
+};
+
+int main() {
+  Foo foo;
+  const Foo const_foo;
+  auto res = foo.func() + const_foo.func() + Foo{}.func() +
+ static_cast(Foo{}).func();
+
+  std::puts("Break here");
+  return res;
+}
Index: lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionQualifiers.py
@@ -0,0 +1,39 @@
+"""
+Tests that C++ expression evaluation can
+disambiguate between rvalue and lvalue
+reference-qualified functions.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+def test(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "Break here", lldb.SBFileSpec("main.cpp"))
+
+# const lvalue
+self.expect_expr("const_foo.func()", result_type="uint32_t", result_value="0")
+
+# const rvalue
+self.expect_expr("static_cast(Foo{}).func()",
+ result_type="int64_t", result_value="1")
+
+# non-const lvalue
+self.expect_expr("foo.func()", result_type="uint32_t", result_value="2")
+
+# non-const rvalue
+self.expect_expr("Foo{}.func()", result_type="int64_t", result_value="3")
+
+self.filecheck("target modules dump ast", __file__)
+# CHECK:  |-CXXMethodDecl {{.*}} func 'uint32_t () const &'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'int64_t () const &&'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'uint32_t () &'
+# CHECK-NEXT: | `-AsmLabelAttr {{.*}}
+# CHECK-NEXT: `-CXXMethodDecl {{.*}} func 'int64_t () &&'
+# CHECK-NEXT:   `-AsmLabelAttr {{.*}}
Index: lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/function-ref-qualifiers/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -23,6 +23,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/TemplateBase.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
@@ -398,10 +399,11 @@
   llvm::StringRef name, const CompilerType _Type,
   clang::StorageClass storage, bool is_inline);
 
-  CompilerType CreateFunctionType(const CompilerType _type,
-  const CompilerType *args, unsigned num_args,
-  bool is_variadic, unsigned type_quals,
-  clang::CallingConv cc = clang::CC_C);
+