Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Wshadows fixes #3143

Closed
wants to merge 12 commits into from
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
add_compile_options(-Wall -Wmaybe-uninitialized -Wuninitialized -Wunused -Wunused-local-typedefs
-Wunused-parameter -Wunused-value -Wunused-variable -Wunused-but-set-parameter -Wunused-but-set-variable -fno-exceptions)
add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over.
# add_compile_options(-Wno-reorder) # disable this from -Wall, since it happens all over, but not required in Feb 2023.

add_compile_options(-Wshadow)

if(NOT ENABLE_RTTI)
add_compile_options(-fno-rtti)
endif()
Expand Down
62 changes: 31 additions & 31 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ class SpecConstantOpModeGuard {

struct OpDecorations {
public:
OpDecorations(spv::Decoration precision, spv::Decoration noContraction, spv::Decoration nonUniform) :
precision(precision)
OpDecorations(spv::Decoration in_precision, spv::Decoration in_noContraction, spv::Decoration in_nonUniform) :
precision(in_precision)
#ifndef GLSLANG_WEB
,
noContraction(noContraction),
nonUniform(nonUniform)
noContraction(in_noContraction),
nonUniform(in_nonUniform)
#endif
{ }

Expand Down Expand Up @@ -1551,16 +1551,16 @@ bool HasNonLayoutQualifiers(const glslang::TType& type, const glslang::TQualifie
//

TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
const glslang::TIntermediate* glslangIntermediate,
spv::SpvBuildLogger* buildLogger, glslang::SpvOptions& options) :
const glslang::TIntermediate* in_glslangIntermediate,
spv::SpvBuildLogger* buildLogger, glslang::SpvOptions& in_options) :
TIntermTraverser(true, false, true),
options(options),
options(in_options),
shaderEntry(nullptr), currentFunction(nullptr),
sequenceDepth(0), logger(buildLogger),
builder(spvVersion, (glslang::GetKhronosToolId() << 16) | glslang::GetSpirvGeneratorVersion(), logger),
inEntryPoint(false), entryPointTerminated(false), linkageOnly(false),
glslangIntermediate(glslangIntermediate),
nanMinMaxClamp(glslangIntermediate->getNanMinMaxClamp()),
glslangIntermediate(in_glslangIntermediate),
nanMinMaxClamp(in_glslangIntermediate->getNanMinMaxClamp()),
nonSemanticDebugPrintf(0),
taskPayloadID(0)
{
Expand Down Expand Up @@ -1936,13 +1936,13 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
const glslang::TSpirvExecutionMode spirvExecutionMode = glslangIntermediate->getSpirvExecutionMode();

// Add spirv_execution_mode
for (auto& mode : spirvExecutionMode.modes) {
if (!mode.second.empty()) {
for (auto& execution_mode : spirvExecutionMode.modes) {
if (!execution_mode.second.empty()) {
std::vector<unsigned> literals;
TranslateLiterals(mode.second, literals);
builder.addExecutionMode(shaderEntry, static_cast<spv::ExecutionMode>(mode.first), literals);
TranslateLiterals(execution_mode.second, literals);
builder.addExecutionMode(shaderEntry, static_cast<spv::ExecutionMode>(execution_mode.first), literals);
} else
builder.addExecutionMode(shaderEntry, static_cast<spv::ExecutionMode>(mode.first));
builder.addExecutionMode(shaderEntry, static_cast<spv::ExecutionMode>(execution_mode.first));
}

// Add spirv_execution_mode_id
Expand Down Expand Up @@ -2728,7 +2728,7 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI
else
op = glslang::EOpSub;

spv::Id result = createBinaryOperation(op, decorations,
result = createBinaryOperation(op, decorations,
convertGlslangToSpvType(node->getType()), operand, one,
node->getType().getBasicType());
assert(result != spv::NoResult);
Expand Down Expand Up @@ -3615,9 +3615,9 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
spv::Id typeId = builder.getContainedTypeId(builder.getTypeId(operands[0]));
assert(builder.isCooperativeMatrixType(typeId));
// do the op
spv::Id result = builder.createOp(spv::OpCooperativeMatrixLoadNV, typeId, idImmOps);
spv::Id createResult = builder.createOp(spv::OpCooperativeMatrixLoadNV, typeId, idImmOps);
// store the result to the pointer (out param 'm')
builder.createStore(result, operands[0]);
builder.createStore(createResult, operands[0]);
result = 0;
} else if (node->getOp() == glslang::EOpCooperativeMatrixStore) {
std::vector<spv::IdImmediate> idImmOps;
Expand Down Expand Up @@ -3766,11 +3766,11 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang
node->getType() == node->getFalseBlock()->getAsTyped()->getType());

// return true if a single operand to ? : is okay for OpSelect
const auto operandOkay = [](glslang::TIntermTyped* node) {
return node->getAsSymbolNode() || node->getType().getQualifier().isConstant();
const auto operandOkay = [](glslang::TIntermTyped* nodeOkay) {
return nodeOkay->getAsSymbolNode() || nodeOkay->getType().getQualifier().isConstant();
};

return operandOkay(node->getTrueBlock() ->getAsTyped()) &&
return operandOkay(node->getTrueBlock()->getAsTyped()) &&
operandOkay(node->getFalseBlock()->getAsTyped());
};

Expand Down Expand Up @@ -4733,8 +4733,8 @@ void TGlslangToSpvTraverser::decorateStructType(const glslang::TType& type,
// Add memory decorations only to top-level members of shader storage block
std::vector<spv::Decoration> memory;
TranslateMemoryDecoration(memberQualifier, memory, glslangIntermediate->usingVulkanMemoryModel());
for (unsigned int i = 0; i < memory.size(); ++i)
builder.addMemberDecoration(spvType, member, memory[i]);
for (unsigned int mi = 0; mi < memory.size(); ++mi)
builder.addMemberDecoration(spvType, member, memory[mi]);
}

#endif
Expand Down Expand Up @@ -5850,12 +5850,12 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
builder.addDecoration(pointer, spv::DecorationNonUniformEXT);
}

std::vector<spv::Id> operands;
operands.push_back(pointer);
std::vector<spv::Id> ids;
ids.push_back(pointer);
for (; opIt != arguments.end(); ++opIt)
operands.push_back(*opIt);
ids.push_back(*opIt);

return createAtomicOperation(node->getOp(), precision, resultType(), operands, typeProxy,
return createAtomicOperation(node->getOp(), precision, resultType(), ids, typeProxy,
lvalueCoherentFlags);
}
}
Expand Down Expand Up @@ -7878,8 +7878,8 @@ spv::Id TGlslangToSpvTraverser::createInvocationsOperation(glslang::TOperator op
}

for (auto opIt = operands.begin(); opIt != operands.end(); ++opIt) {
spv::IdImmediate op = { true, *opIt };
spvGroupOperands.push_back(op);
spv::IdImmediate operand = { true, *opIt };
spvGroupOperands.push_back(operand);
}

switch (op) {
Expand Down Expand Up @@ -9210,10 +9210,10 @@ spv::Id TGlslangToSpvTraverser::createNoArgOperation(glslang::TOperator op, spv:

spv::Id TGlslangToSpvTraverser::getSymbolId(const glslang::TIntermSymbol* symbol)
{
auto iter = symbolValues.find(symbol->getId());
auto symbol_iter = symbolValues.find(symbol->getId());
spv::Id id;
if (symbolValues.end() != iter) {
id = iter->second;
if (symbolValues.end() != symbol_iter) {
id = symbol_iter->second;
return id;
}

Expand Down
14 changes: 7 additions & 7 deletions SPIRV/SPVRemapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ namespace spv {
literal.reserve(16);

do {
spirword_t word = *pos;
spirword_t value = *pos;
for (int i = 0; i < 4; i++) {
char c = word & 0xff;
char c = value & 0xff;
if (c == '\0')
return literal;
literal += c;
word >>= 8;
value >>= 8;
}
pos++;
} while (true);
Expand Down Expand Up @@ -1113,10 +1113,10 @@ namespace spv {
process(
[&](spv::Op opCode, unsigned start) {
if (opCode == spv::Op::OpFunctionCall) {
const auto call_it = fnCalls.find(asId(start + 3));
if (call_it != fnCalls.end()) {
if (--call_it->second <= 0)
fnCalls.erase(call_it);
const auto itr = fnCalls.find(asId(start + 3));
if (itr != fnCalls.end()) {
if (--itr->second <= 0)
fnCalls.erase(itr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion SPIRV/SPVRemapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace spv {
class spirvbin_t : public spirvbin_base_t
{
public:
spirvbin_t(int verbose = 0) : entryPoint(spv::NoResult), largestNewId(0), verbose(verbose), errorLatch(false)
spirvbin_t(int in_verbose = 0) : entryPoint(spv::NoResult), largestNewId(0), verbose(in_verbose), errorLatch(false)
{ }

virtual ~spirvbin_t() { }
Expand Down
34 changes: 17 additions & 17 deletions SPIRV/SpvBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@

namespace spv {

Builder::Builder(unsigned int spvVersion, unsigned int magicNumber, SpvBuildLogger* buildLogger) :
spvVersion(spvVersion),
Builder::Builder(unsigned int in_spvVersion, unsigned int magicNumber, SpvBuildLogger* buildLogger) :
spvVersion(in_spvVersion),
sourceLang(SourceLanguageUnknown),
sourceVersion(0),
sourceFileStringId(NoResult),
Expand Down Expand Up @@ -1896,15 +1896,15 @@ void Builder::addDecoration(Id id, Decoration decoration, const std::vector<unsi
decorations.push_back(std::unique_ptr<Instruction>(dec));
}

void Builder::addDecoration(Id id, Decoration decoration, const std::vector<const char*>& strings)
void Builder::addDecoration(Id id, Decoration decoration, const std::vector<const char*>& decorationStrings)
{
if (decoration == spv::DecorationMax)
return;

Instruction* dec = new Instruction(OpDecorateString);
dec->addIdOperand(id);
dec->addImmediateOperand(decoration);
for (auto string : strings)
for (auto string : decorationStrings)
dec->addStringOperand(string);

decorations.push_back(std::unique_ptr<Instruction>(dec));
Expand Down Expand Up @@ -1982,7 +1982,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat
decorations.push_back(std::unique_ptr<Instruction>(dec));
}

void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, const std::vector<const char*>& strings)
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, const std::vector<const char*>& decorationStrings)
{
if (decoration == spv::DecorationMax)
return;
Expand All @@ -1991,7 +1991,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat
dec->addIdOperand(id);
dec->addImmediateOperand(member);
dec->addImmediateOperand(decoration);
for (auto string : strings)
for (auto string : decorationStrings)
dec->addStringOperand(string);

decorations.push_back(std::unique_ptr<Instruction>(dec));
Expand All @@ -2005,7 +2005,7 @@ Function* Builder::makeEntryPoint(const char* entryPoint)
Block* entry;
std::vector<Id> paramsTypes;
std::vector<char const*> paramNames;
std::vector<std::vector<Decoration>> decorations;
std::vector<std::vector<Decoration>> paramDecorations;

auto const returnType = makeVoidType();

Expand All @@ -2014,7 +2014,7 @@ Function* Builder::makeEntryPoint(const char* entryPoint)
emitNonSemanticShaderDebugInfo = false;
}

entryPointFunction = makeFunctionEntry(NoPrecision, returnType, entryPoint, paramsTypes, paramNames, decorations, &entry);
entryPointFunction = makeFunctionEntry(NoPrecision, returnType, entryPoint, paramsTypes, paramNames, paramDecorations, &entry);

emitNonSemanticShaderDebugInfo = restoreNonSemanticShaderDebugInfo;

Expand All @@ -2024,7 +2024,7 @@ Function* Builder::makeEntryPoint(const char* entryPoint)
// Comments in header
Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const char* name,
const std::vector<Id>& paramTypes, const std::vector<char const*>& paramNames,
const std::vector<std::vector<Decoration>>& decorations, Block **entry)
const std::vector<std::vector<Decoration>>& paramDecorations, Block **entry)
{
// Make the function and initial instructions in it
Id typeId = makeFunctionType(returnType, paramTypes);
Expand All @@ -2035,10 +2035,10 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const
// Set up the precisions
setPrecision(function->getId(), precision);
function->setReturnPrecision(precision);
for (unsigned p = 0; p < (unsigned)decorations.size(); ++p) {
for (int d = 0; d < (int)decorations[p].size(); ++d) {
addDecoration(firstParamId + p, decorations[p][d]);
function->addParamPrecision(p, decorations[p][d]);
for (unsigned p = 0; p < (unsigned)paramDecorations.size(); ++p) {
for (int d = 0; d < (int)paramDecorations[p].size(); ++d) {
addDecoration(firstParamId + p, paramDecorations[p][d]);
function->addParamPrecision(p, paramDecorations[p][d]);
}
}

Expand Down Expand Up @@ -2066,12 +2066,12 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const
assert(paramTypes.size() == paramNames.size());
for(size_t p = 0; p < paramTypes.size(); ++p)
{
auto getParamTypeId = [this](Id const& typeId) {
if (isPointerType(typeId) || isArrayType(typeId)) {
return getContainedTypeId(typeId);
auto getParamTypeId = [this](Id const& paramTypeId) {
if (isPointerType(paramTypeId) || isArrayType(paramTypeId)) {
return getContainedTypeId(paramTypeId);
}
else {
return typeId;
return paramTypeId;
}
};
auto const& paramName = paramNames[p];
Expand Down
4 changes: 2 additions & 2 deletions SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ class Builder {
void endSwitch(std::vector<Block*>& segmentBB);

struct LoopBlocks {
LoopBlocks(Block& head, Block& body, Block& merge, Block& continue_target) :
head(head), body(body), merge(merge), continue_target(continue_target) { }
LoopBlocks(Block& in_head, Block& in_body, Block& in_merge, Block& in_continue_target) :
head(in_head), body(in_body), merge(in_merge), continue_target(in_continue_target) { }
Block &head, &body, &merge, &continue_target;
private:
LoopBlocks();
Expand Down
10 changes: 5 additions & 5 deletions SPIRV/SpvPostProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ void Builder::postProcess(Instruction& inst)
// (set via Builder::AccessChain::alignment) only accounts for the base of
// the reference type and any scalar component selection in the accesschain,
// and this function computes the rest from the SPIR-V Offset decorations.
Instruction *accessChain = module.getInstruction(inst.getIdOperand(0));
if (accessChain->getOpCode() == OpAccessChain) {
Instruction *base = module.getInstruction(accessChain->getIdOperand(0));
Instruction *moduleAccessChain = module.getInstruction(inst.getIdOperand(0));
if (moduleAccessChain->getOpCode() == OpAccessChain) {
Instruction *base = module.getInstruction(moduleAccessChain->getIdOperand(0));
// Get the type of the base of the access chain. It must be a pointer type.
Id typeId = base->getTypeId();
Instruction *type = module.getInstruction(typeId);
Expand All @@ -263,8 +263,8 @@ void Builder::postProcess(Instruction& inst)
// Offset/ArrayStride/MatrixStride decorations, and bitwise OR them all
// together.
int alignment = 0;
for (int i = 1; i < accessChain->getNumOperands(); ++i) {
Instruction *idx = module.getInstruction(accessChain->getIdOperand(i));
for (int i = 1; i < moduleAccessChain->getNumOperands(); ++i) {
Instruction *idx = module.getInstruction(moduleAccessChain->getIdOperand(i));
if (type->getOpCode() == OpTypeStruct) {
assert(idx->getOpCode() == OpConstant);
unsigned int c = idx->getImmediateOperand(0);
Expand Down
2 changes: 1 addition & 1 deletion SPIRV/disassemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ enum ExtInstSet {
// Container class for a single instance of a SPIR-V stream, with methods for disassembly.
class SpirvStream {
public:
SpirvStream(std::ostream& out, const std::vector<unsigned int>& stream) : out(out), stream(stream), word(0), nextNestedControl(0) { }
SpirvStream(std::ostream& in_out, const std::vector<unsigned int>& in_stream) : out(in_out), stream(in_stream), word(0), nextNestedControl(0) { }
virtual ~SpirvStream() { }

void validate();
Expand Down
10 changes: 5 additions & 5 deletions SPIRV/spvIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ struct IdImmediate {

class Instruction {
public:
Instruction(Id resultId, Id typeId, Op opCode) : resultId(resultId), typeId(typeId), opCode(opCode), block(nullptr) { }
explicit Instruction(Op opCode) : resultId(NoResult), typeId(NoType), opCode(opCode), block(nullptr) { }
Instruction(Id in_resultId, Id in_typeId, Op in_opCode) : resultId(in_resultId), typeId(in_typeId), opCode(in_opCode), block(nullptr) { }
explicit Instruction(Op in_opCode) : resultId(NoResult), typeId(NoType), opCode(in_opCode), block(nullptr) { }
virtual ~Instruction() {}
void addIdOperand(Id id) {
operands.push_back(id);
Expand Down Expand Up @@ -471,8 +471,8 @@ class Module {
// Add both
// - the OpFunction instruction
// - all the OpFunctionParameter instructions
__inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, Module& parent)
: parent(parent), lineInstruction(nullptr),
__inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, Module& in_parent)
: parent(in_parent), lineInstruction(nullptr),
functionInstruction(id, resultType, OpFunction), implicitThis(false),
reducedPrecisionReturn(false)
{
Expand All @@ -499,7 +499,7 @@ __inline void Function::addLocalVariable(std::unique_ptr<Instruction> inst)
parent.mapInstruction(raw_instruction);
}

__inline Block::Block(Id id, Function& parent) : parent(parent), unreachable(false)
__inline Block::Block(Id id, Function& in_parent) : parent(in_parent), unreachable(false)
{
instructions.push_back(std::unique_ptr<Instruction>(new Instruction(id, NoType, OpLabel)));
instructions.back()->setBlock(this);
Expand Down
Loading