* [PATCH] configure: Avoid -Werror=maybe-uninitialized
@ 2023-04-05 7:00 Akihiko Odaki
2023-04-05 12:07 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Akihiko Odaki @ 2023-04-05 7:00 UTC (permalink / raw)
Cc: qemu-devel, Paolo Bonzini, Alex Bennée, Thomas Huth,
Akihiko Odaki
The configure script used to compile some code which dereferences memory
with ubsan to verify the compiler can link with ubsan library which
detects dereferencing of uninitialized memory. However, as the
dereferenced memory was allocated in the same code, GCC can statically
detect the unitialized memory dereference and emit maybe-uninitialized
warning. If -Werror is set, this becomes an error, and the configure
script incorrectly thinks the error indicates the compiler cannot use
ubsan.
Fix this error by replacing the code with another function which adds
1 to a signed integer argument. This brings in ubsan to detect if it
causes signed integer overflow. As the value of the argument cannot be
statically determined, the new function is also immune to compiler
warnings.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
configure | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/configure b/configure
index 05bed4f4a1..cf72a4121f 100755
--- a/configure
+++ b/configure
@@ -1737,13 +1737,9 @@ if test "$sanitizers" = "yes" ; then
# detect the static linking issue of ubsan, see also:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
cat > $TMPC << EOF
-#include <stdlib.h>
-int main(void) {
- void *tmp = malloc(10);
- if (tmp != NULL) {
- return *(int *)(tmp + 2);
- }
- return 1;
+int main(int argc, char **argv)
+{
+ return argc + 1;
}
EOF
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
--
2.40.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-05 12:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-05 7:00 [PATCH] configure: Avoid -Werror=maybe-uninitialized Akihiko Odaki
2023-04-05 12:07 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).