Skip to content

Commit

Permalink
Resolve compiler warnings on Linux and macOS (microsoft#1628)
Browse files Browse the repository at this point in the history
* Removed unused functions and fields
* Turned off switch enumeration value not handled warnings
* Fixed initialization issues
  • Loading branch information
antiagainst authored Oct 25, 2018
1 parent 35dd1b7 commit efb4557
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 135 deletions.
1 change: 1 addition & 0 deletions cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )

append_if(LLVM_ENABLE_PEDANTIC "-pedantic -Wno-long-long" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
# add_flag_if_supported("-Wcovered-switch-default" COVERED_SWITCH_DEFAULT_FLAG) # HLSL Change
append("-Wno-switch" CMAKE_CXX_FLAGS) # HLSL Change
append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)

Expand Down
6 changes: 3 additions & 3 deletions include/dxc/HLSL/DxilRuntimeReflection.inl
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ DxilRuntimeReflection_impl::AddResource(const ResourceReader &resourceReader) {
assert(m_Resources.size() < m_Resources.capacity() && "Otherwise, number of resources was incorrect");
if (!(m_Resources.size() < m_Resources.capacity()))
return nullptr;
m_Resources.emplace_back(DxilResourceDesc({0}));
m_Resources.emplace_back(DxilResourceDesc({}));
DxilResourceDesc &resource = m_Resources.back();
resource.Class = (uint32_t)resourceReader.GetResourceClass();
resource.Kind = (uint32_t)resourceReader.GetResourceKind();
Expand Down Expand Up @@ -432,7 +432,7 @@ DxilRuntimeReflection_impl::AddFunction(const FunctionReader &functionReader) {
assert(m_Functions.size() < m_Functions.capacity() && "Otherwise, number of functions was incorrect");
if (!(m_Functions.size() < m_Functions.capacity()))
return nullptr;
m_Functions.emplace_back(DxilFunctionDesc({0}));
m_Functions.emplace_back(DxilFunctionDesc({}));
DxilFunctionDesc &function = m_Functions.back();
function.Name = GetWideString(functionReader.GetName());
function.UnmangledName = GetWideString(functionReader.GetUnmangledName());
Expand Down Expand Up @@ -467,7 +467,7 @@ DxilSubobjectDesc *DxilRuntimeReflection_impl::AddSubobject(const SubobjectReade
assert(m_Subobjects.size() < m_Subobjects.capacity() && "Otherwise, number of subobjects was incorrect");
if (!(m_Subobjects.size() < m_Subobjects.capacity()))
return nullptr;
m_Subobjects.emplace_back(DxilSubobjectDesc({0}));
m_Subobjects.emplace_back(DxilSubobjectDesc({}));
DxilSubobjectDesc &subobject = m_Subobjects.back();
subobject.Name = GetWideString(subobjectReader.GetName());
subobject.Kind = (uint32_t)subobjectReader.GetKind();
Expand Down
2 changes: 1 addition & 1 deletion lib/DXIL/DxilShaderFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ ShaderFlags::ShaderFlags():
, m_bTiledResources(false)
, m_bUAVLoadAdditionalFormats(false)
, m_bLevel9ComparisonFiltering(false)
, m_bCSRawAndStructuredViaShader4X(false)
, m_b64UAVs(false)
, m_UAVsAtEveryStage(false)
, m_bCSRawAndStructuredViaShader4X(false)
, m_bROVS(false)
, m_bWaveOps(false)
, m_bInt64Ops(false)
Expand Down
3 changes: 1 addition & 2 deletions lib/DxilContainer/DxilContainerAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,8 @@ class StringBufferPart : public RDATPart {
private:
StringMap<uint32_t> m_StringMap;
SmallVector<char, 256> m_StringBuffer;
uint32_t curIndex;
public:
StringBufferPart() : m_StringMap(), m_StringBuffer(), curIndex(0) {
StringBufferPart() : m_StringMap(), m_StringBuffer() {
// Always start string table with null so empty/null strings have offset of zero
m_StringBuffer.push_back('\0');
}
Expand Down
19 changes: 0 additions & 19 deletions lib/DxrFallback/StateFunctionTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ static std::string stripSuffix(StringRef name, StringRef suffix)
}


static std::string stripAfter(StringRef name, StringRef suffixStart)
{
size_t pos = name.find(suffixStart);
if (pos != name.npos)
return name.substr(0, pos).str();
else
return name.str();
}


// Insert str before the final "." in filename.
static std::string insertBeforeExtension(const std::string& filename, const std::string& str)
{
Expand Down Expand Up @@ -1285,15 +1275,6 @@ void StateFunctionTransform::rewriteDummyStackSize(uint64_t frameSizeInBytes)
m_stackFrameSizeVal = frameSizeVal;
}

static inline Value* toIntIndex(int offsetInBytes, Value* baseOffset, Instruction* insertBefore)
{
assert(offsetInBytes % sizeof(int) == 0);
Value* intIndex = makeInt32(offsetInBytes / sizeof(int), insertBefore->getContext());
if (baseOffset)
intIndex = BinaryOperator::Create(Instruction::Add, intIndex, baseOffset, "", insertBefore);
return intIndex;
}

void StateFunctionTransform::createStackStore(Value* baseOffset, Value* val, int offsetInBytes, Instruction* insertBefore)
{
assert(offsetInBytes % sizeof(int) == 0);
Expand Down
103 changes: 0 additions & 103 deletions lib/HLSL/DxilCondenseResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,109 +323,6 @@ void PatchLowerBoundOfCreateHandle(CallInst *handle, DxilModule &DM) {
}
}

static void PatchTBufferCreateHandle(CallInst *handle, DxilModule &DM, std::unordered_set<unsigned> &tbufferIDs) {
DxilInst_CreateHandle createHandle(handle);
DXASSERT_NOMSG(createHandle);

DXIL::ResourceClass ResClass = static_cast<DXIL::ResourceClass>(createHandle.get_resourceClass_val());
if (ResClass != DXIL::ResourceClass::CBuffer)
return;

Value *resID = createHandle.get_rangeId();
DXASSERT(isa<ConstantInt>(resID), "cannot handle dynamic resID for cbuffer CreateHandle");
if (!isa<ConstantInt>(resID))
return;

unsigned rangeId = cast<ConstantInt>(resID)->getLimitedValue();
DxilResourceBase *res = &DM.GetCBuffer(rangeId);

// For TBuffer, we need to switch resource type from CBuffer to SRV
if (res->GetKind() == DXIL::ResourceKind::TBuffer) {
// Track cbuffers IDs that are actually tbuffers
tbufferIDs.insert(rangeId);
hlsl::OP *hlslOP = DM.GetOP();
llvm::LLVMContext &Ctx = DM.GetCtx();

// Temporarily add SRV size to rangeID to guarantee unique new SRV ID
Value *newRangeID = hlslOP->GetU32Const(rangeId + DM.GetSRVs().size());
handle->setArgOperand(DXIL::OperandIndex::kCreateHandleResIDOpIdx,
newRangeID);
// switch create handle to SRV
handle->setArgOperand(DXIL::OperandIndex::kCreateHandleResClassOpIdx,
hlslOP->GetU8Const(
static_cast<std::underlying_type<DxilResourceBase::Class>::type>(
DXIL::ResourceClass::SRV)));

Type *doubleTy = Type::getDoubleTy(Ctx);
Type *i64Ty = Type::getInt64Ty(Ctx);

// Replace corresponding cbuffer loads with typed buffer loads
for (auto U = handle->user_begin(); U != handle->user_end(); ) {
CallInst *I = cast<CallInst>(*(U++));
DXASSERT(I && OP::IsDxilOpFuncCallInst(I), "otherwise unexpected user of CreateHandle value");
DXIL::OpCode opcode = OP::GetDxilOpFuncCallInst(I);
if (opcode == DXIL::OpCode::CBufferLoadLegacy) {
DxilInst_CBufferLoadLegacy cbLoad(I);

// Replace with appropriate buffer load instruction
IRBuilder<> Builder(I);
opcode = OP::OpCode::BufferLoad;
Type *Ty = Type::getInt32Ty(Ctx);
Function *BufLoad = hlslOP->GetOpFunc(opcode, Ty);
Constant *opArg = hlslOP->GetU32Const((unsigned)opcode);
Value *undefI = UndefValue::get(Type::getInt32Ty(Ctx));
Value *offset = cbLoad.get_regIndex();
CallInst* load = Builder.CreateCall(BufLoad, {opArg, handle, offset, undefI});

// Find extractelement uses of cbuffer load and replace + generate bitcast as necessary
for (auto LU = I->user_begin(); LU != I->user_end(); ) {
ExtractValueInst *evInst = dyn_cast<ExtractValueInst>(*(LU++));
DXASSERT(evInst && evInst->getNumIndices() == 1, "user of cbuffer load result should be extractvalue");
uint64_t idx = evInst->getIndices()[0];
Type *EltTy = evInst->getType();
IRBuilder<> EEBuilder(evInst);
Value *result = nullptr;
if (EltTy != Ty) {
// extract two values and DXIL::OpCode::MakeDouble or construct i64
if ((EltTy == doubleTy) || (EltTy == i64Ty)) {
DXASSERT(idx < 2, "64-bit component index out of range");

// This assumes big endian order in tbuffer elements (is this correct?)
Value *low = EEBuilder.CreateExtractValue(load, idx * 2);
Value *high = EEBuilder.CreateExtractValue(load, idx * 2 + 1);
if (EltTy == doubleTy) {
opcode = OP::OpCode::MakeDouble;
Function *MakeDouble = hlslOP->GetOpFunc(opcode, doubleTy);
Constant *opArg = hlslOP->GetU32Const((unsigned)opcode);
result = EEBuilder.CreateCall(MakeDouble, {opArg, low, high});
} else {
high = EEBuilder.CreateZExt(high, i64Ty);
low = EEBuilder.CreateZExt(low, i64Ty);
high = EEBuilder.CreateShl(high, hlslOP->GetU64Const(32));
result = EEBuilder.CreateOr(high, low);
}
} else {
result = EEBuilder.CreateExtractValue(load, idx);
result = EEBuilder.CreateBitCast(result, EltTy);
}
} else {
result = EEBuilder.CreateExtractValue(load, idx);
}

evInst->replaceAllUsesWith(result);
evInst->eraseFromParent();
}
} else if (opcode == DXIL::OpCode::CBufferLoad) {
// TODO: Handle this, or prevent this for tbuffer
DXASSERT(false, "otherwise CBufferLoad used for tbuffer rather than CBufferLoadLegacy");
} else {
DXASSERT(false, "otherwise unexpected user of CreateHandle value");
}
I->eraseFromParent();
}
}
}

}

void DxilCondenseResources::PatchCreateHandle(DxilModule &DM) {
Expand Down
2 changes: 1 addition & 1 deletion lib/HLSL/DxilPatchShaderRecordBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ void DxilPatchShaderRecordBindings::InitializeViewTable() {
// manually add it to the list of UAV register spaces used
if (*pInputShaderInfo->pNumUAVSpaces == 0)
{
ViewKey key = { (unsigned int)hlsl::DXIL::ResourceKind::RawBuffer, 0 };
ViewKey key = { (unsigned int)hlsl::DXIL::ResourceKind::RawBuffer, {0} };
unsigned int index = FindOrInsertViewIntoList(
key,
pInputShaderInfo->pUAVRegisterSpaceArray,
Expand Down
2 changes: 0 additions & 2 deletions lib/HLSL/DxilValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2347,8 +2347,6 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
const unsigned uglobal =
static_cast<unsigned>(DXIL::BarrierMode::UAVFenceGlobal);
const unsigned g = static_cast<unsigned>(DXIL::BarrierMode::TGSMFence);
const unsigned t =
static_cast<unsigned>(DXIL::BarrierMode::SyncThreadGroup);
const unsigned ut =
static_cast<unsigned>(DXIL::BarrierMode::UAVFenceThreadGroup);
unsigned barrierMode = cMode->getLimitedValue();
Expand Down
7 changes: 4 additions & 3 deletions lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,8 @@ static Value *CoerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy,
return IRB.CreateBitCast(StoredVal, LoadedTy, "bitcast");
}

#if 0 // HLSL Change: Don't support bitcasting to different sizes.

/// This function is called when we have a
/// memdep query of a load that ends up being a clobbering memory write (store,
/// memset, memcpy, memmove). This means that the write *may* provide bits used
Expand All @@ -955,8 +957,6 @@ static int AnalyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr,
Value *WritePtr,
uint64_t WriteSizeInBits,
const DataLayout &DL) {
#if 0 // HLSL Change: Don't support bitcasting to different sizes.

// If the loaded or stored value is a first class array or struct, don't try
// to transform them. We need to be able to bitcast to integer.
if (LoadTy->isStructTy() || LoadTy->isArrayTy())
Expand Down Expand Up @@ -1024,10 +1024,11 @@ static int AnalyzeLoadFromClobberingWrite(Type *LoadTy, Value *LoadPtr,
// Okay, we can do this transformation. Return the number of bytes into the
// store that the load is.
return LoadOffset-StoreOffset;
#endif // HLSL Change: Don't support bitcasting to different sizes.
return -1;
}

#endif // HLSL Change: Don't support bitcasting to different sizes.

/// This function is called when we have a
/// memdep query of a load that ends up being a clobbering store.
static int AnalyzeLoadFromClobberingStore(Type *LoadTy, Value *LoadPtr,
Expand Down
1 change: 0 additions & 1 deletion tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7824,7 +7824,6 @@ bool HLSLExternalSource::CanConvert(
_Out_opt_ TYPE_CONVERSION_REMARKS* remarks,
_Inout_opt_ StandardConversionSequence* standard)
{
bool bCheckElt = false;
UINT uTSize, uSSize;

DXASSERT_NOMSG(sourceExpr != nullptr);
Expand Down

0 comments on commit efb4557

Please sign in to comment.