Author: gclayton
Date: Fri Jun 10 15:56:09 2016
New Revision: 272434

URL: http://llvm.org/viewvc/llvm-project?rev=272434&view=rev
Log:
Fixed C++ template integer parameter types to work correctly when the integer 
type is signed.

Prior to this we would display the typename for "TestObj<-1>" as 
"TestObj<4294967295>" when we showed the type. Expression parsing could also 
fail because we would fail to find the mangled name when evaluating expressions.

The issue was we were losing the signed'ness of the template integer parameter 
in DWARFASTParserClang.cpp.

<rdar://problem/25577041>

Added:
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/Makefile
    
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py
    lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp
Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/Makefile
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/Makefile?rev=272434&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/Makefile Fri 
Jun 10 15:56:09 2016
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+CFLAGS_EXTRAS += $(NO_LIMIT_DEBUG_INFO_FLAGS)
+
+include $(LEVEL)/Makefile.rules

Added: 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py?rev=272434&view=auto
==============================================================================
--- 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py
 (added)
+++ 
lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py
 Fri Jun 10 15:56:09 2016
@@ -0,0 +1,62 @@
+"""
+Tests that C++ templates work as expected
+"""
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TemplateIntegerArgsTestCase(TestBase):
+    
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_with_run_command(self):
+        """Test that C++ template classes that have integer parameters work 
correctly.
+           
+           We must reconstruct the types correctly so the template types are 
correct 
+           and display correctly, and also make sure the expression parser 
works and
+           is able the find all needed functions when evaluating expressions"""
+        self.build()
+        
+        # Set debugger into synchronous mode
+        self.dbg.SetAsync(False)
+
+        # Create a target by the debugger.
+        exe = os.path.join(os.getcwd(), "a.out")
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        # Set breakpoints inside and outside methods that take pointers to the 
containing struct.
+        line = line_number('main.cpp', '// Breakpoint 1')
+        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, 
num_expected_locations=1, loc_exact=True)
+
+        arguments = None
+        environment = None 
+
+        # Now launch the process, and do not stop at entry point.
+        process = target.LaunchSimple (arguments, environment, 
self.get_process_working_directory())
+        self.assertTrue(process, PROCESS_IS_VALID)
+ 
+        # Get the thread of the process
+        self.assertTrue(process.GetState() == lldb.eStateStopped, 
PROCESS_STOPPED)
+        thread = lldbutil.get_stopped_thread(process, 
lldb.eStopReasonBreakpoint)
+
+        # Get frame for current thread
+        frame = thread.GetSelectedFrame()
+        
+        testpos = frame.FindVariable('testpos') 
+        self.assertTrue(testpos.IsValid(), 'make sure we find a local 
variabble named "testpos"')
+        self.assertTrue(testpos.GetType().GetName() == 'TestObj<1>')
+        expr_result = frame.EvaluateExpression("testpos.getArg()")
+        self.assertTrue(expr_result.IsValid(), 'got a valid expression result 
from expression "testpos.getArg()"');
+        self.assertTrue(expr_result.GetValue() == "1", "testpos.getArg() == 1")
+        self.assertTrue(expr_result.GetType().GetName() == "int", 
'expr_result.GetType().GetName() == "int"')     
+        
+        testneg = frame.FindVariable('testneg') 
+        self.assertTrue(testneg.IsValid(), 'make sure we find a local 
variabble named "testneg"')
+        self.assertTrue(testneg.GetType().GetName() == 'TestObj<-1>')        
+        
+        expr_result = frame.EvaluateExpression("testneg.getArg()")
+        self.assertTrue(expr_result.IsValid(), 'got a valid expression result 
from expression "testneg.getArg()"');
+        self.assertTrue(expr_result.GetValue() == "-1", "testneg.getArg() == 
-1")
+        self.assertTrue(expr_result.GetType().GetName() == "int", 
'expr_result.GetType().GetName() == "int"')

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp?rev=272434&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp Fri 
Jun 10 15:56:09 2016
@@ -0,0 +1,25 @@
+//===-- main.cpp ------------------------------------------------*- C++ 
-*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+template <int Arg>
+class TestObj
+{
+public:
+  int getArg()
+  {
+    return Arg;
+  }
+};
+
+int main(int argc, char **argv)
+{
+  TestObj<1> testpos;
+  TestObj<-1> testneg;
+  return testpos.getArg() - testneg.getArg(); // Breakpoint 1
+}

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=272434&r1=272433&r2=272434&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Fri Jun 
10 15:56:09 2016
@@ -2053,7 +2053,7 @@ DWARFASTParserClang::ParseTemplateDIE (c
                     {
                         llvm::APInt apint (lldb_type->GetByteSize() * 8, 
uval64, is_signed);
                         template_param_infos.args.push_back(
-                            clang::TemplateArgument(*ast, llvm::APSInt(apint), 
ClangUtil::GetQualType(clang_type)));
+                            clang::TemplateArgument(*ast, llvm::APSInt(apint, 
!is_signed), ClangUtil::GetQualType(clang_type)));
                     }
                     else
                     {


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

Reply via email to