Skip to content

Commit

Permalink
Merged master:48ddf5e182c6 into amd-gfx:4d6e647240ec
Browse files Browse the repository at this point in the history
Local branch amd-gfx 4d6e647 Merged master:75f50e15bf8f into amd-gfx:40142cb34d81
Remote branch master 48ddf5e [lld][WebAssembly] Ensure stub symbols always get address 0
  • Loading branch information
Sw authored and Sw committed Nov 26, 2020
2 parents 4d6e647 + 48ddf5e commit 56092a7
Show file tree
Hide file tree
Showing 27 changed files with 377 additions and 97 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ClangdServer {
bool BackgroundIndex = false;

/// Store refs to main-file symbols in the index.
bool CollectMainFileRefs = false;
bool CollectMainFileRefs = true;

/// If set, use this index to augment code completion results.
SymbolIndex *StaticIndex = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/tool/ClangdMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ opt<bool> CollectMainFileRefs{
"collect-main-file-refs",
cat(Misc),
desc("Store references to main-file-only symbols in the index"),
init(false),
init(ClangdServer::Options().CollectMainFileRefs),
};

#if CLANGD_ENABLE_REMOTE
Expand Down
13 changes: 8 additions & 5 deletions clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
size_t CacheHits = 0;
MemoryShardStorage MSS(Storage, CacheHits);
OverlayCDB CDB(/*Base=*/nullptr);
BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return &MSS; },
/*Opts=*/{});
BackgroundIndex::Options Opts;
Opts.CollectMainFileRefs = true;
BackgroundIndex Idx(
FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts);

tooling::CompileCommand Cmd;
Cmd.Filename = testPath("root/A.cc");
Expand All @@ -201,7 +203,7 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
EXPECT_THAT(runFuzzyFind(Idx, ""),
UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)),
AllOf(Named("A_CC"), NumReferences(0U)),
AllOf(Named("g"), NumReferences(0U)),
AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(),
Not(Defined()), NumReferences(0U))));

Expand All @@ -214,7 +216,7 @@ TEST_F(BackgroundIndexTest, IndexTwoFiles) {
EXPECT_THAT(runFuzzyFind(Idx, ""),
UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)),
AllOf(Named("A_CC"), NumReferences(0U)),
AllOf(Named("g"), NumReferences(0U)),
AllOf(Named("g"), NumReferences(1U)),
AllOf(Named("f_b"), Declared(), Defined(),
NumReferences(1U))));

Expand All @@ -238,7 +240,8 @@ TEST_F(BackgroundIndexTest, MainFileRefs) {
FS.Files[testPath("root/A.cc")] =
"#include \"A.h\"\nstatic void main_sym() { (void)header_sym; }";

// Check the behaviour with CollectMainFileRefs = false (the default).
// Check the behaviour with CollectMainFileRefs = false (the default
// at the SymbolCollector level).
{
llvm::StringMap<std::string> Storage;
size_t CacheHits = 0;
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -8640,6 +8640,8 @@ def err_ambiguous_member_multiple_subobjects : Error<
def err_ambiguous_member_multiple_subobject_types : Error<
"member %0 found in multiple base classes of different types">;
def note_ambiguous_member_found : Note<"member found by ambiguous name lookup">;
def note_ambiguous_member_type_found : Note<
"member type %0 found by ambiguous name lookup">;
def err_ambiguous_reference : Error<"reference to %0 is ambiguous">;
def note_ambiguous_candidate : Note<"candidate found by name lookup is %q0">;
def err_ambiguous_tag_hiding : Error<"a type named %0 is hidden by a "
Expand Down
40 changes: 25 additions & 15 deletions clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2228,11 +2228,10 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,

// Determine whether two sets of members contain the same members, as
// required by C++ [class.member.lookup]p6.
auto HasSameDeclarations = [IDNS,
TemplateNameLookup](DeclContextLookupResult A,
DeclContextLookupResult B) {
auto HasSameDeclarations = [&](DeclContextLookupResult A,
DeclContextLookupResult B) {
using Iterator = DeclContextLookupResult::iterator;
using Result = const Decl *;
using Result = const void *;

auto Next = [&](Iterator &It, Iterator End) -> Result {
while (It != End) {
Expand All @@ -2252,14 +2251,15 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
if (auto *TD = getAsTemplateNameDecl(ND))
ND = TD;

// FIXME: Per C++ [class.member.lookup]p3:
// type declarations (including injected-class-names are replaced by the
// types they designate
// So two different typedef declarations with the same name from two
// different base classes declaring the same type do not introduce an
// ambiguity.
// C++ [class.member.lookup]p3:
// type declarations (including injected-class-names) are replaced by
// the types they designate
if (const TypeDecl *TD = dyn_cast<TypeDecl>(ND->getUnderlyingDecl())) {
QualType T = Context.getTypeDeclType(TD);
return T.getCanonicalType().getAsOpaquePtr();
}

return cast<NamedDecl>(ND->getUnderlyingDecl()->getCanonicalDecl());
return ND->getUnderlyingDecl()->getCanonicalDecl();
}
return nullptr;
};
Expand Down Expand Up @@ -2509,13 +2509,23 @@ void Sema::DiagnoseAmbiguousLookup(LookupResult &Result) {
<< Name << LookupRange;

CXXBasePaths *Paths = Result.getBasePaths();
std::set<Decl *> DeclsPrinted;
std::set<const NamedDecl *> DeclsPrinted;
for (CXXBasePaths::paths_iterator Path = Paths->begin(),
PathEnd = Paths->end();
Path != PathEnd; ++Path) {
Decl *D = Path->Decls.front();
if (DeclsPrinted.insert(D).second)
Diag(D->getLocation(), diag::note_ambiguous_member_found);
const NamedDecl *D = Path->Decls.front();
if (!D->isInIdentifierNamespace(Result.getIdentifierNamespace()))
continue;
if (DeclsPrinted.insert(D).second) {
if (const auto *TD = dyn_cast<TypedefNameDecl>(D->getUnderlyingDecl()))
Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
<< TD->getUnderlyingType();
else if (const auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
<< Context.getTypeDeclType(TD);
else
Diag(D->getLocation(), diag::note_ambiguous_member_found);
}
}
break;
}
Expand Down
16 changes: 10 additions & 6 deletions clang/test/CXX/drs/dr3xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,17 @@ namespace dr305 { // dr305: no
#endif
}

namespace dr306 { // dr306: no
// FIXME: dup 39
// FIXME: This should be accepted.
struct A { struct B {}; }; // expected-note 2{{member}}
struct C { typedef A::B B; }; // expected-note {{member}}
namespace dr306 { // dr306: dup 39
struct A { struct B {}; };
struct C { typedef A::B B; };
struct D : A, A::B, C {};
D::B b; // expected-error {{found in multiple base classes of different types}}
D::B b;

struct X {}; // expected-note {{member type 'dr306::X' found}}
template<typename T> struct Y { typedef T X; }; // expected-note {{member type 'const dr306::X' found}}
template<typename T> struct Z : X, Y<T> {};
Z<X>::X zx;
Z<const X>::X zcx; // expected-error {{member 'X' found in multiple base classes of different types}}
}

// dr307: na
Expand Down
4 changes: 3 additions & 1 deletion clang/test/CXX/temp/temp.res/temp.local/p3.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 -verify %s

template <class T> struct Base { // expected-note 4 {{member found by ambiguous name lookup}}
template <class T> struct Base {
// expected-note@-1 2{{member type 'Base<int>' found by ambiguous name lookup}}
// expected-note@-2 2{{member type 'Base<char>' found by ambiguous name lookup}}
static void f();
};

Expand Down
12 changes: 6 additions & 6 deletions clang/test/SemaCXX/member-name-lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ struct B : A {

enum E2 { enumerator2 };

enum E3 { enumerator3 }; // expected-note 2{{member found by ambiguous name lookup}}
enum E3 { enumerator3 }; // expected-note 2{{member type 'B::E3' found by ambiguous name lookup}}
};

struct C : A {
int c; // expected-note 2{{member found by ambiguous name lookup}}
int d; // expected-note 2{{member found by ambiguous name lookup}}

enum E3 { enumerator3_2 }; // expected-note 2{{member found by ambiguous name lookup}}
enum E3 { enumerator3_2 }; // expected-note 2{{member type 'C::E3' found by ambiguous name lookup}}
};

struct D : B, C {
Expand Down Expand Up @@ -71,14 +71,14 @@ struct B2 : virtual A {

enum E2 { enumerator2 };

enum E3 { enumerator3 }; // expected-note 2 {{member found by ambiguous name lookup}}
enum E3 { enumerator3 }; // expected-note 2 {{member type 'B2::E3' found by ambiguous name lookup}}
};

struct C2 : virtual A {
int c;
int d; // expected-note 2{{member found by ambiguous name lookup}}

enum E3 { enumerator3_2 }; // expected-note 2{{member found by ambiguous name lookup}}
enum E3 { enumerator3_2 }; // expected-note 2{{member type 'C2::E3' found by ambiguous name lookup}}
};

struct D2 : B2, C2 {
Expand Down Expand Up @@ -132,11 +132,11 @@ void G::test_virtual_lookup() {


struct HasMemberType1 {
struct type { }; // expected-note{{member found by ambiguous name lookup}}
struct type { }; // expected-note{{member type 'HasMemberType1::type' found by ambiguous name lookup}}
};

struct HasMemberType2 {
struct type { }; // expected-note{{member found by ambiguous name lookup}}
struct type { }; // expected-note{{member type 'HasMemberType2::type' found by ambiguous name lookup}}
};

struct HasAnotherMemberType : HasMemberType1, HasMemberType2 {
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaTemplate/dependent-base-classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ namespace PR6031 {
namespace Ambig {
template<typename T>
struct Base1 {
typedef int type; // expected-note{{member found by ambiguous name lookup}}
typedef int type; // expected-note{{member type 'int' found by ambiguous name lookup}}
};

struct Base2 {
typedef float type; // expected-note{{member found by ambiguous name lookup}}
typedef float type; // expected-note{{member type 'float' found by ambiguous name lookup}}
};

template<typename T>
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ static_assert(sizeof(B<int>) == sizeof(A<int>::NameFromBase), "");
}

namespace two_types_in_base {
template <typename T> struct A { typedef T NameFromBase; }; // expected-note {{member found by ambiguous name lookup}}
template <typename T> struct B { struct NameFromBase { T m; }; }; // expected-note {{member found by ambiguous name lookup}}
template <typename T> struct A { typedef T NameFromBase; }; // expected-note {{member type 'int' found by ambiguous name lookup}}
template <typename T> struct B { struct NameFromBase { T m; }; }; // expected-note {{member type 'two_types_in_base::B<int>::NameFromBase' found by ambiguous name lookup}}
template <typename T> struct C : A<T>, B<T> {
NameFromBase m; // expected-error {{member 'NameFromBase' found in multiple base classes of different types}} expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
};
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaTemplate/temp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace test0 {

// PR7252
namespace test1 {
namespace A { template<typename T> struct Base { typedef T t; }; } // expected-note 3{{member}}
namespace B { template<typename T> struct Base { typedef T t; }; } // expected-note {{member found}}
namespace A { template<typename T> struct Base { typedef T t; }; } // expected-note {{member type 'test1::A::Base<char>' found}} expected-note 2{{declared here}}
namespace B { template<typename T> struct Base { typedef T t; }; } // expected-note {{member type 'test1::B::Base<int>' found}}

template<typename T> struct Derived : A::Base<char>, B::Base<int> {
typename Derived::Base<float>::t x; // expected-error {{found in multiple base classes of different types}}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaTemplate/typename-specifier-4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ namespace PR6268 {
}

namespace PR6463 {
struct B { typedef int type; }; // expected-note 2{{member found by ambiguous name lookup}}
struct C { typedef int type; }; // expected-note 2{{member found by ambiguous name lookup}}
struct B { typedef int type; }; // expected-note 2{{member type 'int' found by ambiguous name lookup}}
struct C { typedef const int type; }; // expected-note 2{{member type 'const int' found by ambiguous name lookup}}

template<typename T>
struct A : B, C {
Expand Down
2 changes: 1 addition & 1 deletion clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://wg21.link/cwg306">306</a></td>
<td>CD1</td>
<td>Ambiguity by class name injection</td>
<td class="none" align="center">No</td>
<td class="none" align="center">Duplicate of <a href="#39">39</a></td>
</tr>
<tr id="307">
<td><a href="https://wg21.link/cwg307">307</a></td>
Expand Down
2 changes: 1 addition & 1 deletion lld/COFF/InputFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class ImportFile : public InputFile {
const coff_import_header *hdr;
Chunk *location = nullptr;

// We want to eliminate dllimported symbols if no one actually refers them.
// We want to eliminate dllimported symbols if no one actually refers to them.
// These "Live" bits are used to keep track of which import library members
// are actually in use.
//
Expand Down
90 changes: 90 additions & 0 deletions lld/test/wasm/weak-undefined-pic.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Checks handling of undefined weak external functions. When the
# static linker decides they are undefined, check GOT relocations
# resolve to zero (i.e. a global that contains zero.).
#
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: wasm-ld %t.o -o %t1.wasm
# RUN: obj2yaml %t1.wasm | FileCheck %s
#
# With `--unresolved-symbols=ignore-all` the behaviour should be the same
# as the default.>
#
# RUN: wasm-ld --unresolved-symbols=ignore-all %t.o -o %t2.wasm
# RUN: obj2yaml %t2.wasm | FileCheck %s

.globl get_foo_addr
get_foo_addr:
.functype get_foo_addr () -> (i32)
global.get foo@GOT
end_function

.globl _start
_start:
.functype _start () -> ()
call get_foo_addr
end_function

.weak foo
.functype foo () -> (i32)

# Verify that we do not generate dynamnic relocations for the GOT entry.

# CHECK-NOT: __wasm_apply_relocs

# Verify that we do not generate an import for foo

# CHECK-NOT: - Type: IMPORT

# CHECK: - Type: GLOBAL
# CHECK-NEXT: Globals:
# CHECK-NEXT: - Index: 0
# CHECK-NEXT: Type: I32
# CHECK-NEXT: Mutable: true
# CHECK-NEXT: InitExpr:
# CHECK-NEXT: Opcode: I32_CONST
# CHECK-NEXT: Value: 66560
# Global 'undefined_weak:foo' representing the GOT entry for foo
# Unlike other internal GOT entries that need to be mutable this one
# is immutable and not updated by `__wasm_apply_relocs`
# CHECK-NEXT: - Index: 1
# CHECK-NEXT: Type: I32
# CHECK-NEXT: Mutable: false
# CHECK-NEXT: InitExpr:
# CHECK-NEXT: Opcode: I32_CONST
# CHECK-NEXT: Value: 0

# CHECK: - Type: CUSTOM
# CHECK-NEXT: Name: name
# CHECK-NEXT: FunctionNames:
# CHECK-NEXT: - Index: 0
# CHECK-NEXT: Name: 'undefined_weak:foo'
# CHECK-NEXT: - Index: 1
# CHECK-NEXT: Name: get_foo_addr
# CHECK-NEXT: - Index: 2
# CHECK-NEXT: Name: _start
# CHECK-NEXT: GlobalNames:
# CHECK-NEXT: - Index: 0
# CHECK-NEXT: Name: __stack_pointer
# CHECK-NEXT: - Index: 1
# CHECK-NEXT: Name: 'undefined_weak:foo'

# With `-pie` or `-shared` the resolution should is defered to the dynamic
# linker and the function address should be imported as GOT.func.foo.
#
# RUN: wasm-ld --experimental-pic -pie %t.o -o %t3.wasm
# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=IMPORT

# IMPORT: - Type: IMPORT
# IMPORT: - Module: GOT.func
# IMPORT-NEXT: Field: foo
# IMPORT-NEXT: Kind: GLOBAL
# IMPORT-NEXT: GlobalType: I32
# IMPORT-NEXT: GlobalMutable: true

# IMPORT: GlobalNames:
# IMPORT-NEXT: - Index: 0
# IMPORT-NEXT: Name: __memory_base
# IMPORT-NEXT: - Index: 1
# IMPORT-NEXT: Name: __table_base
# IMPORT-NEXT: - Index: 2
# IMPORT-NEXT: Name: foo
2 changes: 1 addition & 1 deletion lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
warn(Twine("symbol exported via --export not found: ") + arg->getValue());
}

if (!config->relocatable) {
if (!config->relocatable && !config->isPic) {
// Add synthetic dummies for weak undefined functions. Must happen
// after LTO otherwise functions may not yet have signatures.
symtab->handleWeakUndefines();
Expand Down
2 changes: 1 addition & 1 deletion lld/wasm/MarkLive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void MarkLive::mark() {
reloc.Type == R_WASM_TABLE_INDEX_I32 ||
reloc.Type == R_WASM_TABLE_INDEX_I64) {
auto *funcSym = cast<FunctionSymbol>(sym);
if (funcSym->hasTableIndex() && funcSym->getTableIndex() == 0)
if (funcSym->isStub)
continue;
}

Expand Down
Loading

0 comments on commit 56092a7

Please sign in to comment.