Skip to content

Commit

Permalink
Meta: Disable -Wmaybe-uninitialized
Browse files Browse the repository at this point in the history
It's prone to finding "technically uninitialized but can never happen"
cases, particularly in Optional<T> and Variant<Ts...>.
The general case seems to be that it cannot infer the dependency
between Variant's index (or Optional's boolean state) and a particular
alternative (or Optional's buffer) being untouched.
So it can flag cases like this:
```c++
if (index == StaticIndexForF)
    new (new_buffer) F(move(*bit_cast<F*>(old_buffer)));
```
The code in that branch can _technically_ make a partially initialized
`F`, but that path can never be taken since the buffer holding an
object of type `F` and the condition being true are correlated, and so
will never be taken _unless_ the buffer holds an object of type `F`.

This commit also removed the various 'diagnostic ignored' pragmas used
to work around this warning, as they no longer do anything.
  • Loading branch information
alimpfard committed Jun 9, 2021
1 parent 45710d0 commit 50349de
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 20 deletions.
3 changes: 0 additions & 3 deletions AK/Base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ ByteBuffer decode_base64(const StringView& input)
output.append(out2);
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
return ByteBuffer::copy(output.data(), output.size());
#pragma GCC diagnostic pop
}

String encode_base64(ReadonlyBytes input)
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ add_compile_options(-Wno-unknown-warning-option)
add_compile_options(-Wundef)
add_compile_options(-Wunused)
add_compile_options(-Wwrite-strings)
add_compile_options(-Wno-maybe-uninitialized)

add_compile_options(-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.)
add_compile_options(-fno-exceptions)
Expand Down
8 changes: 0 additions & 8 deletions Kernel/Syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,7 @@ KResultOr<FlatPtr> handle(RegisterState& regs, FlatPtr function, FlatPtr arg1, F
return ENOSYS;
}

// This appears to be a bogus warning, as s_syscall_table is always
// initialized, and the index (function) is always bounded.
// TODO: Figure out how to avoid the suppression.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

return (process.*(s_syscall_table[function]))(arg1, arg2, arg3);

#pragma GCC diagnostic pop
}

}
Expand Down
3 changes: 0 additions & 3 deletions Userland/Libraries/LibGUI/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ void Label::wrap_text()
case '\t':
case ' ': {
if (start.has_value())
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
words.append(m_text.substring(start.value(), i - start.value()));
#pragma GCC diagnostic pop
start.clear();
continue;
}
Expand Down
6 changes: 0 additions & 6 deletions Userland/Utilities/crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ int main(int argc, char** argv)
if (!uninitialized_memory)
return Crash::Failure::UnexpectedError;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
[[maybe_unused]] volatile auto x = uninitialized_memory[0][0];
#pragma GCC diagnostic pop
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
Expand All @@ -144,10 +141,7 @@ int main(int argc, char** argv)
if (!uninitialized_memory)
return Crash::Failure::UnexpectedError;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
uninitialized_memory[4][0] = 1;
#pragma GCC diagnostic pop
return Crash::Failure::DidNotCrash;
}).run(run_type);
}
Expand Down

0 comments on commit 50349de

Please sign in to comment.