build: Enable declaration hiding warning on Windows
Fixes #1388
Turn on the Windows compiler option (4456) to report
hidden declarations.
Fix all places where this was occurring.
Change-Id: I3346d87da8b70d6299c206fcac68520a091ed1a6
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8b09cbc..77e365a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,9 +57,12 @@
endif()
if(WIN32)
- # Disable RTTI, Treat warnings as errors
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR- /WX")
+ # Treat warnings as errors
+ add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/WX>")
+ # Disable RTTI
+ add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/GR->")
+ # Warn about nested declarations
+ add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34456>")
endif()
if(NOT WIN32)
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp
index 4ed0803..d342afa 100644
--- a/layers/core_validation.cpp
+++ b/layers/core_validation.cpp
@@ -7621,49 +7621,50 @@
}
auto oldFinalBoundSet = pCB->lastBound[pipelineBindPoint].boundDescriptorSets[lastSetIndex];
auto pipeline_layout = getPipelineLayout(dev_data, layout);
- for (uint32_t i = 0; i < setCount; i++) {
- cvdescriptorset::DescriptorSet *descriptor_set = getSetNode(dev_data, pDescriptorSets[i]);
+ for (uint32_t set_idx = 0; set_idx < setCount; set_idx++) {
+ cvdescriptorset::DescriptorSet *descriptor_set = getSetNode(dev_data, pDescriptorSets[set_idx]);
if (descriptor_set) {
pCB->lastBound[pipelineBindPoint].pipeline_layout = *pipeline_layout;
- pCB->lastBound[pipelineBindPoint].boundDescriptorSets[i + firstSet] = descriptor_set;
+ pCB->lastBound[pipelineBindPoint].boundDescriptorSets[set_idx + firstSet] = descriptor_set;
skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT,
- VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[i], __LINE__,
- DRAWSTATE_NONE, "DS", "Descriptor Set 0x%" PRIxLEAST64 " bound on pipeline %s",
- (uint64_t)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[set_idx],
+ __LINE__, DRAWSTATE_NONE, "DS", "Descriptor Set 0x%" PRIxLEAST64 " bound on pipeline %s",
+ (uint64_t)pDescriptorSets[set_idx], string_VkPipelineBindPoint(pipelineBindPoint));
if (!descriptor_set->IsUpdated() && (descriptor_set->GetTotalDescriptorCount() != 0)) {
skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
- VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[i], __LINE__,
- DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[set_idx],
+ __LINE__, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
"Descriptor Set 0x%" PRIxLEAST64
" bound but it was never updated. You may want to either update it or not bind it.",
- (uint64_t)pDescriptorSets[i]);
+ (uint64_t)pDescriptorSets[set_idx]);
}
// Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
- if (!verify_set_layout_compatibility(dev_data, descriptor_set, pipeline_layout, i + firstSet, errorString)) {
+ if (!verify_set_layout_compatibility(dev_data, descriptor_set, pipeline_layout, set_idx + firstSet,
+ errorString)) {
skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
- VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[i], __LINE__,
- VALIDATION_ERROR_00974, "DS",
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[set_idx],
+ __LINE__, VALIDATION_ERROR_00974, "DS",
"descriptorSet #%u being bound is not compatible with overlapping descriptorSetLayout "
"at index %u of pipelineLayout 0x%" PRIxLEAST64 " due to: %s. %s",
- i, i + firstSet, reinterpret_cast<uint64_t &>(layout), errorString.c_str(),
+ set_idx, set_idx + firstSet, reinterpret_cast<uint64_t &>(layout), errorString.c_str(),
validation_error_map[VALIDATION_ERROR_00974]);
}
auto setDynamicDescriptorCount = descriptor_set->GetDynamicDescriptorCount();
- pCB->lastBound[pipelineBindPoint].dynamicOffsets[firstSet + i].clear();
+ pCB->lastBound[pipelineBindPoint].dynamicOffsets[firstSet + set_idx].clear();
if (setDynamicDescriptorCount) {
// First make sure we won't overstep bounds of pDynamicOffsets array
if ((totalDynamicDescriptors + setDynamicDescriptorCount) > dynamicOffsetCount) {
skip_call |=
log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
- VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[i], __LINE__,
- DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[set_idx],
+ __LINE__, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
"descriptorSet #%u (0x%" PRIxLEAST64
") requires %u dynamicOffsets, but only %u dynamicOffsets are left in pDynamicOffsets "
"array. There must be one dynamic offset for each dynamic descriptor being bound.",
- i, (uint64_t)pDescriptorSets[i], descriptor_set->GetDynamicDescriptorCount(),
+ set_idx, (uint64_t)pDescriptorSets[set_idx], descriptor_set->GetDynamicDescriptorCount(),
(dynamicOffsetCount - totalDynamicDescriptors));
} else { // Validate and store dynamic offsets with the set
// Validate Dynamic Offset Minimums
@@ -7702,7 +7703,7 @@
}
}
- pCB->lastBound[pipelineBindPoint].dynamicOffsets[firstSet + i] =
+ pCB->lastBound[pipelineBindPoint].dynamicOffsets[firstSet + set_idx] =
std::vector<uint32_t>(pDynamicOffsets + totalDynamicDescriptors,
pDynamicOffsets + totalDynamicDescriptors + setDynamicDescriptorCount);
// Keep running total of dynamic descriptor count to verify at the end
@@ -7710,10 +7711,11 @@
}
}
} else {
- skip_call |= log_msg(
- dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
- (uint64_t)pDescriptorSets[i], __LINE__, DRAWSTATE_INVALID_SET, "DS",
- "Attempt to bind descriptor set 0x%" PRIxLEAST64 " that doesn't exist!", (uint64_t)pDescriptorSets[i]);
+ skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)pDescriptorSets[set_idx],
+ __LINE__, DRAWSTATE_INVALID_SET, "DS",
+ "Attempt to bind descriptor set 0x%" PRIxLEAST64 " that doesn't exist!",
+ (uint64_t)pDescriptorSets[set_idx]);
}
skip_call |= ValidateCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescriptorSets()");
UpdateCmdBufferLastCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS);
@@ -9277,7 +9279,6 @@
"PREINITIALIZED.",
funcName);
}
- auto image_data = getImageState(dev_data, mem_barrier->image);
VkFormat format = VK_FORMAT_UNDEFINED;
uint32_t arrayLayers = 0, mipLevels = 0;
bool imageFound = false;
@@ -10139,7 +10140,6 @@
}
// If the attachment was written to by a previous node than this node needs to preserve it.
if (result && depth > 0) {
- const VkSubpassDescription &subpass = pCreateInfo->pSubpasses[index];
bool has_preserved = false;
for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
if (subpass.pPreserveAttachments[j] == attachment) {
diff --git a/layers/object_tracker.cpp b/layers/object_tracker.cpp
index 6b854be..f4acbe3 100644
--- a/layers/object_tracker.cpp
+++ b/layers/object_tracker.cpp
@@ -4338,7 +4338,7 @@
if (dev_data->dispatch_table.RegisterDeviceEventEXT) {
result = dev_data->dispatch_table.RegisterDeviceEventEXT(device, pDeviceEventInfo, pAllocator, pFence);
if (result == VK_SUCCESS && pFence != NULL) {
- std::lock_guard<std::mutex> lock(global_lock);
+ std::lock_guard<std::mutex> create_lock(global_lock);
CreateObject(device, *pFence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, pAllocator);
}
}
@@ -4360,7 +4360,7 @@
if (dev_data->dispatch_table.RegisterDisplayEventEXT) {
result = dev_data->dispatch_table.RegisterDisplayEventEXT(device, display, pDisplayEventInfo, pAllocator, pFence);
if (result == VK_SUCCESS && pFence != NULL) {
- std::lock_guard<std::mutex> lock(global_lock);
+ std::lock_guard<std::mutex> create_lock(global_lock);
CreateObject(device, *pFence, VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, pAllocator);
}
}
diff --git a/layers/threading.h b/layers/threading.h
index 481acd4..67bb0d6 100644
--- a/layers/threading.h
+++ b/layers/threading.h
@@ -101,10 +101,10 @@
counter_condition.wait(lock);
}
// There is now no current use of the object. Record writer thread.
- struct object_use_data *use_data = &uses[object];
- use_data->thread = tid;
- use_data->reader_count = 0;
- use_data->writer_count = 1;
+ struct object_use_data *new_use_data = &uses[object];
+ new_use_data->thread = tid;
+ new_use_data->reader_count = 0;
+ new_use_data->writer_count = 1;
} else {
// Continue with an unsafe use of the object.
use_data->thread = tid;
@@ -128,10 +128,10 @@
counter_condition.wait(lock);
}
// There is now no current use of the object. Record writer thread.
- struct object_use_data *use_data = &uses[object];
- use_data->thread = tid;
- use_data->reader_count = 0;
- use_data->writer_count = 1;
+ struct object_use_data *new_use_data = &uses[object];
+ new_use_data->thread = tid;
+ new_use_data->reader_count = 0;
+ new_use_data->writer_count = 1;
} else {
// Continue with an unsafe use of the object.
use_data->thread = tid;
diff --git a/layers/unique_objects.cpp b/layers/unique_objects.cpp
index f973ec5..dfd35f2 100644
--- a/layers/unique_objects.cpp
+++ b/layers/unique_objects.cpp
@@ -103,7 +103,6 @@
#endif
// Check for recognized instance extensions
- layer_data *instance_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
if (!white_list(pCreateInfo->ppEnabledExtensionNames[i], kUniqueObjectsSupportedInstanceExtensions)) {
log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
VALIDATION_ERROR_UNDEFINED, "UniqueObjects",
diff --git a/loader/loader.c b/loader/loader.c
index 9c43525..2875af1 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -4858,7 +4858,6 @@
struct loader_icd_term *icd_term;
struct loader_phys_dev_per_icd *icd_phys_dev_array = NULL;
struct loader_physical_device_term **new_phys_devs = NULL;
- uint32_t i = 0;
inst->total_gpu_count = 0;
@@ -4879,38 +4878,35 @@
// For each ICD, query the number of physical devices, and then get an
// internal value for those physical devices.
- while (NULL != icd_term) {
- res = icd_term->EnumeratePhysicalDevices(icd_term->instance, &icd_phys_dev_array[i].count, NULL);
+ for (uint32_t icd_idx = 0; NULL != icd_term; icd_term = icd_term->next, icd_idx++) {
+ res = icd_term->EnumeratePhysicalDevices(icd_term->instance, &icd_phys_dev_array[icd_idx].count, NULL);
if (VK_SUCCESS != res) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"setupLoaderTermPhysDevs: Call to "
"ICD %d's \'vkEnumeratePhysicalDevices\' failed with"
" error 0x%08x",
- i, res);
+ icd_idx, res);
goto out;
}
- icd_phys_dev_array[i].phys_devs =
- (VkPhysicalDevice *)loader_stack_alloc(icd_phys_dev_array[i].count * sizeof(VkPhysicalDevice));
- if (NULL == icd_phys_dev_array[i].phys_devs) {
+ icd_phys_dev_array[icd_idx].phys_devs =
+ (VkPhysicalDevice *)loader_stack_alloc(icd_phys_dev_array[icd_idx].count * sizeof(VkPhysicalDevice));
+ if (NULL == icd_phys_dev_array[icd_idx].phys_devs) {
loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
"setupLoaderTermPhysDevs: Failed to allocate temporary "
"ICD Physical device array for ICD %d of size %d",
- i, inst->total_gpu_count);
+ icd_idx, inst->total_gpu_count);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- res =
- icd_term->EnumeratePhysicalDevices(icd_term->instance, &(icd_phys_dev_array[i].count), icd_phys_dev_array[i].phys_devs);
+ res = icd_term->EnumeratePhysicalDevices(icd_term->instance, &(icd_phys_dev_array[icd_idx].count),
+ icd_phys_dev_array[icd_idx].phys_devs);
if (VK_SUCCESS != res) {
goto out;
}
- inst->total_gpu_count += icd_phys_dev_array[i].count;
- icd_phys_dev_array[i].this_icd_term = icd_term;
-
- icd_term = icd_term->next;
- i++;
+ inst->total_gpu_count += icd_phys_dev_array[icd_idx].count;
+ icd_phys_dev_array[icd_idx].this_icd_term = icd_term;
}
if (0 == inst->total_gpu_count) {
diff --git a/tests/layer_validation_tests.cpp b/tests/layer_validation_tests.cpp
index ae879eb..d349b94 100644
--- a/tests/layer_validation_tests.cpp
+++ b/tests/layer_validation_tests.cpp
@@ -2641,7 +2641,6 @@
// buffer to image
{
vk_testing::Buffer src_buffer;
- VkMemoryPropertyFlags reqs = 0;
src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
@@ -20503,7 +20502,7 @@
buffer_create_info.pQueueFamilyIndices = &queue_family_index;
VkBuffer buffer;
- VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
+ err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
ASSERT_VK_SUCCESS(err);
VkMemoryRequirements memory_reqs;