mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-25 08:18:11 +02:00
In the C23 standard unreachable() is now a predefined function-like macro in <stddef.h> See https://android.googlesource.com/platform/bionic/+/HEAD/docs/c23.md#is-now-a-predefined-function_like-macro-in And this causes build errors when building for C23: ----------------------------------------------------------------------- In file included from ../src/util/log.h:30, from ../src/util/log.c:30: ../src/util/macros.h:123:9: warning: "unreachable" redefined 123 | #define unreachable(str) \ | ^~~~~~~~~~~ In file included from ../src/util/macros.h:31: /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:456:9: note: this is the location of the previous definition 456 | #define unreachable() (__builtin_unreachable ()) | ^~~~~~~~~~~ ----------------------------------------------------------------------- So don't redefine it with the same name, but use the name UNREACHABLE() to also signify it's a macro. Using a different name also makes sense because the behavior of the macro was extending the one of __builtin_unreachable() anyway, and it also had a different signature, accepting one argument, compared to the standard unreachable() with no arguments. This change improves the chances of building mesa with the C23 standard, which for instance is the default in recent AOSP versions. All the instances of the macro, including the definition, were updated with the following command line: git grep -l '[^_]unreachable(' -- "src/**" | sort | uniq | \ while read file; \ do \ sed -e 's/\([^_]\)unreachable(/\1UNREACHABLE(/g' -i "$file"; \ done && \ sed -e 's/#undef unreachable/#undef UNREACHABLE/g' -i src/intel/isl/isl_aux_info.c Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36437>
72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
/*
|
|
* Copyright 2024 Valve Corporation
|
|
* Copyright 2022 Collabora Ltd
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "util/macros.h"
|
|
#include <stdbool.h>
|
|
|
|
#ifndef U_TRISTATE_H
|
|
#define U_TRISTATE_H
|
|
|
|
/*
|
|
* Simple tri-state data structure.
|
|
*
|
|
* The tri-state can be set to a boolean or unset. The semantics of "unset"
|
|
* depend on the application, it could be either "don't care" or "maybe".
|
|
*/
|
|
enum u_tristate {
|
|
U_TRISTATE_UNSET,
|
|
U_TRISTATE_NO,
|
|
U_TRISTATE_YES,
|
|
};
|
|
|
|
/*
|
|
* Construct a tristate from an immediate value.
|
|
*/
|
|
static inline enum u_tristate
|
|
u_tristate_make(bool value)
|
|
{
|
|
return value ? U_TRISTATE_YES : U_TRISTATE_NO;
|
|
}
|
|
|
|
/*
|
|
* Try to set a tristate value to a specific boolean value, returning whether
|
|
* the operation is successful.
|
|
*/
|
|
static inline bool
|
|
u_tristate_set(enum u_tristate *state, bool value)
|
|
{
|
|
switch (*state) {
|
|
case U_TRISTATE_UNSET:
|
|
*state = u_tristate_make(value);
|
|
return true;
|
|
|
|
case U_TRISTATE_NO:
|
|
return (value == false);
|
|
|
|
case U_TRISTATE_YES:
|
|
return (value == true);
|
|
|
|
default:
|
|
UNREACHABLE("Invalid tristate value");
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Invert a tristate, returning the new value.
|
|
*/
|
|
static inline enum u_tristate
|
|
u_tristate_invert(enum u_tristate tri)
|
|
{
|
|
switch (tri) {
|
|
case U_TRISTATE_UNSET: return U_TRISTATE_UNSET;
|
|
case U_TRISTATE_YES: return U_TRISTATE_NO;
|
|
case U_TRISTATE_NO: return U_TRISTATE_YES;
|
|
}
|
|
|
|
UNREACHABLE("invalid tristate");
|
|
}
|
|
|
|
#endif
|