Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I52460ce5db3b9882c3b713123d8080eab5b7469f
  • Loading branch information
Jenkins committed Aug 30, 2024
2 parents 28f9f84 + fab9256 commit dc0a164
Show file tree
Hide file tree
Showing 146 changed files with 4,020 additions and 1,741 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
jobs:
code_formatter:
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.repository == 'llvm/llvm-project'
steps:
- name: Fetch LLVM sources
Expand Down
152 changes: 85 additions & 67 deletions clang-tools-extra/clangd/ModulesBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,87 @@ class FailedPrerequisiteModules : public PrerequisiteModules {
}
};

struct ModuleFile {
ModuleFile(StringRef ModuleName, PathRef ModuleFilePath)
: ModuleName(ModuleName.str()), ModuleFilePath(ModuleFilePath.str()) {}

ModuleFile() = delete;

ModuleFile(const ModuleFile &) = delete;
ModuleFile operator=(const ModuleFile &) = delete;

// The move constructor is needed for llvm::SmallVector.
ModuleFile(ModuleFile &&Other)
: ModuleName(std::move(Other.ModuleName)),
ModuleFilePath(std::move(Other.ModuleFilePath)) {
Other.ModuleName.clear();
Other.ModuleFilePath.clear();
}

ModuleFile &operator=(ModuleFile &&Other) {
if (this == &Other)
return *this;

this->~ModuleFile();
new (this) ModuleFile(std::move(Other));
return *this;
}

~ModuleFile() {
if (!ModuleFilePath.empty())
llvm::sys::fs::remove(ModuleFilePath);
}

std::string ModuleName;
std::string ModuleFilePath;
};

bool IsModuleFileUpToDate(
PathRef ModuleFilePath,
const PrerequisiteModules &RequisiteModules) {
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
CompilerInstance::createDiagnostics(new DiagnosticOptions());

auto HSOpts = std::make_shared<HeaderSearchOptions>();
RequisiteModules.adjustHeaderSearchOptions(*HSOpts);
HSOpts->ForceCheckCXX20ModulesInputFiles = true;
HSOpts->ValidateASTInputFilesContent = true;

PCHContainerOperations PCHOperations;
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
ModuleFilePath.str(), PCHOperations.getRawReader(), ASTUnit::LoadASTOnly,
Diags, FileSystemOptions(), std::move(HSOpts));

if (!Unit)
return false;

auto Reader = Unit->getASTReader();
if (!Reader)
return false;

bool UpToDate = true;
Reader->getModuleManager().visit([&](serialization::ModuleFile &MF) -> bool {
Reader->visitInputFiles(
MF, /*IncludeSystem=*/false, /*Complain=*/false,
[&](const serialization::InputFile &IF, bool isSystem) {
if (!IF.getFile() || IF.isOutOfDate())
UpToDate = false;
});

return !UpToDate;
});

return UpToDate;
}

bool IsModuleFilesUpToDate(
llvm::SmallVector<PathRef> ModuleFilePaths,
const PrerequisiteModules &RequisiteModules) {
return llvm::all_of(ModuleFilePaths, [&RequisiteModules](auto ModuleFilePath) {
return IsModuleFileUpToDate(ModuleFilePath, RequisiteModules);
});
}

// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
// the required modules are built successfully. All the module files
// are owned by the StandalonePrerequisiteModules class.
Expand Down Expand Up @@ -135,29 +216,6 @@ class StandalonePrerequisiteModules : public PrerequisiteModules {
}

private:
struct ModuleFile {
ModuleFile(llvm::StringRef ModuleName, PathRef ModuleFilePath)
: ModuleName(ModuleName.str()), ModuleFilePath(ModuleFilePath.str()) {}

ModuleFile(const ModuleFile &) = delete;
ModuleFile operator=(const ModuleFile &) = delete;

// The move constructor is needed for llvm::SmallVector.
ModuleFile(ModuleFile &&Other)
: ModuleName(std::move(Other.ModuleName)),
ModuleFilePath(std::move(Other.ModuleFilePath)) {}

ModuleFile &operator=(ModuleFile &&Other) = delete;

~ModuleFile() {
if (!ModuleFilePath.empty())
llvm::sys::fs::remove(ModuleFilePath);
}

std::string ModuleName;
std::string ModuleFilePath;
};

llvm::SmallVector<ModuleFile, 8> RequiredModules;
// A helper class to speedup the query if a module is built.
llvm::StringSet<> BuiltModuleNames;
Expand Down Expand Up @@ -286,50 +344,10 @@ bool StandalonePrerequisiteModules::canReuse(
if (RequiredModules.empty())
return true;

CompilerInstance Clang;

Clang.setInvocation(std::make_shared<CompilerInvocation>(CI));
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
CompilerInstance::createDiagnostics(new DiagnosticOptions());
Clang.setDiagnostics(Diags.get());

FileManager *FM = Clang.createFileManager(VFS);
Clang.createSourceManager(*FM);

if (!Clang.createTarget())
return false;

assert(Clang.getHeaderSearchOptsPtr());
adjustHeaderSearchOptions(Clang.getHeaderSearchOpts());
// Since we don't need to compile the source code actually, the TU kind here
// doesn't matter.
Clang.createPreprocessor(TU_Complete);
Clang.getHeaderSearchOpts().ForceCheckCXX20ModulesInputFiles = true;
Clang.getHeaderSearchOpts().ValidateASTInputFilesContent = true;

// Following the practice of clang's driver to suppres the checking for ODR
// violation in GMF.
// See
// https://clang.llvm.org/docs/StandardCPlusPlusModules.html#object-definition-consistency
// for example.
Clang.getLangOpts().SkipODRCheckInGMF = true;

Clang.createASTReader();
for (auto &RequiredModule : RequiredModules) {
llvm::StringRef BMIPath = RequiredModule.ModuleFilePath;
// FIXME: Loading BMI fully is too heavy considering something cheaply to
// check if we can reuse the BMI.
auto ReadResult =
Clang.getASTReader()->ReadAST(BMIPath, serialization::MK_MainFile,
SourceLocation(), ASTReader::ARR_None);

if (ReadResult != ASTReader::Success) {
elog("Can't reuse {0}: {1}", BMIPath, ReadResult);
return false;
}
}

return true;
SmallVector<StringRef> BMIPaths;
for (auto &MF : RequiredModules)
BMIPaths.push_back(MF.ModuleFilePath);
return IsModuleFilesUpToDate(BMIPaths, *this);
}

} // namespace clangd
Expand Down
7 changes: 7 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ Bug Fixes in This Version
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fix crash when atomic builtins are called with pointer to zero-size struct (#GH90330)

- Clang now allows pointee types of atomic builtin arguments to be complete template types
that was not instantiated elsewhere.

- ``__noop`` can now be used in a constant expression. (#GH102064)

Bug Fixes to Attribute Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -2980,8 +2980,9 @@ enum CXTypeKind {
CXType_Atomic = 177,
CXType_BTFTagAttributed = 178,

// HLSL Intangible Types
CXType_HLSLResource = 179
// HLSL Types
CXType_HLSLResource = 179,
CXType_HLSLAttributedResource = 180
};

/**
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
mutable llvm::ContextualFoldingSet<DependentBitIntType, ASTContext &>
DependentBitIntTypes;
llvm::FoldingSet<BTFTagAttributedType> BTFTagAttributedTypes;
llvm::FoldingSet<HLSLAttributedResourceType> HLSLAttributedResourceTypes;

mutable llvm::FoldingSet<CountAttributedType> CountAttributedTypes;

Expand Down Expand Up @@ -1671,6 +1672,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
QualType getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr,
QualType Wrapped);

QualType getHLSLAttributedResourceType(
QualType Wrapped, QualType Contained,
const HLSLAttributedResourceType::Attributes &Attrs);

QualType
getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
unsigned Index,
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ class ASTNodeTraverser
void VisitBTFTagAttributedType(const BTFTagAttributedType *T) {
Visit(T->getWrappedType());
}
void VisitHLSLAttributedResourceType(const HLSLAttributedResourceType *T) {
QualType Contained = T->getContainedType();
if (!Contained.isNull())
Visit(Contained);
}
void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *) {}
void
VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) {
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,9 @@ DEF_TRAVERSE_TYPE(CountAttributedType, {
DEF_TRAVERSE_TYPE(BTFTagAttributedType,
{ TRY_TO(TraverseType(T->getWrappedType())); })

DEF_TRAVERSE_TYPE(HLSLAttributedResourceType,
{ TRY_TO(TraverseType(T->getWrappedType())); })

DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })

DEF_TRAVERSE_TYPE(MacroQualifiedType,
Expand Down Expand Up @@ -1445,6 +1448,9 @@ DEF_TRAVERSE_TYPELOC(CountAttributedType,
DEF_TRAVERSE_TYPELOC(BTFTagAttributedType,
{ TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); })

DEF_TRAVERSE_TYPELOC(HLSLAttributedResourceType,
{ TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); })

DEF_TRAVERSE_TYPELOC(ElaboratedType, {
if (TL.getQualifierLoc()) {
TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));
Expand Down
51 changes: 51 additions & 0 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
#include "llvm/Support/TrailingObjects.h"
Expand Down Expand Up @@ -6156,6 +6157,54 @@ class BTFTagAttributedType : public Type, public llvm::FoldingSetNode {
}
};

class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode {
public:
struct Attributes {
// Data gathered from HLSL resource attributes
llvm::dxil::ResourceClass ResourceClass;
uint8_t IsROV : 1;
Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV)
: ResourceClass(ResourceClass), IsROV(IsROV) {}
Attributes() : ResourceClass(llvm::dxil::ResourceClass::UAV), IsROV(0) {}
};

private:
friend class ASTContext; // ASTContext creates these

QualType WrappedType;
QualType ContainedType;
const Attributes Attrs;

HLSLAttributedResourceType(QualType Canon, QualType Wrapped,
QualType Contained, const Attributes &Attrs)
: Type(HLSLAttributedResource, Canon, Wrapped->getDependence()),
WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}

public:
QualType getWrappedType() const { return WrappedType; }
QualType getContainedType() const { return ContainedType; }
const Attributes &getAttrs() const { return Attrs; }

bool isSugared() const { return true; }
QualType desugar() const { return getWrappedType(); }

void Profile(llvm::FoldingSetNodeID &ID) {
Profile(ID, WrappedType, ContainedType, Attrs);
}

static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped,
QualType Contained, const Attributes &Attrs) {
ID.AddPointer(Wrapped.getAsOpaquePtr());
ID.AddPointer(Contained.getAsOpaquePtr());
ID.AddInteger(static_cast<uint32_t>(Attrs.ResourceClass));
ID.AddBoolean(Attrs.IsROV);
}

static bool classof(const Type *T) {
return T->getTypeClass() == HLSLAttributedResource;
}
};

class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
friend class ASTContext; // ASTContext creates these

Expand Down Expand Up @@ -8579,6 +8628,8 @@ template <typename T> const T *Type::getAsAdjusted() const {
Ty = A->getModifiedType().getTypePtr();
else if (const auto *A = dyn_cast<BTFTagAttributedType>(Ty))
Ty = A->getWrappedType().getTypePtr();
else if (const auto *A = dyn_cast<HLSLAttributedResourceType>(Ty))
Ty = A->getWrappedType().getTypePtr();
else if (const auto *E = dyn_cast<ElaboratedType>(Ty))
Ty = E->desugar().getTypePtr();
else if (const auto *P = dyn_cast<ParenType>(Ty))
Expand Down
21 changes: 21 additions & 0 deletions clang/include/clang/AST/TypeLoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,25 @@ class BTFTagAttributedTypeLoc
QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
};

struct HLSLAttributedResourceLocInfo {
SourceRange Range;
};

/// Type source information for HLSL attributed resource type.
class HLSLAttributedResourceTypeLoc
: public ConcreteTypeLoc<UnqualTypeLoc, HLSLAttributedResourceTypeLoc,
HLSLAttributedResourceType,
HLSLAttributedResourceLocInfo> {
public:
TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
void setSourceRange(const SourceRange &R) { getLocalData()->Range = R; }
SourceRange getLocalSourceRange() const { return getLocalData()->Range; }
void initializeLocal(ASTContext &Context, SourceLocation loc) {
setSourceRange(SourceRange());
}
QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
};

struct ObjCObjectTypeLocInfo {
SourceLocation TypeArgsLAngleLoc;
SourceLocation TypeArgsRAngleLoc;
Expand Down Expand Up @@ -2690,6 +2709,8 @@ inline T TypeLoc::getAsAdjusted() const {
Cur = ATL.getModifiedLoc();
else if (auto ATL = Cur.getAs<BTFTagAttributedTypeLoc>())
Cur = ATL.getWrappedLoc();
else if (auto ATL = Cur.getAs<HLSLAttributedResourceTypeLoc>())
Cur = ATL.getWrappedLoc();
else if (auto ETL = Cur.getAs<ElaboratedTypeLoc>())
Cur = ETL.getNamedTypeLoc();
else if (auto ATL = Cur.getAs<AdjustedTypeLoc>())
Expand Down
19 changes: 19 additions & 0 deletions clang/include/clang/AST/TypeProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,25 @@ let Class = BTFTagAttributedType in {
}]>;
}

let Class = HLSLAttributedResourceType in {
def : Property<"resClass", UInt32> {
let Read = [{ static_cast<uint32_t>(node->getAttrs().ResourceClass) }];
}
def : Property<"isROV", Bool> {
let Read = [{ node->getAttrs().IsROV }];
}
def : Property<"wrappedTy", QualType> {
let Read = [{ node->getWrappedType() }];
}
def : Property<"containedTy", QualType> {
let Read = [{ node->getContainedType() }];
}
def : Creator<[{
HLSLAttributedResourceType::Attributes attrs(static_cast<llvm::dxil::ResourceClass>(resClass), isROV);
return ctx.getHLSLAttributedResourceType(wrappedTy, containedTy, attrs);
}]>;
}

let Class = DependentAddressSpaceType in {
def : Property<"pointeeType", QualType> {
let Read = [{ node->getPointeeType() }];
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Builtins.td
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,7 @@ def IsoVolatileStore : MSLangBuiltin, Int8_16_32_64Template {

def Noop : MSLangBuiltin {
let Spellings = ["__noop"];
let Attributes = [NoThrow];
let Attributes = [NoThrow, Constexpr];
let Prototype = "int(...)";
}

Expand Down
Loading

0 comments on commit dc0a164

Please sign in to comment.