diff options
author | Shafik Yaghmour <syaghmour@apple.com> | 2019-07-17 20:16:13 +0000 |
---|---|---|
committer | Shafik Yaghmour <syaghmour@apple.com> | 2019-07-17 20:16:13 +0000 |
commit | a0858e2f20c84df1be9d0add9b726996bbe395a4 (patch) | |
tree | 56e85da764961f3b7bb44f7a2ff18c1a1783fa85 /lldb/packages/Python/lldbsuite/test | |
parent | c2cd84bcfbd68e1368874a373744e4c978f2a762 (diff) | |
download | bcm5719-llvm-a0858e2f20c84df1be9d0add9b726996bbe395a4.tar.gz bcm5719-llvm-a0858e2f20c84df1be9d0add9b726996bbe395a4.zip |
Fix CreateFunctionTemplateSpecialization to prevent dangling poiner to stack memory
In ClangASTContext::CreateFunctionTemplateSpecializationInfo a TemplateArgumentList is allocated on the stack but is treated as if it is persistent in subsequent calls. When we exit the function func_decl will still point to the stack allocated memory. We will use TemplateArgumentList::CreateCopy instead which will allocate memory out of the DeclContext.
Differential Revision: https://reviews.llvm.org/D64777
llvm-svn: 366365
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
3 files changed, 39 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/Makefile b/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/Makefile new file mode 100644 index 00000000000..8a7102e347a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py b/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py new file mode 100644 index 00000000000..bd5bc0ec72a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/TestFunctionTemplateSpecializationTempArgs.py @@ -0,0 +1,17 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestFunctionTemplateSpecializationTempArgs(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_function_template_specialization_temp_args(self): + self.build() + + (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp", False)) + + self.expect("expr p0", + substrs=['(VType) $0 = {}']) diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/main.cpp b/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/main.cpp new file mode 100644 index 00000000000..6d01288259a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/expression_command/function_template_specialization_temp_args/main.cpp @@ -0,0 +1,17 @@ +template <typename T> struct M {}; + +template <typename T> void f(T &t); + +template <> void f<int>(int &t) { + typedef M<int> VType; + + VType p0; // break here +} + +int main() { + int x; + + f(x); + + return 0; +} |