[PATCH] D123319: Change how we handle auto return types for lambda operator() to be consistent with gcc
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 18 14:20:10 PDT 2022
shafik updated this revision to Diff 423471.
shafik marked 4 inline comments as done.
shafik added a comment.
- Making test more robust
- Adding comments
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123319/new/
https://reviews.llvm.org/D123319
Files:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/no_auto_return_lambda.cpp
Index: clang/test/CodeGenCXX/no_auto_return_lambda.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/no_auto_return_lambda.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+// We emit "auto" for deduced return types for member functions but we should
+// not emitting "auto" for deduced return types for lambdas call function which
+// will be implmented as operator() in a class type. This test will verify that
+// behavior.
+
+__attribute__((used)) int g() {
+ auto f = []() { return 10; };
+ return f();
+}
+
+// g() is not a member function so we should not emit "auto" for the deduced
+// return type.
+//
+// CHECK: !DISubprogram(name: "g",{{.*}}, type: ![[FUN_TYPE:[0-9]+]],{{.*}}
+// CHECK: ![[FUN_TYPE]] = !DISubroutineType(types: ![[TYPE_NODE:[0-9]+]])
+// CHECK-NEXT: ![[TYPE_NODE]] = !{![[INT_TYPE:[0-9]+]]}
+// CHECK-NEXT: ![[INT_TYPE]] = !DIBasicType(name: "int", {{.*}})
+
+// operator() of the local lambda should have the same return type as g()
+//
+// CHECK: distinct !DISubprogram(name: "operator()",{{.*}}, type: ![[FUN_TYPE_LAMBDA:[0-9]+]],{{.*}}
+// CHECK: ![[FUN_TYPE_LAMBDA]] = !DISubroutineType(types: ![[TYPE_NODE_LAMBDA:[0-9]+]])
+// CHECK-NEXT: ![[TYPE_NODE_LAMBDA]] = !{![[INT_TYPE:[0-9]+]], {{.*}}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1678,9 +1678,17 @@
SmallVector<llvm::Metadata *, 16> Elts;
// First element is always return type. For 'void' functions it is NULL.
QualType temp = Func->getReturnType();
- if (temp->getTypeClass() == Type::Auto && decl)
- Elts.push_back(CreateType(cast<AutoType>(temp)));
- else
+ if (temp->getTypeClass() == Type::Auto && decl) {
+ const AutoType *AT = cast<AutoType>(temp);
+
+ // It may be tricky in some cases to link the specification back the lambda
+ // call operator and so we skip emitting "auto" for lambdas. This is
+ // consistent with gcc as well.
+ if (AT->isDeduced() && ThisPtr->getPointeeCXXRecordDecl()->isLambda())
+ Elts.push_back(getOrCreateType(AT->getDeducedType(), Unit));
+ else
+ Elts.push_back(CreateType(AT));
+ } else
Elts.push_back(Args[0]);
// "this" pointer is always first argument.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123319.423471.patch
Type: text/x-patch
Size: 2407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220418/2887b09f/attachment-0001.bin>
More information about the cfe-commits
mailing list