[clang] Add support for builtin_verbose_trap (PR #79230)

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 26 11:40:03 PST 2024


================
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s
+
+#if !__has_builtin(__builtin_verbose_trap)
+#error
+#endif
+
+constexpr char const* constMsg1 = "hello";
+char const* const constMsg2 = "hello";
+char const constMsg3[] = "hello";
+
+template <const char * const str>
+void f(const char * arg) {
+  __builtin_verbose_trap("Argument_must_not_be_null");
----------------
philnik777 wrote:

You can overload builtins by adding custom type checking to them. The "templates" in `Builtins.td` is more of a way to generate builtins with the same pattern for different types. e.g. there are `__builtin_cos`, `__builtin_cosf` and `__builtin_cosl`, which are essentially identical, except that they take `double`, `float` and `long double` respectively. To avoid typing everything out (and making errors that way), you can make the builtin a template.

https://github.com/llvm/llvm-project/pull/79230


More information about the cfe-commits mailing list