Skip to content

Commit

Permalink
Merged master:9c31e12609e1 into amd-gfx:d382ea182aab
Browse files Browse the repository at this point in the history
Local branch amd-gfx d382ea1 Merged master:8260db752c91 into amd-gfx:362b06229d79
Remote branch master 9c31e12 [sanitizer] Remove -Wno-non-virtual-dtor
  • Loading branch information
Sw authored and Sw committed Nov 4, 2020
2 parents d382ea1 + 9c31e12 commit 5505561
Show file tree
Hide file tree
Showing 46 changed files with 1,368 additions and 524 deletions.
10 changes: 8 additions & 2 deletions clang-tools-extra/clangd/index/Ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ struct Ref {
/// The source location where the symbol is named.
SymbolLocation Location;
RefKind Kind = RefKind::Unknown;
/// The ID of the symbol whose definition contains this reference.
/// For example, for a reference inside a function body, this would
/// be that function. For top-level definitions this isNull().
SymbolID Container;
};

inline bool operator<(const Ref &L, const Ref &R) {
return std::tie(L.Location, L.Kind) < std::tie(R.Location, R.Kind);
return std::tie(L.Location, L.Kind, L.Container) <
std::tie(R.Location, R.Kind, R.Container);
}
inline bool operator==(const Ref &L, const Ref &R) {
return std::tie(L.Location, L.Kind) == std::tie(R.Location, R.Kind);
return std::tie(L.Location, L.Kind, L.Container) ==
std::tie(R.Location, R.Kind, R.Container);
}

llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Ref &);
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/clangd/index/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ void writeRefs(const SymbolID &ID, llvm::ArrayRef<Ref> Refs,
for (const auto &Ref : Refs) {
OS.write(static_cast<unsigned char>(Ref.Kind));
writeLocation(Ref.Location, Strings, OS);
OS << Ref.Container.raw();
}
}

Expand All @@ -356,6 +357,7 @@ readRefs(Reader &Data, llvm::ArrayRef<llvm::StringRef> Strings) {
for (auto &Ref : Result.second) {
Ref.Kind = static_cast<RefKind>(Data.consume8());
Ref.Location = readLocation(Data, Strings);
Ref.Container = Data.consumeID();
}
return Result;
}
Expand Down
44 changes: 22 additions & 22 deletions clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ bool SymbolCollector::handleDeclOccurrence(
!isa<NamespaceDecl>(ND) &&
(Opts.RefsInHeaders ||
SM.getFileID(SM.getFileLoc(Loc)) == SM.getMainFileID()))
DeclRefs[ND].emplace_back(SM.getFileLoc(Loc), Roles);
DeclRefs[ND].push_back(
SymbolRef{SM.getFileLoc(Loc), Roles, ASTNode.Parent});
// Don't continue indexing if this is a mere reference.
if (IsOnlyRef)
return true;
Expand Down Expand Up @@ -422,7 +423,8 @@ bool SymbolCollector::handleMacroOccurrence(const IdentifierInfo *Name,
// Do not store references to main-file macros.
if ((static_cast<unsigned>(Opts.RefFilter) & Roles) && !IsMainFileOnly &&
(Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID()))
MacroRefs[ID].push_back({Loc, Roles});
// FIXME: Populate container information for macro references.
MacroRefs[ID].push_back({Loc, Roles, /*Container=*/nullptr});

// Collect symbols.
if (!Opts.CollectMacro)
Expand Down Expand Up @@ -579,24 +581,22 @@ void SymbolCollector::finish() {
}
return Found->second;
};
auto CollectRef =
[&](SymbolID ID,
const std::pair<SourceLocation, index::SymbolRoleSet> &LocAndRole,
bool Spelled = false) {
auto FileID = SM.getFileID(LocAndRole.first);
// FIXME: use the result to filter out references.
shouldIndexFile(FileID);
if (auto FileURI = GetURI(FileID)) {
auto Range =
getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
Ref R;
R.Location.Start = Range.first;
R.Location.End = Range.second;
R.Location.FileURI = FileURI->c_str();
R.Kind = toRefKind(LocAndRole.second, Spelled);
Refs.insert(ID, R);
}
};
auto CollectRef = [&](SymbolID ID, const SymbolRef &LocAndRole,
bool Spelled = false) {
auto FileID = SM.getFileID(LocAndRole.Loc);
// FIXME: use the result to filter out references.
shouldIndexFile(FileID);
if (auto FileURI = GetURI(FileID)) {
auto Range = getTokenRange(LocAndRole.Loc, SM, ASTCtx->getLangOpts());
Ref R;
R.Location.Start = Range.first;
R.Location.End = Range.second;
R.Location.FileURI = FileURI->c_str();
R.Kind = toRefKind(LocAndRole.Roles, Spelled);
R.Container = getSymbolID(LocAndRole.Container);
Refs.insert(ID, R);
}
};
// Populate Refs slab from MacroRefs.
// FIXME: All MacroRefs are marked as Spelled now, but this should be checked.
for (const auto &IDAndRefs : MacroRefs)
Expand All @@ -607,7 +607,7 @@ void SymbolCollector::finish() {
for (auto &DeclAndRef : DeclRefs) {
if (auto ID = getSymbolID(DeclAndRef.first)) {
for (auto &LocAndRole : DeclAndRef.second) {
const auto FileID = SM.getFileID(LocAndRole.first);
const auto FileID = SM.getFileID(LocAndRole.Loc);
// FIXME: It's better to use TokenBuffer by passing spelled tokens from
// the caller of SymbolCollector.
if (!FilesToTokensCache.count(FileID))
Expand All @@ -617,7 +617,7 @@ void SymbolCollector::finish() {
// Check if the referenced symbol is spelled exactly the same way the
// corresponding NamedDecl is. If it is, mark this reference as spelled.
const auto *IdentifierToken =
spelledIdentifierTouching(LocAndRole.first, Tokens);
spelledIdentifierTouching(LocAndRole.Loc, Tokens);
DeclarationName Name = DeclAndRef.first->getDeclName();
const auto NameKind = Name.getNameKind();
bool IsTargetKind = NameKind == DeclarationName::Identifier ||
Expand Down
6 changes: 5 additions & 1 deletion clang-tools-extra/clangd/index/SymbolCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ class SymbolCollector : public index::IndexDataConsumer {
std::shared_ptr<GlobalCodeCompletionAllocator> CompletionAllocator;
std::unique_ptr<CodeCompletionTUInfo> CompletionTUInfo;
Options Opts;
using SymbolRef = std::pair<SourceLocation, index::SymbolRoleSet>;
struct SymbolRef {
SourceLocation Loc;
index::SymbolRoleSet Roles;
const Decl *Container;
};
// Symbols referenced from the current TU, flushed on finish().
llvm::DenseSet<const NamedDecl *> ReferencedDecls;
llvm::DenseSet<const IdentifierInfo *> ReferencedMacros;
Expand Down
96 changes: 79 additions & 17 deletions clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,16 @@ MATCHER_P(IncludeHeader, P, "") {
MATCHER_P2(IncludeHeaderWithRef, IncludeHeader, References, "") {
return (arg.IncludeHeader == IncludeHeader) && (arg.References == References);
}
bool rangesMatch(const SymbolLocation &Loc, const Range &R) {
return std::make_tuple(Loc.Start.line(), Loc.Start.column(), Loc.End.line(),
Loc.End.column()) ==
std::make_tuple(R.start.line, R.start.character, R.end.line,
R.end.character);
}
MATCHER_P(DeclRange, Pos, "") {
return std::make_tuple(arg.CanonicalDeclaration.Start.line(),
arg.CanonicalDeclaration.Start.column(),
arg.CanonicalDeclaration.End.line(),
arg.CanonicalDeclaration.End.column()) ==
std::make_tuple(Pos.start.line, Pos.start.character, Pos.end.line,
Pos.end.character);
}
MATCHER_P(DefRange, Pos, "") {
return std::make_tuple(
arg.Definition.Start.line(), arg.Definition.Start.column(),
arg.Definition.End.line(), arg.Definition.End.column()) ==
std::make_tuple(Pos.start.line, Pos.start.character, Pos.end.line,
Pos.end.character);
return rangesMatch(arg.CanonicalDeclaration, Pos);
}
MATCHER_P(DefRange, Pos, "") { return rangesMatch(arg.Definition, Pos); }
MATCHER_P(RefCount, R, "") { return int(arg.References) == R; }
MATCHER_P(ForCodeCompletion, IsIndexedForCodeCompletion, "") {
return static_cast<bool>(arg.Flags & Symbol::IndexedForCodeCompletion) ==
Expand All @@ -100,10 +95,7 @@ MATCHER(VisibleOutsideFile, "") {
MATCHER(RefRange, "") {
const Ref &Pos = ::testing::get<0>(arg);
const Range &Range = ::testing::get<1>(arg);
return std::make_tuple(Pos.Location.Start.line(), Pos.Location.Start.column(),
Pos.Location.End.line(), Pos.Location.End.column()) ==
std::make_tuple(Range.start.line, Range.start.character,
Range.end.line, Range.end.character);
return rangesMatch(Pos.Location, Range);
}
::testing::Matcher<const std::vector<Ref> &>
HaveRanges(const std::vector<Range> Ranges) {
Expand Down Expand Up @@ -738,6 +730,76 @@ TEST_F(SymbolCollectorTest, Refs) {
EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "FUNC").ID, _))));
}

TEST_F(SymbolCollectorTest, RefContainers) {
Annotations Code(R"cpp(
int $toplevel1[[f1]](int);
void f2() {
(void) $ref1a[[f1]](1);
auto fptr = &$ref1b[[f1]];
}
int $toplevel2[[v1]] = $ref2[[f1]](2);
void f3(int arg = $ref3[[f1]](3));
struct S1 {
int $classscope1[[member1]] = $ref4[[f1]](4);
int $classscope2[[member2]] = 42;
};
constexpr int f4(int x) { return x + 1; }
template <int I = $ref5[[f4]](0)> struct S2 {};
S2<$ref6[[f4]](0)> v2;
S2<$ref7a[[f4]](0)> f5(S2<$ref7b[[f4]](0)>);
namespace N {
void $namespacescope1[[f6]]();
int $namespacescope2[[v3]];
}
)cpp");
CollectorOpts.RefFilter = RefKind::All;
CollectorOpts.CollectMainFileRefs = true;
runSymbolCollector("", Code.code());
auto FindRefWithRange = [&](Range R) -> Optional<Ref> {
for (auto &Entry : Refs) {
for (auto &Ref : Entry.second) {
if (rangesMatch(Ref.Location, R))
return Ref;
}
}
return llvm::None;
};
auto Container = [&](llvm::StringRef RangeName) {
auto Ref = FindRefWithRange(Code.range(RangeName));
EXPECT_TRUE(bool(Ref));
return Ref->Container;
};
EXPECT_EQ(Container("ref1a"),
findSymbol(Symbols, "f2").ID); // function body (call)
EXPECT_EQ(Container("ref1b"),
findSymbol(Symbols, "f2").ID); // function body (address-of)
EXPECT_EQ(Container("ref2"),
findSymbol(Symbols, "v1").ID); // variable initializer
EXPECT_EQ(Container("ref3"),
findSymbol(Symbols, "f3").ID); // function parameter default value
EXPECT_EQ(Container("ref4"),
findSymbol(Symbols, "S1::member1").ID); // member initializer
EXPECT_EQ(Container("ref5"),
findSymbol(Symbols, "S2").ID); // template parameter default value
EXPECT_EQ(Container("ref6"),
findSymbol(Symbols, "v2").ID); // type of variable
EXPECT_EQ(Container("ref7a"),
findSymbol(Symbols, "f5").ID); // return type of function
EXPECT_EQ(Container("ref7b"),
findSymbol(Symbols, "f5").ID); // parameter type of function

EXPECT_FALSE(Container("classscope1").isNull());
EXPECT_FALSE(Container("namespacescope1").isNull());

EXPECT_EQ(Container("toplevel1"), Container("toplevel2"));
EXPECT_EQ(Container("classscope1"), Container("classscope2"));
EXPECT_EQ(Container("namespacescope1"), Container("namespacescope2"));

EXPECT_NE(Container("toplevel1"), Container("namespacescope1"));
EXPECT_NE(Container("toplevel1"), Container("classscope1"));
EXPECT_NE(Container("classscope1"), Container("namespacescope1"));
}

TEST_F(SymbolCollectorTest, MacroRefInHeader) {
Annotations Header(R"(
#define $foo[[FOO]](X) (X + 1)
Expand Down
12 changes: 11 additions & 1 deletion compiler-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ endif()
append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS)
Expand Down Expand Up @@ -597,7 +596,18 @@ else()
set(COMPILER_RT_HAS_LLD TRUE)
endif()
endif()

if(ANDROID)
set(COMPILER_RT_HAS_LLD TRUE)
set(COMPILER_RT_TEST_USE_LLD TRUE)
append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld SANITIZER_COMMON_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_LLD -fuse-ld=lld COMPILER_RT_UNITTEST_LINK_FLAGS)
if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
set(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT FALSE)
endif()
endif()
pythonize_bool(COMPILER_RT_HAS_LLD)
pythonize_bool(COMPILER_RT_TEST_USE_LLD)

add_subdirectory(lib)

Expand Down
4 changes: 1 addition & 3 deletions compiler-rt/lib/asan/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ set(ASAN_UNITTEST_COMMON_CFLAGS
-fno-rtti
-O2
-Wno-format
-Werror=sign-compare
-Wno-non-virtual-dtor
)
-Werror=sign-compare)
append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros ASAN_UNITTEST_COMMON_CFLAGS)

# This will ensure the target linker is used
Expand Down
3 changes: 1 addition & 2 deletions compiler-rt/lib/interception/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ set(INTERCEPTION_TEST_CFLAGS_COMMON
-I${COMPILER_RT_SOURCE_DIR}/lib/interception
-fno-rtti
-O2
-Werror=sign-compare
-Wno-non-virtual-dtor)
-Werror=sign-compare)

set(INTERCEPTION_TEST_LINK_FLAGS_COMMON
${COMPILER_RT_UNITTEST_LINK_FLAGS})
Expand Down
1 change: 0 additions & 1 deletion compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ set(SANITIZER_TEST_CFLAGS_COMMON
-fno-rtti
-O2
-Werror=sign-compare
-Wno-non-virtual-dtor
-Wno-gnu-zero-variadic-macro-arguments
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

// https://code.google.com/p/address-sanitizer/issues/detail?id=260
// REQUIRES: lld

// FIXME: This may pass on Android, with non-emulated-tls.
// XFAIL: android
int undefined();

// On i386 clang adds --export-dynamic when linking with ASan, which adds all
Expand Down
12 changes: 0 additions & 12 deletions compiler-rt/test/lit.common.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@
if config.memprof_shadow_scale != '':
config.target_cflags += " -mllvm -memprof-mapping-scale=" + config.memprof_shadow_scale

# BFD linker in 64-bit android toolchains fails to find libc++_shared.so, which
# is a transitive shared library dependency (via asan runtime).
if config.android:
# Prepend the flag so that it can be overridden.
config.target_cflags = "-pie -fuse-ld=gold " + config.target_cflags
if config.android_ndk_version < 19:
# With a new compiler and NDK < r19 this flag ends up meaning "link against
# libc++", but NDK r19 makes this mean "link against the stub libstdc++ that
# just contains a handful of ABI functions", which makes most C++ code fail
# to link. In r19 and later we just use the default which is libc++.
config.cxx_mode_flags.append('-stdlib=libstdc++')

config.environment = dict(os.environ)

# Clear some environment variables that might affect Clang.
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/lit.common.configured.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ set_default("apple_platform_min_deployment_target_flag", "-mmacosx-version-min")
set_default("sanitizer_can_use_cxxabi", @SANITIZER_CAN_USE_CXXABI_PYBOOL@)
set_default("has_lld", @COMPILER_RT_HAS_LLD_PYBOOL@)
set_default("can_symbolize", @CAN_SYMBOLIZE@)
set_default("use_lld", False)
set_default("use_lld", @COMPILER_RT_TEST_USE_LLD_PYBOOL@)
set_default("use_thinlto", False)
set_default("use_lto", config.use_thinlto)
set_default("use_newpm", False)
Expand Down
2 changes: 2 additions & 0 deletions flang/include/flang/Semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ class Symbol {
OmpShared, OmpPrivate, OmpLinear, OmpFirstPrivate, OmpLastPrivate,
// OpenMP data-mapping attribute
OmpMapTo, OmpMapFrom, OmpMapAlloc, OmpMapRelease, OmpMapDelete,
// OpenMP data-copying attribute
OmpCopyIn,
// OpenMP miscellaneous flags
OmpCommonBlock, OmpReduction, OmpAllocate, OmpDeclareSimd,
OmpDeclareTarget, OmpThreadprivate, OmpDeclareReduction, OmpFlushed,
Expand Down
Loading

0 comments on commit 5505561

Please sign in to comment.