Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: Ib6486bde1b05bbb13d46631f6bff38fe6b5bec0b
  • Loading branch information
Jenkins authored and ronlieb committed Nov 21, 2024
2 parents aa137c6 + 56c091e commit 300c83e
Show file tree
Hide file tree
Showing 338 changed files with 5,668 additions and 2,407 deletions.
4 changes: 2 additions & 2 deletions amd/comgr/src/comgr-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ AMDGPUCompiler::executeInProcessDriver(ArrayRef<const char *> Args) {
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);

auto VFS = llvm::vfs::getRealFileSystem();
ProcessWarningOptions(Diags, *DiagOpts, *VFS, /*ReportDiags=*/false);
ProcessWarningOptions(Diags, *DiagOpts, *VFS, /*ReportDiags=*/false);

Driver TheDriver((Twine(env::getLLVMPath()) + "/bin/clang").str(),
llvm::sys::getDefaultTargetTriple(), Diags,
Expand Down Expand Up @@ -719,7 +719,7 @@ AMDGPUCompiler::executeInProcessDriver(ArrayRef<const char *> Args) {
// Internally this call refers to the invocation created above, so at
// this point the DiagnosticsEngine should accurately reflect all user
// requested configuration from Argv.
Clang->createDiagnostics(DiagClient, /* ShouldOwnClient */ false);
Clang->createDiagnostics(*VFS, DiagClient, /* ShouldOwnClient */ false);
if (!Clang->hasDiagnostics()) {
return AMD_COMGR_STATUS_ERROR;
}
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clang-include-fixer/IncludeFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ bool IncludeFixerActionFactory::runInvocation(

// Create the compiler's actual diagnostics engine. We want to drop all
// diagnostics here.
Compiler.createDiagnostics(new clang::IgnoringDiagConsumer,
Compiler.createDiagnostics(Files->getVirtualFileSystem(),
new clang::IgnoringDiagConsumer,
/*ShouldOwnClient=*/true);
Compiler.createSourceManager(*Files);

Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/clangd/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
CIOpts.VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
CIOpts.CC1Args = CC1Args;
CIOpts.RecoverOnError = true;
CIOpts.Diags =
CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false);
CIOpts.Diags = CompilerInstance::createDiagnostics(
*CIOpts.VFS, new DiagnosticOptions, &D, false);
CIOpts.ProbePrecompiled = false;
std::unique_ptr<CompilerInvocation> CI = createInvocation(ArgStrs, CIOpts);
if (!CI)
Expand Down Expand Up @@ -148,7 +148,7 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
auto Clang = std::make_unique<CompilerInstance>(
std::make_shared<PCHContainerOperations>());
Clang->setInvocation(std::move(CI));
Clang->createDiagnostics(&DiagsClient, false);
Clang->createDiagnostics(*VFS, &DiagsClient, false);

if (auto VFSWithRemapping = createVFSFromCompilerInvocation(
Clang->getInvocation(), Clang->getDiagnostics(), VFS))
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/ModulesBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,

clang::clangd::IgnoreDiagnostics IgnoreDiags;
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
CompilerInstance::createDiagnostics(new DiagnosticOptions, &IgnoreDiags,
CompilerInstance::createDiagnostics(*VFS, new DiagnosticOptions,
&IgnoreDiags,
/*ShouldOwnClient=*/false);

LangOptions LangOpts;
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/Preamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,9 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
for (const auto &L : ASTListeners)
L->sawDiagnostic(D, Diag);
});
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine =
CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
CompilerInstance::createDiagnostics(*VFS, &CI.getDiagnosticOpts(),
&PreambleDiagnostics,
/*ShouldOwnClient=*/false);
const Config &Cfg = Config::current();
Expand Down Expand Up @@ -651,7 +652,6 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
for (const auto &L : ASTListeners)
L->beforeExecute(CI);
});
auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory);
llvm::SmallString<32> AbsFileName(FileName);
VFS->makeAbsolute(AbsFileName);
auto StatCache = std::make_shared<PreambleFileStatusCache>(AbsFileName);
Expand Down
19 changes: 10 additions & 9 deletions clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,6 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
)cpp";
Inputs.ExtraFiles["foo.h"] = "";

auto Clang = std::make_unique<CompilerInstance>(
std::make_shared<PCHContainerOperations>());
Clang->createDiagnostics();

Clang->setInvocation(std::make_unique<CompilerInvocation>());
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(
Clang->getInvocation(), {Filename.data()}, Clang->getDiagnostics(),
"clang"));

// Create unnamed memory buffers for all the files.
auto VFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
VFS->addFile(Filename, /*ModificationTime=*/0,
Expand All @@ -626,6 +617,16 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
VFS->addFile(Extra.getKey(), /*ModificationTime=*/0,
llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
/*BufferName=*/""));

auto Clang = std::make_unique<CompilerInstance>(
std::make_shared<PCHContainerOperations>());
Clang->createDiagnostics(*VFS);

Clang->setInvocation(std::make_unique<CompilerInvocation>());
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(
Clang->getInvocation(), {Filename.data()}, Clang->getDiagnostics(),
"clang"));

auto *FM = Clang->createFileManager(VFS);
ASSERT_TRUE(Clang->ExecuteAction(*Inputs.MakeAction()));
EXPECT_THAT(
Expand Down
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ Improvements to Clang's diagnostics

- Clang now diagnoses missing return value in functions containing ``if consteval`` (#GH116485).

- Clang now correctly recognises code after a call to a ``[[noreturn]]`` constructor
as unreachable (#GH63009).

Improvements to Clang's time-trace
----------------------------------

Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Basic/arm_neon.td
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def OP_BFMLALT_LN

def OP_VCVT_F32_BF16
: Op<(bitcast "R",
(call "vshll_n", (bitcast "int16x4_t", $p0),
(call "vshll_n", (bitcast "uint16x4_t", $p0),
(literal "int32_t", "16")))>;
def OP_VCVT_F32_BF16_LO
: Op<(call "vcvt_f32_bf16", (call "vget_low", $p0))>;
Expand All @@ -275,8 +275,8 @@ def OP_VCVT_BF16_F32_HI_A32
(call "vget_low", $p0))>;

def OP_CVT_F32_BF16
: Op<(bitcast "R", (op "<<", (cast "int32_t", (bitcast "int16_t", $p0)),
(literal "int32_t", "16")))>;
: Op<(bitcast "R", (op "<<", (cast "uint32_t", (bitcast "uint16_t", $p0)),
(literal "uint32_t", "16")))>;

//===----------------------------------------------------------------------===//
// Auxiliary Instructions
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/arm_neon_incl.td
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def OP_UNAVAILABLE : Operation {
// h: half-float
// d: double
// b: bfloat16
// m: mfloat8
//
// Typespec modifiers
// ------------------
Expand Down
15 changes: 10 additions & 5 deletions clang/include/clang/Frontend/CompilerInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,17 @@ class CompilerInstance : public ModuleLoader {
/// Note that this routine also replaces the diagnostic client,
/// allocating one if one is not provided.
///
/// \param VFS is used for any IO needed when creating DiagnosticsEngine. It
/// doesn't replace VFS in the CompilerInstance (if any).
///
/// \param Client If non-NULL, a diagnostic client that will be
/// attached to (and, then, owned by) the DiagnosticsEngine inside this AST
/// unit.
///
/// \param ShouldOwnClient If Client is non-NULL, specifies whether
/// the diagnostic object should take ownership of the client.
void createDiagnostics(DiagnosticConsumer *Client = nullptr,
void createDiagnostics(llvm::vfs::FileSystem &VFS,
DiagnosticConsumer *Client = nullptr,
bool ShouldOwnClient = true);

/// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
Expand All @@ -702,10 +706,11 @@ class CompilerInstance : public ModuleLoader {
/// used by some diagnostics printers (for logging purposes only).
///
/// \return The new object on success, or null on failure.
static IntrusiveRefCntPtr<DiagnosticsEngine> createDiagnostics(
DiagnosticOptions *Opts, DiagnosticConsumer *Client = nullptr,
bool ShouldOwnClient = true, const CodeGenOptions *CodeGenOpts = nullptr,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
static IntrusiveRefCntPtr<DiagnosticsEngine>
createDiagnostics(llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
DiagnosticConsumer *Client = nullptr,
bool ShouldOwnClient = true,
const CodeGenOptions *CodeGenOpts = nullptr);

/// Create the file manager and replace any existing one with it.
///
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static bool CheckBitcastType(InterpState &S, CodePtr OpPC, QualType T,
};
auto note = [&](int Construct, QualType NoteType, SourceRange NoteRange) {
S.Note(NoteRange.getBegin(), diag::note_constexpr_bit_cast_invalid_subtype)
<< NoteType << Construct << T << NoteRange;
<< NoteType << Construct << T.getUnqualifiedType() << NoteRange;
return false;
};

Expand Down Expand Up @@ -388,11 +388,10 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC,
QualType FromType = FromPtr.getType();
QualType ToType = ToPtr.getType();

if (!CheckBitcastType(S, OpPC, FromType, /*IsToType=*/false))
return false;

if (!CheckBitcastType(S, OpPC, ToType, /*IsToType=*/true))
return false;
if (!CheckBitcastType(S, OpPC, FromType, /*IsToType=*/false))
return false;

BitcastBuffer Buffer;
readPointerToBuffer(S.getContext(), FromPtr, Buffer,
Expand Down
26 changes: 15 additions & 11 deletions clang/lib/Analysis/CFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ class CFGBuilder {
void cleanupConstructionContext(Expr *E);

void autoCreateBlock() { if (!Block) Block = createBlock(); }

CFGBlock *createBlock(bool add_successor = true);
CFGBlock *createNoReturnBlock();

Expand Down Expand Up @@ -818,15 +819,21 @@ class CFGBuilder {
B->appendStmt(const_cast<Stmt*>(S), cfg->getBumpVectorContext());
}

void appendConstructor(CFGBlock *B, CXXConstructExpr *CE) {
void appendConstructor(CXXConstructExpr *CE) {
CXXConstructorDecl *C = CE->getConstructor();
if (C && C->isNoReturn())
Block = createNoReturnBlock();
else
autoCreateBlock();

if (const ConstructionContext *CC =
retrieveAndCleanupConstructionContext(CE)) {
B->appendConstructor(CE, CC, cfg->getBumpVectorContext());
Block->appendConstructor(CE, CC, cfg->getBumpVectorContext());
return;
}

// No valid construction context found. Fall back to statement.
B->appendStmt(CE, cfg->getBumpVectorContext());
Block->appendStmt(CE, cfg->getBumpVectorContext());
}

void appendCall(CFGBlock *B, CallExpr *CE) {
Expand Down Expand Up @@ -4832,9 +4839,7 @@ CFGBlock *CFGBuilder::VisitCXXConstructExpr(CXXConstructExpr *C,
// construct these objects. Construction contexts we find here aren't for the
// constructor C, they're for its arguments only.
findConstructionContextsForArguments(C);

autoCreateBlock();
appendConstructor(Block, C);
appendConstructor(C);

return VisitChildren(C);
}
Expand Down Expand Up @@ -4892,16 +4897,15 @@ CFGBlock *CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
return Visit(E->getSubExpr(), asc);
}

CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
AddStmtChoice asc) {
// If the constructor takes objects as arguments by value, we need to properly
// construct these objects. Construction contexts we find here aren't for the
// constructor C, they're for its arguments only.
findConstructionContextsForArguments(C);
findConstructionContextsForArguments(E);
appendConstructor(E);

autoCreateBlock();
appendConstructor(Block, C);
return VisitChildren(C);
return VisitChildren(E);
}

CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E,
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info,
LocalSLocEntryTable.push_back(SLocEntry::get(NextLocalOffset, Info));
if (NextLocalOffset + Length + 1 <= NextLocalOffset ||
NextLocalOffset + Length + 1 > CurrentLoadedOffset) {
Diag.Report(SourceLocation(), diag::err_sloc_space_too_large);
Diag.Report(diag::err_sloc_space_too_large);
// FIXME: call `noteSLocAddressSpaceUsage` to report details to users and
// use a source location from `Info` to point at an error.
// Currently, both cause Clang to run indefinitely, this needs to be fixed.
Expand Down Expand Up @@ -2295,7 +2295,7 @@ void SourceManager::noteSLocAddressSpaceUsage(
uint64_t LoadedUsage = MaxLoadedOffset - CurrentLoadedOffset;
int UsagePercent = static_cast<int>(100.0 * double(LocalUsage + LoadedUsage) /
MaxLoadedOffset);
Diag.Report(SourceLocation(), diag::note_total_sloc_usage)
Diag.Report(diag::note_total_sloc_usage)
<< LocalUsage << LoadedUsage << (LocalUsage + LoadedUsage)
<< UsagePercent;

Expand All @@ -2311,7 +2311,7 @@ void SourceManager::noteSLocAddressSpaceUsage(

// Describe any remaining usage not reported in the per-file usage.
if (ReportedSize != CountedSize) {
Diag.Report(SourceLocation(), diag::note_file_misc_sloc_usage)
Diag.Report(diag::note_file_misc_sloc_usage)
<< (SortedUsage.end() - SortedEnd) << CountedSize - ReportedSize;
}
}
Expand Down
30 changes: 14 additions & 16 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,20 @@ static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
}
}

void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client,
void CompilerInstance::createDiagnostics(llvm::vfs::FileSystem &VFS,
DiagnosticConsumer *Client,
bool ShouldOwnClient) {
Diagnostics = createDiagnostics(
&getDiagnosticOpts(), Client, ShouldOwnClient, &getCodeGenOpts(),
FileMgr ? FileMgr->getVirtualFileSystemPtr() : nullptr);
Diagnostics = createDiagnostics(VFS, &getDiagnosticOpts(), Client,
ShouldOwnClient, &getCodeGenOpts());
}

IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
DiagnosticOptions *Opts, DiagnosticConsumer *Client, bool ShouldOwnClient,
const CodeGenOptions *CodeGenOpts,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
llvm::vfs::FileSystem &VFS, DiagnosticOptions *Opts,
DiagnosticConsumer *Client, bool ShouldOwnClient,
const CodeGenOptions *CodeGenOpts) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
IntrusiveRefCntPtr<DiagnosticsEngine>
Diags(new DiagnosticsEngine(DiagID, Opts));

if (!VFS)
VFS = llvm::vfs::getRealFileSystem();
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
new DiagnosticsEngine(DiagID, Opts));

// Create the diagnostic client for reporting errors or for
// implementing -verify.
Expand All @@ -372,7 +369,7 @@ IntrusiveRefCntPtr<DiagnosticsEngine> CompilerInstance::createDiagnostics(
Opts->DiagnosticSerializationFile);

// Configure our handling of diagnostics.
ProcessWarningOptions(*Diags, *Opts, *VFS);
ProcessWarningOptions(*Diags, *Opts, VFS);

return Diags;
}
Expand Down Expand Up @@ -1240,9 +1237,10 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
auto &Inv = *Invocation;
Instance.setInvocation(std::move(Invocation));

Instance.createDiagnostics(new ForwardingDiagnosticConsumer(
ImportingInstance.getDiagnosticClient()),
/*ShouldOwnClient=*/true);
Instance.createDiagnostics(
ImportingInstance.getVirtualFileSystem(),
new ForwardingDiagnosticConsumer(ImportingInstance.getDiagnosticClient()),
/*ShouldOwnClient=*/true);

if (llvm::is_contained(DiagOpts.SystemHeaderWarningsModules, ModuleName))
Instance.getDiagnostics().setSuppressSystemWarnings(false);
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/TargetParser/Host.h"
using namespace clang;
using namespace llvm::opt;
Expand All @@ -32,7 +33,9 @@ clang::createInvocation(ArrayRef<const char *> ArgList,
assert(!ArgList.empty());
auto Diags = Opts.Diags
? std::move(Opts.Diags)
: CompilerInstance::createDiagnostics(new DiagnosticOptions);
: CompilerInstance::createDiagnostics(
Opts.VFS ? *Opts.VFS : *llvm::vfs::getRealFileSystem(),
new DiagnosticOptions);

SmallVector<const char *, 16> Args(ArgList);

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Frontend/Rewrite/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener {
Instance.setInvocation(
std::make_shared<CompilerInvocation>(CI.getInvocation()));
Instance.createDiagnostics(
CI.getVirtualFileSystem(),
new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()),
/*ShouldOwnClient=*/true);
Instance.getFrontendOpts().DisableFree = false;
Expand Down
Loading

0 comments on commit 300c83e

Please sign in to comment.