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

-Wmaybe-uninitialized #428

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Create variable to enable additional compiler warnings for SimEng targets only
set(SIMENG_COMPILE_OPTIONS -Wall -pedantic -Werror) #-Wextra
set(SIMENG_COMPILE_OPTIONS -Wall -pedantic -Werror -fno-strict-aliasing) #-Wextra

# Disable RTTI for all targets
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
Expand Down
12 changes: 6 additions & 6 deletions src/include/simeng/RegisterValue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class RegisterValue {
typename std::enable_if_t<!std::is_pointer_v<T>, T>* = nullptr>
RegisterValue(T value, uint16_t bytes = sizeof(T)) : bytes(bytes) {
if (isLocal()) {
T* view = reinterpret_cast<T*>(this->value);
T* view = reinterpret_cast<T*>(this->localValue);
view[0] = value;

if (bytes > sizeof(T)) {
// Zero the remaining bytes not set by the provided value
std::fill<char*, uint16_t>(this->value + sizeof(T), this->value + bytes,
0);
std::fill<char*, uint16_t>(this->localValue + sizeof(T),
this->localValue + bytes, 0);
}
} else {
void* data = pool.allocate(bytes);
Expand All @@ -57,7 +57,7 @@ class RegisterValue {
assert(capacity >= bytes && "Capacity is less than requested bytes");
char* dest;
if (isLocal()) {
dest = this->value;
dest = this->localValue;
} else {
dest = static_cast<char*>(pool.allocate(capacity));
std::memset(dest, 0, capacity);
Expand Down Expand Up @@ -96,7 +96,7 @@ class RegisterValue {
"Attempted to access a RegisterValue as a datatype larger than the "
"data held");
if (isLocal()) {
return reinterpret_cast<const T*>(value);
return reinterpret_cast<const T*>(localValue);
} else {
return reinterpret_cast<const T*>(ptr.get());
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class RegisterValue {

/** The underlying local member value. Aligned to 8 bytes to prevent
* potential alignment issue when casting. */
alignas(8) char value[MAX_LOCAL_BYTES];
alignas(8) char localValue[MAX_LOCAL_BYTES] = {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly inefficient as it initialises localValue to all 0's for every instance which will be overwritten when constructing the instance. We should test if there is any visible performance degradation from this change. Maybe another one for Leo @ABenC377

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative solution is to do something like

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
    foo(b);         /* no diagnostic for this one */
#pragma GCC diagnostic pop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we use Pool's for RegisterValues this may not cause a huge performance hit. Worth checking though

};

inline bool operator==(const RegisterValue& lhs, const RegisterValue& rhs) {
Expand Down
11 changes: 9 additions & 2 deletions src/include/simeng/arch/aarch64/helpers/neon.hh
Original file line number Diff line number Diff line change
Expand Up @@ -785,14 +785,21 @@ RegisterValue vecSumElems_2ops(srcValContainer& sourceValues) {
template <typename D, typename N, int I>
RegisterValue vecXtn(srcValContainer& sourceValues, bool isXtn2) {
const D* d;
if (isXtn2) d = sourceValues[0].getAsVector<D>();
const N* n = sourceValues[isXtn2 ? 1 : 0].getAsVector<N>();
const N* n;
if (isXtn2) {
d = sourceValues[0].getAsVector<D>();
n = sourceValues[1].getAsVector<N>();
} else {
d = {};
n = sourceValues[0].getAsVector<N>();
}

D out[16 / sizeof(D)] = {0};
int index = 0;

for (int i = 0; i < I; i++) {
if (isXtn2 & (i < (I / 2))) {
assert(isXtn2 && "isXtn2 is false so d is not initialised");
out[i] = d[i];
} else {
out[i] = static_cast<D>(n[index]);
Comment on lines +788 to 805
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FinnWilkinson this is a temporary solution as I didn't want to fiddle too much with the for loop below. If you have a preferred solution then feel free to push a commit implementing that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this proposed solution is good.

From our offline discussion aboout line 801 on whether it should be isXtn2 & (i < (I / 2)) or isXtn2 && (i < (I / 2)), given both arguments are bools the functionality would be the same, but using && may be marginally clearer of this fact?

Expand Down
4 changes: 2 additions & 2 deletions src/lib/RegisterValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ RegisterValue RegisterValue::zeroExtend(uint16_t fromBytes,
auto extended = RegisterValue(0, toBytes);

// Get the appropriate source/destination pointers and copy the data
const char* src = (isLocal() ? value : ptr.get());
char* dest = (extended.isLocal() ? extended.value : extended.ptr.get());
const char* src = (isLocal() ? localValue : ptr.get());
char* dest = (extended.isLocal() ? extended.localValue : extended.ptr.get());

std::memcpy(dest, src, fromBytes);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/arch/aarch64/ExceptionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ bool ExceptionHandler::init() {
return readStringThen(filename, filenamePtr,
kernel::Linux::LINUX_PATH_MAX, [=](auto length) {
// Invoke the kernel
kernel::stat statOut;
kernel::stat statOut = {};
uint64_t retval = linux_.newfstatat(
dfd, filename, statOut, flag);
ProcessStateChange stateChange = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/arch/riscv/ExceptionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ bool ExceptionHandler::init() {
return readStringThen(filename, filenamePtr,
kernel::Linux::LINUX_PATH_MAX, [=](auto length) {
// Invoke the kernel
kernel::stat statOut;
kernel::stat statOut = {};
uint64_t retval = linux_.newfstatat(
dfd, filename, statOut, flag);
ProcessStateChange stateChange = {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/RegisterValueTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(RegisterValueTest, Reinterpret) {
TEST(RegisterValueTest, Vector) {
uint64_t value = 0x0000000200000001;
auto registerValue = simeng::RegisterValue(value, 8);
auto vector = registerValue.getAsVector<uint32_t>();
const uint32_t* vector = registerValue.getAsVector<uint32_t>();
EXPECT_EQ(vector[0], 1);
EXPECT_EQ(vector[1], 2);
}
Expand Down