Skip to content

Commit

Permalink
[NFC] Remove SAL annotations from internal APIs (#5639)
Browse files Browse the repository at this point in the history
We don't keep these annotations up to date or rely on them, so to
simplify our platform layering and ease code formatting this change
removes all the SAL annotations from internal APIs. This change also
replaces most `_Analysis_Assme_(...)` annotations with `assert(...)`.

One `_Analysis_Assume_` in ParseDecl.cpp needed to be updated because it
was incorrect. The code was `_Analysis_Assume_(assert(name.size() >
sizeof("space"));`. When converted to an `assert` it fired in our test
suite because the sizeof a string literal includes the null terminator,
but the size of a StringRef does not.

A few of the `_Analysis_Assume_` annotations were removed because they
didn't make sense (like the ones inside the `DXASSERT` implementation,
and a few others were removed to avoid introducing additional header or
linkage dependencies.

This change does not introduce any functional or behavioral changes.
  • Loading branch information
llvm-beanz authored Sep 14, 2023
1 parent d2882d8 commit 3266a87
Show file tree
Hide file tree
Showing 170 changed files with 3,714 additions and 4,522 deletions.
15 changes: 10 additions & 5 deletions include/dxc/DxilContainer/DxcContainerBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ namespace hlsl {

class DxcContainerBuilder : public IDxcContainerBuilder {
public:
HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) override; // Loads DxilContainer to the builder
HRESULT STDMETHODCALLTYPE AddPart(_In_ UINT32 fourCC, _In_ IDxcBlob *pSource) override; // Add the given part with fourCC
HRESULT STDMETHODCALLTYPE RemovePart(_In_ UINT32 fourCC) override; // Remove the part with fourCC
HRESULT STDMETHODCALLTYPE SerializeContainer(_Out_ IDxcOperationResult **ppResult) override; // Builds a container of the given container builder state
// Loads DxilContainer to the builder
HRESULT STDMETHODCALLTYPE Load(IDxcBlob *pDxilContainerHeader) override;
// Add the given part with fourCC
HRESULT STDMETHODCALLTYPE AddPart(UINT32 fourCC, IDxcBlob *pSource) override;
// Remove the part with fourCC
HRESULT STDMETHODCALLTYPE RemovePart(UINT32 fourCC) override;
// Builds a container of the given container builder state
HRESULT STDMETHODCALLTYPE
SerializeContainer(IDxcOperationResult **ppResult) override;

DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL()
DXC_MICROCOM_TM_CTOR(DxcContainerBuilder)
Expand Down Expand Up @@ -65,4 +70,4 @@ class DxcContainerBuilder : public IDxcContainerBuilder {
HRESULT UpdateOffsetTable(AbstractMemoryStream *pStream);
HRESULT UpdateParts(AbstractMemoryStream *pStream);
void AddPart(DxilPart&& part);
};
};
7 changes: 4 additions & 3 deletions include/dxc/DxilContainer/DxilContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ const DxilProgramHeader *
GetDxilProgramHeader(const DxilContainerHeader *pHeader, DxilFourCC fourCC);

/// Initializes container with the specified values.
void InitDxilContainer(_Out_ DxilContainerHeader *pHeader, uint32_t partCount,
void InitDxilContainer(DxilContainerHeader *pHeader, uint32_t partCount,
uint32_t containerSizeInBytes);

/// Checks whether pHeader claims by signature to be a DXIL container
Expand Down Expand Up @@ -587,7 +587,8 @@ inline bool IsDxilShaderDebugNameValid(const DxilPartHeader *pPart) {
}

inline bool GetDxilShaderDebugName(const DxilPartHeader *pDebugNamePart,
const char **ppUtf8Name, _Out_opt_ uint16_t *pUtf8NameLen) {
const char **ppUtf8Name,
uint16_t *pUtf8NameLen) {
*ppUtf8Name = nullptr;
if (!IsDxilShaderDebugNameValid(pDebugNamePart)) {
return false;
Expand Down Expand Up @@ -627,7 +628,7 @@ inline SerializeDxilFlags operator~(SerializeDxilFlags l) {
void CreateDxcContainerReflection(IDxcContainerReflection **ppResult);

// Converts uint32_t partKind to char array object.
inline char * PartKindToCharArray(uint32_t partKind, _Out_writes_(5) char* pText) {
inline char *PartKindToCharArray(uint32_t partKind, char *pText) {
pText[0] = (char)((partKind & 0x000000FF) >> 0);
pText[1] = (char)((partKind & 0x0000FF00) >> 8);
pText[2] = (char)((partKind & 0x00FF0000) >> 16);
Expand Down
13 changes: 7 additions & 6 deletions include/dxc/DxilContainer/DxilContainerReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ namespace hlsl {
// Minor = DXBC_MAJOR_VERSION
//
// Returns S_OK or E_FAIL
HRESULT Load(_In_ const void* pContainer, _In_ uint32_t containerSizeInBytes);
HRESULT Load(const void *pContainer, uint32_t containerSizeInBytes);

HRESULT GetVersion(_Out_ DxilContainerVersion *pResult);
HRESULT GetPartCount(_Out_ uint32_t *pResult);
HRESULT GetPartContent(uint32_t idx, _Outptr_ const void **ppResult, _Out_ uint32_t *pResultSize = nullptr);
HRESULT GetPartFourCC(uint32_t idx, _Out_ uint32_t *pResult);
HRESULT FindFirstPartKind(uint32_t kind, _Out_ uint32_t *pResult);
HRESULT GetVersion(DxilContainerVersion *pResult);
HRESULT GetPartCount(uint32_t *pResult);
HRESULT GetPartContent(uint32_t idx, const void **ppResult,
uint32_t *pResultSize = nullptr);
HRESULT GetPartFourCC(uint32_t idx, uint32_t *pResult);
HRESULT FindFirstPartKind(uint32_t kind, uint32_t *pResult);

private:
const void* m_pContainer = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions include/dxc/DxilContainer/DxilPipelineStateValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct PSVStringTable {
PSVStringTable() : Table(nullptr), Size(0) {}
PSVStringTable(const char *table, uint32_t size) : Table(table), Size(size) {}
const char *Get(uint32_t offset) const {
_Analysis_assume_(offset < Size && Table && Table[Size-1] == '\0');
assert(offset < Size && Table && Table[Size - 1] == '\0');
return Table + offset;
}
};
Expand Down Expand Up @@ -279,7 +279,7 @@ struct PSVSemanticIndexTable {
PSVSemanticIndexTable() : Table(nullptr), Entries(0) {}
PSVSemanticIndexTable(const uint32_t *table, uint32_t entries) : Table(table), Entries(entries) {}
const uint32_t *Get(uint32_t offset) const {
_Analysis_assume_(offset < Entries && Table);
assert(offset < Entries && Table);
return Table + offset;
}
};
Expand Down Expand Up @@ -526,7 +526,7 @@ class DxilPipelineStateValidation
_T *GetRecord(void *pRecords, uint32_t recordSize, uint32_t numRecords,
uint32_t index) const {
if (pRecords && index < numRecords && sizeof(_T) <= recordSize) {
__analysis_assume((size_t)index * (size_t)recordSize <= UINT_MAX);
assert((size_t)index * (size_t)recordSize <= UINT_MAX);
return reinterpret_cast<_T *>(reinterpret_cast<uint8_t *>(pRecords) +
(index * recordSize));
}
Expand Down
4 changes: 0 additions & 4 deletions include/dxc/DxilContainer/DxilRuntimeReflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ class StringTableReader {
m_size = size;
}
const char *Get(uint32_t offset) const {
_Analysis_assume_(offset < m_size && m_table &&
m_table[m_size - 1] == '\0');
(void)m_size; // avoid unused private warning if use above is ignored.
return m_table + offset;
}
Expand All @@ -224,8 +222,6 @@ class RawBytesReader {
}
uint32_t Size() const { return m_size; }
const void *Get(uint32_t offset) const {
_Analysis_assume_(offset < m_size && m_table);
(void)m_size; // avoid unused private warning if use above is ignored.
return (const void*)(((const char*)m_table) + offset);
}
};
Expand Down
38 changes: 18 additions & 20 deletions include/dxc/DxilRootSignature/DxilRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ struct DxilDescriptorRange {
};
struct DxilRootDescriptorTable {
uint32_t NumDescriptorRanges;
_Field_size_full_(NumDescriptorRanges) DxilDescriptorRange *pDescriptorRanges;
DxilDescriptorRange *pDescriptorRanges;
};
struct DxilRootConstants {
uint32_t ShaderRegister;
Expand Down Expand Up @@ -280,7 +280,7 @@ struct DxilDescriptorRange1 {
};
struct DxilRootDescriptorTable1 {
uint32_t NumDescriptorRanges;
_Field_size_full_(NumDescriptorRanges) DxilDescriptorRange1 *pDescriptorRanges;
DxilDescriptorRange1 *pDescriptorRanges;
};
struct DxilRootParameter1 {
DxilRootParameterType ParameterType;
Expand All @@ -293,9 +293,9 @@ struct DxilRootParameter1 {
};
struct DxilRootSignatureDesc {
uint32_t NumParameters;
_Field_size_full_(NumParameters) DxilRootParameter *pParameters;
DxilRootParameter *pParameters;
uint32_t NumStaticSamplers;
_Field_size_full_(NumStaticSamplers) DxilStaticSamplerDesc *pStaticSamplers;
DxilStaticSamplerDesc *pStaticSamplers;
DxilRootSignatureFlags Flags;
};
struct DxilStaticSamplerDesc {
Expand All @@ -315,9 +315,9 @@ struct DxilStaticSamplerDesc {
};
struct DxilRootSignatureDesc1 {
uint32_t NumParameters;
_Field_size_full_(NumParameters) DxilRootParameter1 *pParameters;
DxilRootParameter1 *pParameters;
uint32_t NumStaticSamplers;
_Field_size_full_(NumStaticSamplers) DxilStaticSamplerDesc *pStaticSamplers;
DxilStaticSamplerDesc *pStaticSamplers;
DxilRootSignatureFlags Flags;
};
struct DxilVersionedRootSignatureDesc {
Expand Down Expand Up @@ -365,25 +365,23 @@ void ConvertRootSignature(const DxilVersionedRootSignatureDesc* pRootSignatureIn
DxilRootSignatureVersion RootSignatureVersionOut,
const DxilVersionedRootSignatureDesc ** ppRootSignatureOut);

void SerializeRootSignature(const DxilVersionedRootSignatureDesc *pRootSignature,
_Outptr_ IDxcBlob **ppBlob, _Outptr_ IDxcBlobEncoding **ppErrorBlob,
bool bAllowReservedRegisterSpace);
void SerializeRootSignature(
const DxilVersionedRootSignatureDesc *pRootSignature, IDxcBlob **ppBlob,
IDxcBlobEncoding **ppErrorBlob, bool bAllowReservedRegisterSpace);

void DeserializeRootSignature(_In_reads_bytes_(SrcDataSizeInBytes) const void *pSrcData,
_In_ uint32_t SrcDataSizeInBytes,
_Out_ const DxilVersionedRootSignatureDesc **ppRootSignature);
void DeserializeRootSignature(
const void *pSrcData, uint32_t SrcDataSizeInBytes,
const DxilVersionedRootSignatureDesc **ppRootSignature);

// Takes PSV - pipeline state validation data, not shader container.
bool VerifyRootSignatureWithShaderPSV(_In_ const DxilVersionedRootSignatureDesc *pDesc,
_In_ DXIL::ShaderKind ShaderKind,
_In_reads_bytes_(PSVSize) const void *pPSVData,
_In_ uint32_t PSVSize,
_In_ llvm::raw_ostream &DiagStream);
bool VerifyRootSignatureWithShaderPSV(
const DxilVersionedRootSignatureDesc *pDesc, DXIL::ShaderKind ShaderKind,
const void *pPSVData, uint32_t PSVSize, llvm::raw_ostream &DiagStream);

// standalone verification
bool VerifyRootSignature(_In_ const DxilVersionedRootSignatureDesc *pDesc,
_In_ llvm::raw_ostream &DiagStream,
_In_ bool bAllowReservedRegisterSpace);
bool VerifyRootSignature(const DxilVersionedRootSignatureDesc *pDesc,
llvm::raw_ostream &DiagStream,
bool bAllowReservedRegisterSpace);

class DxilVersionedRootSignature {
DxilVersionedRootSignatureDesc *m_pRootSignature;
Expand Down
77 changes: 33 additions & 44 deletions include/dxc/HLSL/DxilValidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,77 +29,66 @@ namespace hlsl {
#include "dxc/HLSL/DxilValidation.inc"

const char *GetValidationRuleText(ValidationRule value);
void GetValidationVersion(_Out_ unsigned *pMajor, _Out_ unsigned *pMinor);
HRESULT ValidateDxilModule(_In_ llvm::Module *pModule,
_In_opt_ llvm::Module *pDebugModule);
void GetValidationVersion(unsigned *pMajor, unsigned *pMinor);
HRESULT ValidateDxilModule(llvm::Module *pModule, llvm::Module *pDebugModule);

// DXIL Container Verification Functions (return false on failure)

bool VerifySignatureMatches(_In_ llvm::Module *pModule,
bool VerifySignatureMatches(llvm::Module *pModule,
hlsl::DXIL::SignatureKind SigKind,
_In_reads_bytes_(SigSize) const void *pSigData,
_In_ uint32_t SigSize);
const void *pSigData, uint32_t SigSize);

// PSV = data for Pipeline State Validation
bool VerifyPSVMatches(_In_ llvm::Module *pModule,
_In_reads_bytes_(PSVSize) const void *pPSVData,
_In_ uint32_t PSVSize);
bool VerifyPSVMatches(llvm::Module *pModule, const void *pPSVData,
uint32_t PSVSize);

// PSV = data for Pipeline State Validation
bool VerifyRDATMatches(_In_ llvm::Module *pModule,
_In_reads_bytes_(RDATSize) const void *pRDATData,
_In_ uint32_t RDATSize);
bool VerifyRDATMatches(llvm::Module *pModule, const void *pRDATData,
uint32_t RDATSize);

bool VerifyFeatureInfoMatches(_In_ llvm::Module *pModule,
_In_reads_bytes_(FeatureInfoSize) const void *pFeatureInfoData,
_In_ uint32_t FeatureInfoSize);
bool VerifyFeatureInfoMatches(llvm::Module *pModule,
const void *pFeatureInfoData,
uint32_t FeatureInfoSize);

// Validate the container parts, assuming supplied module is valid, loaded from the container provided
struct DxilContainerHeader;
HRESULT ValidateDxilContainerParts(_In_ llvm::Module *pModule,
_In_opt_ llvm::Module *pDebugModule,
_In_reads_bytes_(ContainerSize) const DxilContainerHeader *pContainer,
_In_ uint32_t ContainerSize);
HRESULT ValidateDxilContainerParts(llvm::Module *pModule,
llvm::Module *pDebugModule,
const DxilContainerHeader *pContainer,
uint32_t ContainerSize);

// Loads module, validating load, but not module.
HRESULT ValidateLoadModule(_In_reads_bytes_(ILLength) const char *pIL,
_In_ uint32_t ILLength,
_In_ std::unique_ptr<llvm::Module> &pModule,
_In_ llvm::LLVMContext &Ctx,
_In_ llvm::raw_ostream &DiagStream,
_In_ unsigned bLazyLoad);
HRESULT ValidateLoadModule(const char *pIL, uint32_t ILLength,
std::unique_ptr<llvm::Module> &pModule,
llvm::LLVMContext &Ctx,
llvm::raw_ostream &DiagStream, unsigned bLazyLoad);

// Loads module from container, validating load, but not module.
HRESULT ValidateLoadModuleFromContainer(
_In_reads_bytes_(ContainerSize) const void *pContainer,
_In_ uint32_t ContainerSize, _In_ std::unique_ptr<llvm::Module> &pModule,
_In_ std::unique_ptr<llvm::Module> &pDebugModule,
_In_ llvm::LLVMContext &Ctx, llvm::LLVMContext &DbgCtx,
_In_ llvm::raw_ostream &DiagStream);
const void *pContainer, uint32_t ContainerSize,
std::unique_ptr<llvm::Module> &pModule,
std::unique_ptr<llvm::Module> &pDebugModule, llvm::LLVMContext &Ctx,
llvm::LLVMContext &DbgCtx, llvm::raw_ostream &DiagStream);
// Lazy loads module from container, validating load, but not module.
HRESULT ValidateLoadModuleFromContainerLazy(
_In_reads_bytes_(ContainerSize) const void *pContainer,
_In_ uint32_t ContainerSize, _In_ std::unique_ptr<llvm::Module> &pModule,
_In_ std::unique_ptr<llvm::Module> &pDebugModule,
_In_ llvm::LLVMContext &Ctx, llvm::LLVMContext &DbgCtx,
_In_ llvm::raw_ostream &DiagStream);
const void *pContainer, uint32_t ContainerSize,
std::unique_ptr<llvm::Module> &pModule,
std::unique_ptr<llvm::Module> &pDebugModule, llvm::LLVMContext &Ctx,
llvm::LLVMContext &DbgCtx, llvm::raw_ostream &DiagStream);

// Load and validate Dxil module from bitcode.
HRESULT ValidateDxilBitcode(_In_reads_bytes_(ILLength) const char *pIL,
_In_ uint32_t ILLength,
_In_ llvm::raw_ostream &DiagStream);
HRESULT ValidateDxilBitcode(const char *pIL, uint32_t ILLength,
llvm::raw_ostream &DiagStream);

// Full container validation, including ValidateDxilModule
HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pContainer,
_In_ uint32_t ContainerSize,
_In_ llvm::raw_ostream &DiagStream);
HRESULT ValidateDxilContainer(const void *pContainer, uint32_t ContainerSize,
llvm::raw_ostream &DiagStream);

// Full container validation, including ValidateDxilModule, with debug module
HRESULT ValidateDxilContainer(_In_reads_bytes_(ContainerSize) const void *pContainer,
_In_ uint32_t ContainerSize,
HRESULT ValidateDxilContainer(const void *pContainer, uint32_t ContainerSize,
const void *pOptDebugBitcode,
uint32_t OptDebugBitcodeSize,
_In_ llvm::raw_ostream &DiagStream);
llvm::raw_ostream &DiagStream);

class PrintDiagnosticContext {
private:
Expand Down
Loading

0 comments on commit 3266a87

Please sign in to comment.