Fixed a bug where we report a single type multiple times in namespaces.

Also added a testcase.

<rdar://problem/22786569>

llvm-svn: 274580
This commit is contained in:
Sean Callanan 2016-07-05 22:06:01 +00:00
parent b395d7271d
commit 8ba1654d48
10 changed files with 164 additions and 6 deletions

View File

@ -0,0 +1,19 @@
LEVEL := ../../../make
LD_EXTRAS := -L. -l$(LIB_PREFIX)a -l$(LIB_PREFIX)b
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules
.PHONY:
a.out: lib_a lib_b
lib_%:
$(MAKE) -f $*.mk
hidden_lib_d:
$(MAKE) -C hidden
clean::
$(MAKE) -f a.mk clean
$(MAKE) -f b.mk clean

View File

@ -0,0 +1,57 @@
"""Test that forward declarations don't cause bogus conflicts in namespaced types"""
from __future__ import print_function
import unittest2
import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil
class NamespaceDefinitionsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def test_expr(self):
self.build()
self.common_setup()
self.expect("expression -- Foo::MyClass()", VARIABLES_DISPLAYED_CORRECTLY,
substrs = ['thing = '])
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.source = 'main.cpp'
self.line = line_number(self.source, '// Set breakpoint here')
self.shlib_names = ["a", "b"]
def common_setup(self):
# Run in synchronous mode
self.dbg.SetAsync(False)
# Create a target by the debugger.
target = self.dbg.CreateTarget("a.out")
self.assertTrue(target, VALID_TARGET)
# Break inside the foo function which takes a bar_ptr argument.
lldbutil.run_break_set_by_file_and_line (self, self.source, self.line, num_expected_locations=1, loc_exact=True)
# Register our shared libraries for remote targets so they get automatically uploaded
environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names)
# Now launch the process, and do not stop at entry point.
process = target.LaunchSimple (None, environment, self.get_process_working_directory())
self.assertTrue(process, PROCESS_IS_VALID)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
'stop reason = breakpoint'])
# The breakpoint should have a hit count of 1.
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])

View File

@ -0,0 +1,16 @@
//===-- a.cpp ---------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "foo.h"
class ThingInside {
int a;
};
Foo::MyClass a_class;

View File

@ -0,0 +1,9 @@
LEVEL := ../../../make
DYLIB_NAME := a
DYLIB_CXX_SOURCES := a.cpp
DYLIB_ONLY := YES
CXXFLAGS += -fPIC
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,12 @@
//===-- b.cpp ---------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "foo.h"
Foo::MyClass b_class;

View File

@ -0,0 +1,9 @@
LEVEL := ../../../make
DYLIB_NAME := b
DYLIB_CXX_SOURCES := b.cpp
DYLIB_ONLY := YES
CXXFLAGS += -fPIC
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,18 @@
//===-- foo.h ---------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
class ThingInside;
namespace Foo {
class MyClass {
ThingInside *thing;
public:
MyClass() { }
};
}

View File

@ -0,0 +1,16 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
int
main (int argc, char const *argv[])
{
return 0; // Set breakpoint here
}

View File

@ -743,6 +743,9 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
do
{
if (context.m_found.type)
break;
TypeList types;
SymbolContext null_sc;
const bool exact_match = false;
@ -752,8 +755,6 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
else
m_target->GetImages().FindTypes(null_sc, name, exact_match, 1, searched_symbol_files, types);
bool found_a_type = false;
if (size_t num_types = types.GetSize())
{
for (size_t ti = 0; ti < num_types; ++ti)
@ -785,12 +786,12 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
context.AddTypeDecl(copied_clang_type);
found_a_type = true;
context.m_found.type = true;
break;
}
}
if (!found_a_type)
if (!context.m_found.type)
{
// Try the modules next.
@ -835,13 +836,13 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
context.AddNamedDecl(copied_named_decl);
found_a_type = true;
context.m_found.type = true;
}
}
} while (0);
}
if (!found_a_type)
if (!context.m_found.type)
{
do
{

View File

@ -431,6 +431,7 @@ struct NameSearchContext {
bool function_with_type_info : 1;
bool function : 1;
bool local_vars_nsp : 1;
bool type : 1;
} m_found;
//------------------------------------------------------------------