summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/lang/cpp/template-function/main.cpp
diff options
context:
space:
mode:
authorFrederic Riss <friss@apple.com>2019-04-24 21:04:23 +0000
committerFrederic Riss <friss@apple.com>2019-04-24 21:04:23 +0000
commit265df39a80dae1cc0eb6080b7e6bbf863512b7f7 (patch)
tree685e17018f6441bd5faf5052df6640a39fc35731 /lldb/packages/Python/lldbsuite/test/lang/cpp/template-function/main.cpp
parent9d287358a8ce1bb5ca981403b4d9f7436d209e1b (diff)
downloadbcm5719-llvm-265df39a80dae1cc0eb6080b7e6bbf863512b7f7.tar.gz
bcm5719-llvm-265df39a80dae1cc0eb6080b7e6bbf863512b7f7.zip
Fix infinite recursion when calling C++ template functions
Summary: When we encounter a templated function in the debug information, we were creating an AST that looked like this: FunctionTemplateDecl 0x12980ab90 <<invalid sloc>> <invalid sloc> foo<int> |-TemplateTypeParmDecl 0x12980aad0 <<invalid sloc>> <invalid sloc> class depth 0 index 0 T |-FunctionDecl 0x12980aa30 <<invalid sloc>> <invalid sloc> foo<int> 'int (int)' extern | |-TemplateArgument type 'int' | `-ParmVarDecl 0x12980a998 <<invalid sloc>> <invalid sloc> t1 'int' `-FunctionDecl 0x12980aa30 <<invalid sloc>> <invalid sloc> foo<int> 'int (int)' extern |-TemplateArgument type 'int' `-ParmVarDecl 0x12980a998 <<invalid sloc>> <invalid sloc> t1 'int' Note that the FunctionTemplateDecl has 2 children which are identical (as in have the same address). This is not what Clang is doing: FunctionTemplateDecl 0x7f89d206c6f8 </tmp/template.cpp:1:1, line:4:1> line:2:5 foo |-TemplateTypeParmDecl 0x7f89d206c4a8 <line:1:10, col:19> col:19 referenced typename depth 0 index 0 T |-FunctionDecl 0x7f89d206c660 <line:2:1, line:4:1> line:2:5 foo 'int (T)' | `-ParmVarDecl 0x7f89d206c570 <col:9, col:11> col:11 t1 'T' `-FunctionDecl 0x7f89d206cb60 <line:2:1, line:4:1> line:2:5 used foo 'int (int)' |-TemplateArgument type 'int' `-ParmVarDecl 0x7f89d206ca68 <col:9, col:11> col:11 t1 'int':'int' The 2 chidlren are different and actually repesent different things: the first one is the unspecialized version and the second one is specialized. (Just looking at the names shows another major difference which is that we create the parent with a name of "foo<int>" when it should be just "foo".) The fact that we have those 2 identical children confuses the ClangImporter and generates an infinite recursion (reported in https://llvm.org/pr41473). We cannot create the unspecialized version as the debug information doesn't contain a mapping from the template parameters to their use in the prototype. This patch just creates 2 different FunctionDecls for those 2 children of the FunctionTemplateDecl. This avoids the infinite recursion and allows us to call functions. As the XFAILs in the added test show, we've still got issues in our handling of templates. I believe they are mostly centered on the fact that we create do not register "foo" as a template, but "foo<int>". This is a bigger change that will need changes to the debug information generation. I believe this change makes sense on its own. Reviewers: shafik, clayborg, jingham Subscribers: aprantl, javed.absar, kristof.beyls, lldb-commits Differential Revision: https://reviews.llvm.org/D61044 llvm-svn: 359140
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lang/cpp/template-function/main.cpp')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lang/cpp/template-function/main.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/template-function/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/template-function/main.cpp
new file mode 100644
index 00000000000..035e6450cd3
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/template-function/main.cpp
@@ -0,0 +1,16 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+template<typename T>
+int foo(T t1) {
+ return int(t1);
+}
+
+int main() {
+ return foo(42);
+}
OpenPOWER on IntegriCloud