build: avoid redefining unreachable() which is standard in C23

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>
This commit is contained in:
Antonio Ospite
2025-07-23 09:17:35 +02:00
committed by Marge Bot
parent b4c7d3a08e
commit ddf2aa3a4d
1079 changed files with 3741 additions and 3741 deletions
+8 -8
View File
@@ -32,7 +32,7 @@ src_as_uint(const brw_reg &src)
return src.u64;
default:
unreachable("Invalid integer type.");
UNREACHABLE("Invalid integer type.");
}
}
@@ -52,7 +52,7 @@ src_as_float(const brw_reg &src)
return src.df;
default:
unreachable("Invalid float type.");
UNREACHABLE("Invalid float type.");
}
}
@@ -79,7 +79,7 @@ brw_imm_for_type(uint64_t value, enum brw_reg_type type)
return brw_imm_uq(value);
default:
unreachable("Invalid integer type.");
UNREACHABLE("Invalid integer type.");
}
}
@@ -120,11 +120,11 @@ fold_multiplicands_of_MAD(brw_inst *inst)
break;
case BRW_TYPE_DF:
unreachable("float64 should be impossible.");
UNREACHABLE("float64 should be impossible.");
break;
default:
unreachable("Invalid float type.");
UNREACHABLE("Invalid float type.");
}
}
@@ -269,7 +269,7 @@ brw_opt_constant_fold_instruction(const intel_device_info *devinfo, brw_inst *in
break;
default:
/* Just in case a future platform re-enables B or UB types. */
unreachable("Invalid source size.");
UNREACHABLE("Invalid source size.");
}
result = retype(result, inst->dst.type);
@@ -426,7 +426,7 @@ brw_opt_algebraic(brw_shader &s)
if (inst->dst.type != inst->src[0].type &&
inst->dst.type != BRW_TYPE_DF &&
inst->src[0].type != BRW_TYPE_F)
unreachable("unimplemented: saturate mixed types");
UNREACHABLE("unimplemented: saturate mixed types");
if (brw_reg_saturate_immediate(&inst->src[0])) {
inst->saturate = false;
@@ -670,7 +670,7 @@ brw_opt_algebraic(brw_shader &s)
progress = true;
break;
default:
unreachable("Impossible icsel condition.");
UNREACHABLE("Impossible icsel condition.");
}
}
}