Skip to content

Commit

Permalink
Merge pull request #300 from Xilinx/bump_to_6870ac201f9f
Browse files Browse the repository at this point in the history
Bump to 6870ac2 (6)
  • Loading branch information
mgehre-amd authored Aug 23, 2024
2 parents e6a5e19 + 07845fc commit af74a27
Show file tree
Hide file tree
Showing 74 changed files with 6,551 additions and 365 deletions.
8 changes: 7 additions & 1 deletion clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "refactor/Rename.h"
#include "refactor/Tweak.h"
#include "support/Cancellation.h"
#include "support/Context.h"
#include "support/Logger.h"
#include "support/MemoryTree.h"
#include "support/ThreadsafeFS.h"
Expand Down Expand Up @@ -112,7 +113,12 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
// Index outlives TUScheduler (declared first)
FIndex(FIndex),
// shared_ptr extends lifetime
Stdlib(Stdlib)]() mutable {
Stdlib(Stdlib),
// We have some FS implementations that rely on information in
// the context.
Ctx(Context::current().clone())]() mutable {
// Make sure we install the context into current thread.
WithContext C(std::move(Ctx));
clang::noteBottomOfStack();
IndexFileIn IF;
IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clangd/Preamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
Result->Marks = CapturedInfo.takeMarks();
Result->StatCache = StatCache;
Result->MainIsIncludeGuarded = CapturedInfo.isMainFileIncludeGuarded();
Result->TargetOpts = CI.TargetOpts;
if (PreambleCallback) {
trace::Span Tracer("Running PreambleCallback");
auto Ctx = CapturedInfo.takeLife();
Expand Down Expand Up @@ -913,6 +914,12 @@ PreamblePatch PreamblePatch::createMacroPatch(llvm::StringRef FileName,
}

void PreamblePatch::apply(CompilerInvocation &CI) const {
// Make sure the compilation uses same target opts as the preamble. Clang has
// no guarantees around using arbitrary options when reusing PCHs, and
// different target opts can result in crashes, see
// ParsedASTTest.PreambleWithDifferentTarget.
CI.TargetOpts = Baseline->TargetOpts;

// No need to map an empty file.
if (PatchContents.empty())
return;
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/clangd/Preamble.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "clang-include-cleaner/Record.h"
#include "support/Path.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/PrecompiledPreamble.h"
#include "clang/Lex/Lexer.h"
Expand Down Expand Up @@ -97,6 +98,10 @@ struct PreambleData {
// Version of the ParseInputs this preamble was built from.
std::string Version;
tooling::CompileCommand CompileCommand;
// Target options used when building the preamble. Changes in target can cause
// crashes when deserializing preamble, this enables consumers to use the
// same target (without reparsing CompileCommand).
std::shared_ptr<TargetOptions> TargetOpts = nullptr;
PrecompiledPreamble Preamble;
std::vector<Diag> Diags;
// Processes like code completions and go-to-definitions will need #include
Expand Down
25 changes: 25 additions & 0 deletions clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4160,7 +4160,32 @@ TEST(CompletionTest, DoNotCrash) {
auto Completions = completions(Case);
}
}
TEST(CompletionTest, PreambleFromDifferentTarget) {
constexpr std::string_view PreambleTarget = "x86_64";
constexpr std::string_view Contents =
"int foo(int); int num; int num2 = foo(n^";

Annotations Test(Contents);
auto TU = TestTU::withCode(Test.code());
TU.ExtraArgs.emplace_back("-target");
TU.ExtraArgs.emplace_back(PreambleTarget);
auto Preamble = TU.preamble();
ASSERT_TRUE(Preamble);
// Switch target to wasm.
TU.ExtraArgs.pop_back();
TU.ExtraArgs.emplace_back("wasm32");

MockFS FS;
auto Inputs = TU.inputs(FS);
auto Result = codeComplete(testPath(TU.Filename), Test.point(),
Preamble.get(), Inputs, {});
auto Signatures =
signatureHelp(testPath(TU.Filename), Test.point(), *Preamble, Inputs, {});

// Make sure we don't crash.
EXPECT_THAT(Result.Completions, Not(testing::IsEmpty()));
EXPECT_THAT(Signatures.signatures, Not(testing::IsEmpty()));
}
} // namespace
} // namespace clangd
} // namespace clang
39 changes: 32 additions & 7 deletions clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
//===----------------------------------------------------------------------===//

#include "../../clang-tidy/ClangTidyCheck.h"
#include "../../clang-tidy/ClangTidyModule.h"
#include "../../clang-tidy/ClangTidyModuleRegistry.h"
#include "AST.h"
#include "CompileCommands.h"
#include "Compiler.h"
#include "Config.h"
#include "Diagnostics.h"
Expand All @@ -32,7 +29,6 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Testing/Annotations/Annotations.h"
Expand All @@ -41,6 +37,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <memory>
#include <string_view>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -347,9 +344,8 @@ TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
}
for (const auto &R : AST.getMacros().UnknownMacros)
MacroExpansionPositions.push_back(R.StartOffset);
EXPECT_THAT(
MacroExpansionPositions,
testing::UnorderedElementsAreArray(TestCase.points()));
EXPECT_THAT(MacroExpansionPositions,
testing::UnorderedElementsAreArray(TestCase.points()));
}

MATCHER_P(withFileName, Inc, "") { return arg.FileName == Inc; }
Expand Down Expand Up @@ -768,6 +764,35 @@ TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
<< "Should not try to build AST for assembly source file";
}

TEST(ParsedASTTest, PreambleWithDifferentTarget) {
constexpr std::string_view kPreambleTarget = "x86_64";
// Specifically picking __builtin_va_list as it triggers crashes when
// switching to wasm.
// It's due to different predefined types in different targets.
auto TU = TestTU::withHeaderCode("void foo(__builtin_va_list);");
TU.Code = "void bar() { foo(2); }";
TU.ExtraArgs.emplace_back("-target");
TU.ExtraArgs.emplace_back(kPreambleTarget);
const auto Preamble = TU.preamble();

// Switch target to wasm.
TU.ExtraArgs.pop_back();
TU.ExtraArgs.emplace_back("wasm32");

IgnoreDiagnostics Diags;
MockFS FS;
auto Inputs = TU.inputs(FS);
auto CI = buildCompilerInvocation(Inputs, Diags);
ASSERT_TRUE(CI) << "Failed to build compiler invocation";

auto AST = ParsedAST::build(testPath(TU.Filename), std::move(Inputs),
std::move(CI), {}, Preamble);

ASSERT_TRUE(AST);
// We use the target from preamble, not with the most-recent flags.
EXPECT_EQ(AST->getASTContext().getTargetInfo().getTriple().getArchName(),
llvm::StringRef(kPreambleTarget));
}
} // namespace
} // namespace clangd
} // namespace clang
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def err_no_matching_target : Error<"no matching target found for target variant
def err_unsupported_vendor : Error<"vendor '%0' is not supported: '%1'">;
def err_unsupported_environment : Error<"environment '%0' is not supported: '%1'">;
def err_unsupported_os : Error<"os '%0' is not supported: '%1'">;
def err_cannot_read_alias_list : Error<"could not read alias list '%0': %1">;
} // end of command line category.

let CategoryName = "Verification" in {
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ def end_no_unused_arguments : Flag<["--"], "end-no-unused-arguments">,
def interface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">,
Visibility<[ClangOption, CC1Option]>;
def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
def alias_list : Separate<["-"], "alias_list">, Flags<[LinkerInput]>;
def extract_api : Flag<["-"], "extract-api">,
Visibility<[ClangOption, CC1Option]>, Group<Action_Group>,
HelpText<"Extract API information">;
Expand Down
15 changes: 10 additions & 5 deletions clang/include/clang/InstallAPI/DylibVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
DylibVerifier() = default;

DylibVerifier(llvm::MachO::Records &&Dylib, ReexportedInterfaces &&Reexports,
DiagnosticsEngine *Diag, VerificationMode Mode, bool Zippered,
bool Demangle, StringRef DSYMPath)
: Dylib(std::move(Dylib)), Reexports(std::move(Reexports)), Mode(Mode),
Zippered(Zippered), Demangle(Demangle), DSYMPath(DSYMPath),
AliasMap Aliases, DiagnosticsEngine *Diag,
VerificationMode Mode, bool Zippered, bool Demangle,
StringRef DSYMPath)
: Dylib(std::move(Dylib)), Reexports(std::move(Reexports)),
Aliases(std::move(Aliases)), Mode(Mode), Zippered(Zippered),
Demangle(Demangle), DSYMPath(DSYMPath),
Exports(std::make_unique<SymbolSet>()), Ctx(VerifierContext{Diag}) {}

Result verify(GlobalRecord *R, const FrontendAttrs *FA);
Expand All @@ -104,7 +106,7 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
void setTarget(const Target &T);

/// Release ownership over exports.
std::unique_ptr<SymbolSet> getExports() { return std::move(Exports); }
std::unique_ptr<SymbolSet> takeExports();

/// Get result of verification.
Result getState() const { return Ctx.FrontendState; }
Expand Down Expand Up @@ -189,6 +191,9 @@ class DylibVerifier : llvm::MachO::RecordVisitor {
// Reexported interfaces apart of the library.
ReexportedInterfaces Reexports;

// Symbol aliases.
AliasMap Aliases;

// Controls what class of violations to report.
VerificationMode Mode = VerificationMode::Invalid;

Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/InstallAPI/MachO.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/TextAPI/TextAPIWriter.h"
#include "llvm/TextAPI/Utils.h"

using AliasMap = llvm::MachO::AliasMap;
using Architecture = llvm::MachO::Architecture;
using ArchitectureSet = llvm::MachO::ArchitectureSet;
using SymbolFlags = llvm::MachO::SymbolFlags;
Expand Down
29 changes: 29 additions & 0 deletions clang/lib/Driver/ToolChains/AIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,30 @@ AIX::GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const {
return "/";
}

void AIX::AddOpenMPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Add OpenMP include paths if -fopenmp is specified.
if (DriverArgs.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
options::OPT_fno_openmp, false)) {
SmallString<128> PathOpenMP;
switch (getDriver().getOpenMPRuntime(DriverArgs)) {
case Driver::OMPRT_OMP:
PathOpenMP = GetHeaderSysroot(DriverArgs);
llvm::sys::path::append(PathOpenMP, "opt/IBM/openxlCSDK", "include",
"openmp");
addSystemInclude(DriverArgs, CC1Args, PathOpenMP.str());
break;
case Driver::OMPRT_IOMP5:
LLVM_FALLTHROUGH;
case Driver::OMPRT_GOMP:
LLVM_FALLTHROUGH;
case Driver::OMPRT_Unknown:
// Unknown / unsupported include paths.
break;
}
}
}

void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Return if -nostdinc is specified as a driver option.
Expand All @@ -380,6 +404,11 @@ void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
addSystemInclude(DriverArgs, CC1Args, path::parent_path(P.str()));
}

// Add the include directory containing omp.h. This needs to be before
// adding the system include directory because other compilers put their
// omp.h in /usr/include.
AddOpenMPIncludeArgs(DriverArgs, CC1Args);

// Return if -nostdlibinc is specified as a driver option.
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
return;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/AIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain {
private:
llvm::StringRef GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const;
bool ParseInlineAsmUsingAsmParser;
void AddOpenMPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const;
};

} // end namespace toolchains
Expand Down
24 changes: 24 additions & 0 deletions clang/lib/InstallAPI/DylibVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@ void DylibVerifier::visitSymbolInDylib(const Record &R, SymbolContext &SymCtx) {
return;
}

if (Aliases.count({SymbolName.str(), SymCtx.Kind})) {
updateState(Result::Valid);
return;
}

// All checks at this point classify as some kind of violation.
// The different verification modes dictate whether they are reported to the
// user.
Expand Down Expand Up @@ -973,5 +978,24 @@ bool DylibVerifier::verifyBinaryAttrs(const ArrayRef<Target> ProvidedTargets,
return true;
}

std::unique_ptr<SymbolSet> DylibVerifier::takeExports() {
for (const auto &[Alias, Base] : Aliases) {
TargetList Targets;
SymbolFlags Flags = SymbolFlags::None;
if (const Symbol *Sym = Exports->findSymbol(Base.second, Base.first)) {
Flags = Sym->getFlags();
Targets = {Sym->targets().begin(), Sym->targets().end()};
}

Record R(Alias.first, RecordLinkage::Exported, Flags);
SymbolContext SymCtx;
SymCtx.SymbolName = Alias.first;
SymCtx.Kind = Alias.second;
addSymbol(&R, SymCtx, std::move(Targets));
}

return std::move(Exports);
}

} // namespace installapi
} // namespace clang
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4729,7 +4729,8 @@ static bool shouldHaveNullability(QualType T) {
// It's unclear whether the pragma's behavior is useful for C++.
// e.g. treating type-aliases and template-type-parameters differently
// from types of declarations can be surprising.
!isa<RecordType>(T->getCanonicalTypeInternal());
!isa<RecordType, TemplateSpecializationType>(
T->getCanonicalTypeInternal());
}

static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
Expand Down
Loading

0 comments on commit af74a27

Please sign in to comment.