[clang] [clang]: implement std::meta::is_type (PR #211653)
Nhat Nguyen via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 29 12:02:30 PDT 2026
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/211653
>From f227014fc803823c7a649a97c55515d0e6bf82be Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Thu, 15 Oct 2026 21:27:00 -0400
Subject: [PATCH 01/16] implement std::meta::is_type
---
clang/include/clang/Basic/Builtins.td | 6 ++
clang/lib/AST/ASTContext.cpp | 3 +
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 10 +++
clang/lib/AST/ByteCode/Reflect.h | 2 +
clang/lib/AST/ExprConstant.cpp | 8 ++
clang/lib/Basic/Module.cpp | 1 +
clang/lib/Frontend/InitPreprocessor.cpp | 4 +
clang/lib/Headers/CMakeLists.txt | 1 +
clang/lib/Headers/meta | 35 +++++++++
clang/lib/Headers/module.modulemap | 6 ++
clang/test/Headers/meta.cpp | 76 +++++++++++++++++++
clang/test/Lexer/cxx-features.cpp | 6 ++
clang/test/SemaCXX/builtin-meta-is-type.cpp | 71 +++++++++++++++++
clang/test/SemaCXX/consteval-builtin.cpp | 18 +++++
clang/utils/TableGen/ClangBuiltinsEmitter.cpp | 1 +
15 files changed, 248 insertions(+)
create mode 100644 clang/lib/Headers/meta
create mode 100644 clang/test/Headers/meta.cpp
create mode 100644 clang/test/SemaCXX/builtin-meta-is-type.cpp
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index ad9a58bb2ad2d3..4f039de6e0fc07 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1207,6 +1207,12 @@ def IsWithinLifetime : LangBuiltin<"CXX_LANG"> {
let Prototype = "bool(void*)";
}
+def MetaIsType : LangBuiltin<"CXX_LANG"> {
+ let Spellings = ["__builtin_meta_is_type"];
+ let Attributes = [NoThrow, Consteval];
+ let Prototype = "bool(std::meta::info)";
+}
+
def ClearPadding : Builtin {
let Spellings = ["__builtin_clear_padding"];
let Attributes = [NoThrow, CustomTypeChecking];
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 02d656feb0cee5..c866ddd4cdcaa1 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12894,6 +12894,9 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context,
case 'M':
Type = Context.getObjCSuperType();
break;
+ case 'r':
+ Type = Context.MetaInfoTy;
+ break;
case 'a':
Type = Context.getBuiltinVaListType();
assert(!Type.isNull() && "builtin va list type not initialized!");
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 7020c73f4bb981..f431b91b2c9a88 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2489,6 +2489,13 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
return false;
}
+static bool interp__builtin_meta_is_type(InterpState &S, CodePtr OpPC,
+ const CallExpr *) {
+ const Reflect &R = S.Stk.pop<Reflect>();
+ S.Stk.push<Boolean>(Boolean::from(R.getKind() == ReflectionKind::Type));
+ return true;
+}
+
static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
const CallExpr *Call) {
@@ -5449,6 +5456,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case Builtin::BI__builtin_is_within_lifetime:
return interp__builtin_is_within_lifetime(S, OpPC, Call);
+ case Builtin::BI__builtin_meta_is_type:
+ return interp__builtin_meta_is_type(S, OpPC, Call);
+
case Builtin::BI__builtin_elementwise_add_sat:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &LHS, const APSInt &RHS) {
diff --git a/clang/lib/AST/ByteCode/Reflect.h b/clang/lib/AST/ByteCode/Reflect.h
index bfac6f72be8ba0..4aff15e062bd3d 100644
--- a/clang/lib/AST/ByteCode/Reflect.h
+++ b/clang/lib/AST/ByteCode/Reflect.h
@@ -31,6 +31,8 @@ class Reflect final {
Reflect(ReflectionKind Kind, const void *Operand)
: Kind(Kind), Operand(Operand) {}
+ ReflectionKind getKind() const { return Kind; }
+
ComparisonCategoryResult compare(const Reflect &RHS) const {
llvm::FoldingSetNodeID LID, RID;
APValue(Kind, Operand).Profile(LID);
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index cf450699aee999..234dd038ff5572 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -17423,6 +17423,14 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
return Success(*result, E);
return false;
+ case Builtin::BI__builtin_meta_is_type: {
+ APValue Reflection;
+ if (!EvaluateReflection(E->getArg(0), Reflection, Info))
+ return false;
+ return Success(
+ Reflection.getReflectionOperandKind() == ReflectionKind::Type, E);
+ }
+
case Builtin::BI__builtin_ctz:
case Builtin::BI__builtin_ctzl:
case Builtin::BI__builtin_ctzll:
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 80a21cba8e2fcb..745e4bbf0df1c5 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -116,6 +116,7 @@ static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
.Case("objc", LangOpts.ObjC)
.Case("objc_arc", LangOpts.ObjCAutoRefCount)
.Case("opencl", LangOpts.OpenCL)
+ .Case("reflection", LangOpts.Reflection)
.Case("tls", Target.isTLSSupported())
.Case("zvector", LangOpts.ZVector)
.Default(Target.hasFeature(Feature) ||
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 784ff9951a25ad..fad6a07fc3a2d8 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -766,6 +766,10 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
Builder.defineMacro("__cpp_variadic_friend", "202403L");
Builder.defineMacro("__cpp_trivial_relocatability", "202502L");
+ // C++26 reflection.
+ if (LangOpts.Reflection)
+ Builder.defineMacro("__cpp_impl_reflection", "202506L");
+
if (LangOpts.Char8)
Builder.defineMacro("__cpp_char8_t", "202207L");
Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 1e7a4d05ed2cb2..8d5b959bd24e58 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -11,6 +11,7 @@ set(core_files
inttypes.h
iso646.h
limits.h
+ meta
module.modulemap
stdalign.h
stdarg.h
diff --git a/clang/lib/Headers/meta b/clang/lib/Headers/meta
new file mode 100644
index 00000000000000..5f766c63c70f93
--- /dev/null
+++ b/clang/lib/Headers/meta
@@ -0,0 +1,35 @@
+/*===---- meta - header for reflection metafunctions -----------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __CLANG_META
+#define __CLANG_META
+
+#if !defined(__cplusplus)
+#error "meta header is only available in C++ mode"
+#endif
+
+#if !defined(__cpp_impl_reflection)
+#error "meta header is only available when -freflection is enabled"
+#endif
+
+#define __cpp_lib_reflection 202506L
+
+namespace std {
+namespace meta {
+
+using info = decltype(^^int);
+
+consteval bool is_type(info __r) {
+ return __builtin_meta_is_type(__r);
+}
+
+} // namespace meta
+} // namespace std
+
+#endif // __CLANG_META
diff --git a/clang/lib/Headers/module.modulemap b/clang/lib/Headers/module.modulemap
index c8f96df1672c1e..d59c2fddc041d1 100644
--- a/clang/lib/Headers/module.modulemap
+++ b/clang/lib/Headers/module.modulemap
@@ -373,3 +373,9 @@ module ptrauth [system] {
header "ptrauth.h"
export *
}
+
+module _Builtin_meta [system] {
+ requires reflection
+ header "meta"
+ export *
+}
diff --git a/clang/test/Headers/meta.cpp b/clang/test/Headers/meta.cpp
new file mode 100644
index 00000000000000..4869cc776dfeab
--- /dev/null
+++ b/clang/test/Headers/meta.cpp
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify
+
+#include <meta>
+
+static_assert(__is_same(std::meta::info, decltype(^^int)));
+
+struct S {};
+namespace A{};
+
+consteval void test_pass() {
+ static_assert(std::meta::is_type(^^int));
+ static_assert(std::meta::is_type(^^unsigned));
+ static_assert(std::meta::is_type(^^long));
+ static_assert(std::meta::is_type(^^long long));
+ static_assert(std::meta::is_type(^^short));
+ static_assert(std::meta::is_type(^^char));
+ static_assert(std::meta::is_type(^^signed char));
+ static_assert(std::meta::is_type(^^unsigned char));
+ static_assert(std::meta::is_type(^^wchar_t));
+ static_assert(std::meta::is_type(^^char8_t));
+ static_assert(std::meta::is_type(^^char16_t));
+ static_assert(std::meta::is_type(^^char32_t));
+ static_assert(std::meta::is_type(^^bool));
+ static_assert(std::meta::is_type(^^float));
+ static_assert(std::meta::is_type(^^double));
+ static_assert(std::meta::is_type(^^long double));
+ static_assert(std::meta::is_type(^^void));
+ static_assert(std::meta::is_type(^^decltype(nullptr)));
+
+ constexpr std::meta::info null{};
+ static_assert(!std::meta::is_type(null));
+}
+
+using IntAlias = int;
+static_assert(std::meta::is_type(^^const int));
+static_assert(std::meta::is_type(^^volatile int));
+static_assert(std::meta::is_type(^^IntAlias));
+static_assert(std::meta::is_type(^^std::meta::info));
+
+constexpr std::meta::info r = ^^int;
+static_assert(std::meta::is_type(r));
+static_assert(!std::meta::is_type(std::meta::info{}));
+
+template <std::meta::info R> consteval bool f() { return std::meta::is_type(R); }
+static_assert(f<^^int>());
+
+bool x = std::meta::is_type(^^int);
+constexpr bool y = std::meta::is_type(^^int);
+
+auto *fp = &std::meta::is_type; // expected-error {{cannot take address of consteval function 'is_type' outside of an immediate invocation}}
+ // expected-note@*:* {{declared here}}
+
+consteval void test_fail() {
+ static_assert(std::meta::is_type(^^S)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(!std::meta::is_type(^^A)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(std::meta::is_type(^^int*)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(std::meta::is_type(^^int&)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(std::meta::is_type(^^int[3])); // expected-error {{unknown or unimplemented reflectable entity}}
+}
+
+consteval bool test_with_no_arg() {
+ return std::meta::is_type(); // expected-error {{too few arguments to function call, single argument '__r' was not specified}}
+ // expected-note@*:* {{'is_type' declared here}}
+}
+
+consteval bool test_with_more_than_args_needed() {
+ return std::meta::is_type(^^int, ^^float); // expected-error {{too many arguments to function call, expected single argument '__r', have 2 arguments}}
+ // expected-note@*:* {{'is_type' declared here}}
+}
+
+consteval bool test_with_wrong_type() {
+ return std::meta::is_type(42); // expected-error {{cannot initialize a parameter of type 'info' (aka 'std::meta::info') with an rvalue of type 'int'}}
+ // expected-note@*:* {{passing argument to parameter '__r' here}}
+}
+
diff --git a/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp
index b505f18dff14fe..d92bf9a5b7413f 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -16,6 +16,7 @@
// RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS
// RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify %s
// RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify %s
+// RUN: %clang_cc1 -std=c++2c -freflection -DNO_EXCEPTIONS -DREFLECTION -verify %s
// expected-no-diagnostics
@@ -58,6 +59,11 @@
#error "wrong value for __cpp_trivial_relocatability"
#endif
+#if defined(REFLECTION) ? check(impl_reflection, 0, 0, 0, 0, 0, 0, 202506) : \
+ check(impl_reflection, 0, 0, 0, 0, 0, 0, 0)
+#error "wrong value for __cpp_impl_reflection"
+#endif
+
// --- C++23 features ---
#if check(auto_cast, 202110, 202110, 202110, 202110, 202110, 202110, 202110)
diff --git a/clang/test/SemaCXX/builtin-meta-is-type.cpp b/clang/test/SemaCXX/builtin-meta-is-type.cpp
new file mode 100644
index 00000000000000..fdeb3bd31b91b1
--- /dev/null
+++ b/clang/test/SemaCXX/builtin-meta-is-type.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify
+
+using info = decltype(^^int);
+
+struct S {};
+namespace A{};
+
+consteval void test_pass() {
+ static_assert(__builtin_meta_is_type(^^int));
+ static_assert(__builtin_meta_is_type(^^unsigned));
+ static_assert(__builtin_meta_is_type(^^long));
+ static_assert(__builtin_meta_is_type(^^long long));
+ static_assert(__builtin_meta_is_type(^^short));
+ static_assert(__builtin_meta_is_type(^^char));
+ static_assert(__builtin_meta_is_type(^^signed char));
+ static_assert(__builtin_meta_is_type(^^unsigned char));
+ static_assert(__builtin_meta_is_type(^^wchar_t));
+ static_assert(__builtin_meta_is_type(^^char8_t));
+ static_assert(__builtin_meta_is_type(^^char16_t));
+ static_assert(__builtin_meta_is_type(^^char32_t));
+ static_assert(__builtin_meta_is_type(^^bool));
+ static_assert(__builtin_meta_is_type(^^float));
+ static_assert(__builtin_meta_is_type(^^double));
+ static_assert(__builtin_meta_is_type(^^long double));
+ static_assert(__builtin_meta_is_type(^^void));
+ static_assert(__builtin_meta_is_type(^^decltype(nullptr)));
+
+ constexpr info null{};
+ static_assert(!__builtin_meta_is_type(null));
+}
+
+using IntAlias = int;
+static_assert(__builtin_meta_is_type(^^const int));
+static_assert(__builtin_meta_is_type(^^volatile int));
+static_assert(__builtin_meta_is_type(^^IntAlias));
+static_assert(__builtin_meta_is_type(^^info));
+
+constexpr info r = ^^int;
+static_assert(__builtin_meta_is_type(r));
+static_assert(!__builtin_meta_is_type(info{}));
+
+template <info R> consteval bool f() { return __builtin_meta_is_type(R); }
+static_assert(f<^^int>());
+
+bool x = __builtin_meta_is_type(^^int);
+constexpr bool y = __builtin_meta_is_type(^^int);
+
+auto *fp = &__builtin_meta_is_type;
+// expected-error at -1 {{builtin functions must be directly called}}
+// expected-error at -2 {{cannot take address of consteval function '__builtin_meta_is_type' outside of an immediate invocation}}
+
+consteval void test_fail() {
+ static_assert(__builtin_meta_is_type(^^S)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(!__builtin_meta_is_type(^^A)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(__builtin_meta_is_type(^^int*)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(__builtin_meta_is_type(^^int&)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(__builtin_meta_is_type(^^int[3])); // expected-error {{unknown or unimplemented reflectable entity}}
+}
+
+consteval bool test_with_no_arg() {
+ return __builtin_meta_is_type(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+}
+
+consteval bool test_with_more_than_args_needed() {
+ return __builtin_meta_is_type(^^int, ^^float); // expected-error {{too many arguments to function call, expected 1, have 2}}
+}
+
+consteval bool test_with_wrong_type() {
+ return __builtin_meta_is_type(42); // expected-error {{cannot initialize a parameter of type 'std::meta::info' with an rvalue of type 'int'}}
+}
diff --git a/clang/test/SemaCXX/consteval-builtin.cpp b/clang/test/SemaCXX/consteval-builtin.cpp
index 3ba95b4dbd9b50..7b45e3ddc1f789 100644
--- a/clang/test/SemaCXX/consteval-builtin.cpp
+++ b/clang/test/SemaCXX/consteval-builtin.cpp
@@ -25,6 +25,24 @@
// precxx20-error at -3 {{does not have the constexpr builtin}}
// c-error at -4 {{does not have the constexpr builtin}}
+#if __has_builtin(__builtin_meta_is_type)
+#error has the builtin
+#else
+#error does not have the builtin
+#endif
+// cxx20-cxx26-error at -4 {{has the builtin}}
+// precxx20-error at -3 {{does not have the builtin}}
+// c-error at -4 {{does not have the builtin}}
+
+#if __has_constexpr_builtin(__builtin_meta_is_type)
+#error has the constexpr builtin
+#else
+#error does not have the constexpr builtin
+#endif
+// cxx20-cxx26-error at -4 {{has the constexpr builtin}}
+// precxx20-error at -3 {{does not have the constexpr builtin}}
+// c-error at -4 {{does not have the constexpr builtin}}
+
#if __cplusplus < 201103L
#define static_assert __extension__ _Static_assert
#define CONSTEXPR11
diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
index 22c81522f9e41c..259df9275641a9 100644
--- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
@@ -376,6 +376,7 @@ class PrototypeParser {
.Case("short", "s")
.Case("sigjmp_buf", "SJ")
.Case("size_t", "z")
+ .Case("std::meta::info", "r")
.Case("ucontext_t", "K")
.Case("uint8_t", "UBi")
.Case("uint16_t", "UTi")
>From 46bd129a0c5c6f290f2cc25c02c5446176e9473a Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Tue, 20 Oct 2026 20:30:50 +0000
Subject: [PATCH 02/16] move meta builtins into a new file
---
clang/include/clang/Basic/Builtins.td | 7 +------
clang/include/clang/Basic/BuiltinsMeta.td | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 6 deletions(-)
create mode 100644 clang/include/clang/Basic/BuiltinsMeta.td
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 4f039de6e0fc07..c3728feb42d1fb 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
include "clang/Basic/BuiltinsBase.td"
+include "clang/Basic/BuiltinsMeta.td"
class FPMathTemplate : Template<["float", "double", "long double"],
["f", "", "l"]>;
@@ -1207,12 +1208,6 @@ def IsWithinLifetime : LangBuiltin<"CXX_LANG"> {
let Prototype = "bool(void*)";
}
-def MetaIsType : LangBuiltin<"CXX_LANG"> {
- let Spellings = ["__builtin_meta_is_type"];
- let Attributes = [NoThrow, Consteval];
- let Prototype = "bool(std::meta::info)";
-}
-
def ClearPadding : Builtin {
let Spellings = ["__builtin_clear_padding"];
let Attributes = [NoThrow, CustomTypeChecking];
diff --git a/clang/include/clang/Basic/BuiltinsMeta.td b/clang/include/clang/Basic/BuiltinsMeta.td
new file mode 100644
index 00000000000000..dc3ddf7b68f2cb
--- /dev/null
+++ b/clang/include/clang/Basic/BuiltinsMeta.td
@@ -0,0 +1,18 @@
+//===--- BuiltinsMeta.td - Builtins for reflection metafunctions ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===-------------------------------------------------------------------------===//
+
+// All metafunctions should be consteval.
+class CXXMetaBuiltin<string prototype, list<Attribute> Attrs = []>
+ : LangBuiltin<"CXX_LANG"> {
+ let Prototype = prototype;
+ let Attributes = !listconcat([Consteval], Attrs);
+}
+
+def MetaIsType : CXXMetaBuiltin<"bool(std::meta::info)", [NoThrow]> {
+ let Spellings = ["__builtin_meta_is_type"];
+}
>From e783c2dbed1b844031ff200194b7bcc7eb8a4296 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Thu, 22 Oct 2026 16:19:57 +0000
Subject: [PATCH 03/16] move include to end of file and use strconcat for
naming metafunctions
---
clang/include/clang/Basic/Builtins.td | 6 +++++-
clang/include/clang/Basic/BuiltinsMeta.td | 9 ++++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index c3728feb42d1fb..573b6b2947e882 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
include "clang/Basic/BuiltinsBase.td"
-include "clang/Basic/BuiltinsMeta.td"
class FPMathTemplate : Template<["float", "double", "long double"],
["f", "", "l"]>;
@@ -6048,3 +6047,8 @@ def CountedByRef : Builtin {
let Attributes = [NoThrow, CustomTypeChecking];
let Prototype = "int(...)";
}
+
+//===----------------------------------------------------------------------===//
+// C++26 reflection metafunctions.
+//===----------------------------------------------------------------------===//
+include "clang/Basic/BuiltinsMeta.td"
diff --git a/clang/include/clang/Basic/BuiltinsMeta.td b/clang/include/clang/Basic/BuiltinsMeta.td
index dc3ddf7b68f2cb..d0380331a2fb6a 100644
--- a/clang/include/clang/Basic/BuiltinsMeta.td
+++ b/clang/include/clang/Basic/BuiltinsMeta.td
@@ -6,13 +6,12 @@
//
//===-------------------------------------------------------------------------===//
-// All metafunctions should be consteval.
-class CXXMetaBuiltin<string prototype, list<Attribute> Attrs = []>
+// All metafunctions should be consteval.
+class CXXMetaBuiltin<string name, string prototype, list<Attribute> Attrs = []>
: LangBuiltin<"CXX_LANG"> {
+ let Spellings = [!strconcat("__builtin_meta_", name)];
let Prototype = prototype;
let Attributes = !listconcat([Consteval], Attrs);
}
-def MetaIsType : CXXMetaBuiltin<"bool(std::meta::info)", [NoThrow]> {
- let Spellings = ["__builtin_meta_is_type"];
-}
+def MetaIsType : CXXMetaBuiltin<"is_type", "bool(std::meta::info)", [NoThrow]>;
>From 5c7ded8281d523b63371b9bd0dabb97638f84d17 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Thu, 22 Oct 2026 16:54:21 +0000
Subject: [PATCH 04/16] remove feature test macro
---
clang/lib/Frontend/InitPreprocessor.cpp | 2 +-
clang/lib/Headers/meta | 13 +++++++------
clang/test/Lexer/cxx-features.cpp | 6 ------
3 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index fad6a07fc3a2d8..b666b6bb66e15b 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -768,7 +768,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
// C++26 reflection.
if (LangOpts.Reflection)
- Builder.defineMacro("__cpp_impl_reflection", "202506L");
+ Builder.defineMacro("__CLANG_CXX_REFLECTION__");
if (LangOpts.Char8)
Builder.defineMacro("__cpp_char8_t", "202207L");
diff --git a/clang/lib/Headers/meta b/clang/lib/Headers/meta
index 5f766c63c70f93..3491a0331be326 100644
--- a/clang/lib/Headers/meta
+++ b/clang/lib/Headers/meta
@@ -10,15 +10,14 @@
#ifndef __CLANG_META
#define __CLANG_META
-#if !defined(__cplusplus)
+#if !defined(__clang__)
+#error "this meta header was vendored by clang and only works when compiling with clang"
+#elif !defined(__cplusplus)
#error "meta header is only available in C++ mode"
-#endif
-
-#if !defined(__cpp_impl_reflection)
+#elif !defined(__CLANG_CXX_REFLECTION__)
#error "meta header is only available when -freflection is enabled"
-#endif
+#else
-#define __cpp_lib_reflection 202506L
namespace std {
namespace meta {
@@ -32,4 +31,6 @@ consteval bool is_type(info __r) {
} // namespace meta
} // namespace std
+#endif
+
#endif // __CLANG_META
diff --git a/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp
index d92bf9a5b7413f..b505f18dff14fe 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -16,7 +16,6 @@
// RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS
// RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify %s
// RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify %s
-// RUN: %clang_cc1 -std=c++2c -freflection -DNO_EXCEPTIONS -DREFLECTION -verify %s
// expected-no-diagnostics
@@ -59,11 +58,6 @@
#error "wrong value for __cpp_trivial_relocatability"
#endif
-#if defined(REFLECTION) ? check(impl_reflection, 0, 0, 0, 0, 0, 0, 202506) : \
- check(impl_reflection, 0, 0, 0, 0, 0, 0, 0)
-#error "wrong value for __cpp_impl_reflection"
-#endif
-
// --- C++23 features ---
#if check(auto_cast, 202110, 202110, 202110, 202110, 202110, 202110, 202110)
>From 39abad182dc988832de353f333e3d69d40416c7d Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Tue, 27 Oct 2026 18:56:31 +0000
Subject: [PATCH 05/16] merge test files into one
---
clang/test/Headers/meta.cpp | 104 +++++++++++---------
clang/test/SemaCXX/builtin-meta-is-type.cpp | 71 -------------
2 files changed, 60 insertions(+), 115 deletions(-)
delete mode 100644 clang/test/SemaCXX/builtin-meta-is-type.cpp
diff --git a/clang/test/Headers/meta.cpp b/clang/test/Headers/meta.cpp
index 4869cc776dfeab..d15cac35d1e7ca 100644
--- a/clang/test/Headers/meta.cpp
+++ b/clang/test/Headers/meta.cpp
@@ -1,76 +1,92 @@
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
#include <meta>
+#ifdef USE_BUILTIN
+# define meta_is_type __builtin_meta_is_type
+#else
+# define meta_is_type std::meta::is_type
+#endif
+
static_assert(__is_same(std::meta::info, decltype(^^int)));
struct S {};
namespace A{};
consteval void test_pass() {
- static_assert(std::meta::is_type(^^int));
- static_assert(std::meta::is_type(^^unsigned));
- static_assert(std::meta::is_type(^^long));
- static_assert(std::meta::is_type(^^long long));
- static_assert(std::meta::is_type(^^short));
- static_assert(std::meta::is_type(^^char));
- static_assert(std::meta::is_type(^^signed char));
- static_assert(std::meta::is_type(^^unsigned char));
- static_assert(std::meta::is_type(^^wchar_t));
- static_assert(std::meta::is_type(^^char8_t));
- static_assert(std::meta::is_type(^^char16_t));
- static_assert(std::meta::is_type(^^char32_t));
- static_assert(std::meta::is_type(^^bool));
- static_assert(std::meta::is_type(^^float));
- static_assert(std::meta::is_type(^^double));
- static_assert(std::meta::is_type(^^long double));
- static_assert(std::meta::is_type(^^void));
- static_assert(std::meta::is_type(^^decltype(nullptr)));
+ static_assert(meta_is_type(^^int));
+ static_assert(meta_is_type(^^unsigned));
+ static_assert(meta_is_type(^^long));
+ static_assert(meta_is_type(^^long long));
+ static_assert(meta_is_type(^^short));
+ static_assert(meta_is_type(^^char));
+ static_assert(meta_is_type(^^signed char));
+ static_assert(meta_is_type(^^unsigned char));
+ static_assert(meta_is_type(^^wchar_t));
+ static_assert(meta_is_type(^^char8_t));
+ static_assert(meta_is_type(^^char16_t));
+ static_assert(meta_is_type(^^char32_t));
+ static_assert(meta_is_type(^^bool));
+ static_assert(meta_is_type(^^float));
+ static_assert(meta_is_type(^^double));
+ static_assert(meta_is_type(^^long double));
+ static_assert(meta_is_type(^^void));
+ static_assert(meta_is_type(^^decltype(nullptr)));
constexpr std::meta::info null{};
- static_assert(!std::meta::is_type(null));
+ static_assert(!meta_is_type(null));
}
using IntAlias = int;
-static_assert(std::meta::is_type(^^const int));
-static_assert(std::meta::is_type(^^volatile int));
-static_assert(std::meta::is_type(^^IntAlias));
-static_assert(std::meta::is_type(^^std::meta::info));
+static_assert(meta_is_type(^^const int));
+static_assert(meta_is_type(^^volatile int));
+static_assert(meta_is_type(^^IntAlias));
+static_assert(meta_is_type(^^std::meta::info));
constexpr std::meta::info r = ^^int;
-static_assert(std::meta::is_type(r));
-static_assert(!std::meta::is_type(std::meta::info{}));
+static_assert(meta_is_type(r));
+static_assert(!meta_is_type(std::meta::info{}));
-template <std::meta::info R> consteval bool f() { return std::meta::is_type(R); }
+template <std::meta::info R> consteval bool f() { return meta_is_type(R); }
static_assert(f<^^int>());
-bool x = std::meta::is_type(^^int);
-constexpr bool y = std::meta::is_type(^^int);
+bool x = meta_is_type(^^int);
+constexpr bool y = meta_is_type(^^int);
-auto *fp = &std::meta::is_type; // expected-error {{cannot take address of consteval function 'is_type' outside of an immediate invocation}}
- // expected-note@*:* {{declared here}}
+auto *fp = &meta_is_type;
+// std-error at -1 {{cannot take address of consteval function 'is_type' outside of an immediate invocation}}
+// std-note@*:* {{declared here}}
+// builtin-error at -3 {{builtin functions must be directly called}}
+// builtin-error at -4 {{cannot take address of consteval function '__builtin_meta_is_type' outside of an immediate invocation}}
consteval void test_fail() {
- static_assert(std::meta::is_type(^^S)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(!std::meta::is_type(^^A)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(std::meta::is_type(^^int*)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(std::meta::is_type(^^int&)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(std::meta::is_type(^^int[3])); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(meta_is_type(^^S)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(!meta_is_type(^^A)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(meta_is_type(^^int*)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(meta_is_type(^^int&)); // expected-error {{unknown or unimplemented reflectable entity}}
+ static_assert(meta_is_type(^^int[3])); // expected-error {{unknown or unimplemented reflectable entity}}
}
consteval bool test_with_no_arg() {
- return std::meta::is_type(); // expected-error {{too few arguments to function call, single argument '__r' was not specified}}
- // expected-note@*:* {{'is_type' declared here}}
+ return meta_is_type();
+ // std-error at -1 {{too few arguments to function call, single argument '__r' was not specified}}
+ // std-note@*:* {{'is_type' declared here}}
+ // builtin-error at -3 {{too few arguments to function call, expected 1, have 0}}
}
consteval bool test_with_more_than_args_needed() {
- return std::meta::is_type(^^int, ^^float); // expected-error {{too many arguments to function call, expected single argument '__r', have 2 arguments}}
- // expected-note@*:* {{'is_type' declared here}}
+ return meta_is_type(^^int, ^^float);
+ // std-error at -1 {{too many arguments to function call, expected single argument '__r', have 2 arguments}}
+ // std-note@*:* {{'is_type' declared here}}
+ // builtin-error at -3 {{too many arguments to function call, expected 1, have 2}}
}
consteval bool test_with_wrong_type() {
- return std::meta::is_type(42); // expected-error {{cannot initialize a parameter of type 'info' (aka 'std::meta::info') with an rvalue of type 'int'}}
- // expected-note@*:* {{passing argument to parameter '__r' here}}
+ return meta_is_type(42);
+ // std-error at -1 {{cannot initialize a parameter of type 'info' (aka 'std::meta::info') with an rvalue of type 'int'}}
+ // std-note@*:* {{passing argument to parameter '__r' here}}
+ // builtin-error at -3 {{cannot initialize a parameter of type 'std::meta::info' with an rvalue of type 'int'}}
}
-
diff --git a/clang/test/SemaCXX/builtin-meta-is-type.cpp b/clang/test/SemaCXX/builtin-meta-is-type.cpp
deleted file mode 100644
index fdeb3bd31b91b1..00000000000000
--- a/clang/test/SemaCXX/builtin-meta-is-type.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify
-
-using info = decltype(^^int);
-
-struct S {};
-namespace A{};
-
-consteval void test_pass() {
- static_assert(__builtin_meta_is_type(^^int));
- static_assert(__builtin_meta_is_type(^^unsigned));
- static_assert(__builtin_meta_is_type(^^long));
- static_assert(__builtin_meta_is_type(^^long long));
- static_assert(__builtin_meta_is_type(^^short));
- static_assert(__builtin_meta_is_type(^^char));
- static_assert(__builtin_meta_is_type(^^signed char));
- static_assert(__builtin_meta_is_type(^^unsigned char));
- static_assert(__builtin_meta_is_type(^^wchar_t));
- static_assert(__builtin_meta_is_type(^^char8_t));
- static_assert(__builtin_meta_is_type(^^char16_t));
- static_assert(__builtin_meta_is_type(^^char32_t));
- static_assert(__builtin_meta_is_type(^^bool));
- static_assert(__builtin_meta_is_type(^^float));
- static_assert(__builtin_meta_is_type(^^double));
- static_assert(__builtin_meta_is_type(^^long double));
- static_assert(__builtin_meta_is_type(^^void));
- static_assert(__builtin_meta_is_type(^^decltype(nullptr)));
-
- constexpr info null{};
- static_assert(!__builtin_meta_is_type(null));
-}
-
-using IntAlias = int;
-static_assert(__builtin_meta_is_type(^^const int));
-static_assert(__builtin_meta_is_type(^^volatile int));
-static_assert(__builtin_meta_is_type(^^IntAlias));
-static_assert(__builtin_meta_is_type(^^info));
-
-constexpr info r = ^^int;
-static_assert(__builtin_meta_is_type(r));
-static_assert(!__builtin_meta_is_type(info{}));
-
-template <info R> consteval bool f() { return __builtin_meta_is_type(R); }
-static_assert(f<^^int>());
-
-bool x = __builtin_meta_is_type(^^int);
-constexpr bool y = __builtin_meta_is_type(^^int);
-
-auto *fp = &__builtin_meta_is_type;
-// expected-error at -1 {{builtin functions must be directly called}}
-// expected-error at -2 {{cannot take address of consteval function '__builtin_meta_is_type' outside of an immediate invocation}}
-
-consteval void test_fail() {
- static_assert(__builtin_meta_is_type(^^S)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(!__builtin_meta_is_type(^^A)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(__builtin_meta_is_type(^^int*)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(__builtin_meta_is_type(^^int&)); // expected-error {{unknown or unimplemented reflectable entity}}
- static_assert(__builtin_meta_is_type(^^int[3])); // expected-error {{unknown or unimplemented reflectable entity}}
-}
-
-consteval bool test_with_no_arg() {
- return __builtin_meta_is_type(); // expected-error {{too few arguments to function call, expected 1, have 0}}
-}
-
-consteval bool test_with_more_than_args_needed() {
- return __builtin_meta_is_type(^^int, ^^float); // expected-error {{too many arguments to function call, expected 1, have 2}}
-}
-
-consteval bool test_with_wrong_type() {
- return __builtin_meta_is_type(42); // expected-error {{cannot initialize a parameter of type 'std::meta::info' with an rvalue of type 'int'}}
-}
>From c41438a53582c0516d628f0c1f5e7e4ce40d666b Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Tue, 27 Oct 2026 20:56:19 +0000
Subject: [PATCH 06/16] meta builtin can only be used in -freflection
---
clang/include/clang/Basic/Builtins.h | 1 +
clang/include/clang/Basic/BuiltinsMeta.td | 2 +-
clang/lib/Basic/Builtins.cpp | 3 +++
clang/test/SemaCXX/builtin-metafunctions.cpp | 22 ++++++++++++++++++++
clang/test/SemaCXX/consteval-builtin.cpp | 18 ----------------
5 files changed, 27 insertions(+), 19 deletions(-)
create mode 100644 clang/test/SemaCXX/builtin-metafunctions.cpp
diff --git a/clang/include/clang/Basic/Builtins.h b/clang/include/clang/Basic/Builtins.h
index e39c7fe93561a4..7f56f4306c82ac 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -48,6 +48,7 @@ enum LanguageID : uint16_t {
HLSL_LANG = 0x1000, // builtin requires HLSL.
C23_LANG = 0x2000, // builtin requires C23 or later.
C2Y_LANG = 0x4000, // builtin requires C2y or later.
+ REFLECTION_LANG = 0x8000, // builtin requires use of 'freflection' option.
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
diff --git a/clang/include/clang/Basic/BuiltinsMeta.td b/clang/include/clang/Basic/BuiltinsMeta.td
index d0380331a2fb6a..4d109a153a7645 100644
--- a/clang/include/clang/Basic/BuiltinsMeta.td
+++ b/clang/include/clang/Basic/BuiltinsMeta.td
@@ -8,7 +8,7 @@
// All metafunctions should be consteval.
class CXXMetaBuiltin<string name, string prototype, list<Attribute> Attrs = []>
- : LangBuiltin<"CXX_LANG"> {
+ : LangBuiltin<"REFLECTION_LANG"> {
let Spellings = [!strconcat("__builtin_meta_", name)];
let Prototype = prototype;
let Attributes = !listconcat([Consteval], Attrs);
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index 3bf87ca94f5426..b854f47a6b26b3 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -213,6 +213,9 @@ static bool builtinIsSupported(const llvm::StringTable &Strings,
/* C2y unsupported */
if (!LangOpts.C2y && BuiltinInfo.Langs == C2Y_LANG)
return false;
+ /* Reflection unsupported */
+ if (!LangOpts.Reflection && (BuiltinInfo.Langs & REFLECTION_LANG))
+ return false;
return true;
}
diff --git a/clang/test/SemaCXX/builtin-metafunctions.cpp b/clang/test/SemaCXX/builtin-metafunctions.cpp
new file mode 100644
index 00000000000000..622135f2aabab1
--- /dev/null
+++ b/clang/test/SemaCXX/builtin-metafunctions.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++26 -freflection -fsyntax-only %s -verify=metabuiltin
+// RUN: %clang_cc1 -std=c++26 -fsyntax-only %s -verify=nometabuiltin
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only %s -verify=nometabuiltin
+// RUN: %clang_cc1 -x c -std=c23 -fsyntax-only %s -verify=nometabuiltin
+
+// Metafunction builtins are only enabled in C++26 (-freflection enabled).
+
+#if __has_builtin(__builtin_meta_is_type)
+#error has the builtin
+#else
+#error does not have the builtin
+#endif
+// metabuiltin-error at -4 {{has the builtin}}
+// nometabuiltin-error at -3 {{does not have the builtin}}
+
+#if __has_constexpr_builtin(__builtin_meta_is_type)
+#error has the constexpr builtin
+#else
+#error does not have the constexpr builtin
+#endif
+// metabuiltin-error at -4 {{has the constexpr builtin}}
+// nometabuiltin-error at -3 {{does not have the constexpr builtin}}
diff --git a/clang/test/SemaCXX/consteval-builtin.cpp b/clang/test/SemaCXX/consteval-builtin.cpp
index 7b45e3ddc1f789..3ba95b4dbd9b50 100644
--- a/clang/test/SemaCXX/consteval-builtin.cpp
+++ b/clang/test/SemaCXX/consteval-builtin.cpp
@@ -25,24 +25,6 @@
// precxx20-error at -3 {{does not have the constexpr builtin}}
// c-error at -4 {{does not have the constexpr builtin}}
-#if __has_builtin(__builtin_meta_is_type)
-#error has the builtin
-#else
-#error does not have the builtin
-#endif
-// cxx20-cxx26-error at -4 {{has the builtin}}
-// precxx20-error at -3 {{does not have the builtin}}
-// c-error at -4 {{does not have the builtin}}
-
-#if __has_constexpr_builtin(__builtin_meta_is_type)
-#error has the constexpr builtin
-#else
-#error does not have the constexpr builtin
-#endif
-// cxx20-cxx26-error at -4 {{has the constexpr builtin}}
-// precxx20-error at -3 {{does not have the constexpr builtin}}
-// c-error at -4 {{does not have the constexpr builtin}}
-
#if __cplusplus < 201103L
#define static_assert __extension__ _Static_assert
#define CONSTEXPR11
>From 2e9f650ef60aab6857cc4ecf01db041356accbe5 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 15:35:42 +0000
Subject: [PATCH 07/16] tests cover more cases
---
clang/test/Headers/meta.cpp | 83 ++++++++++++++++++++++++++++---------
1 file changed, 63 insertions(+), 20 deletions(-)
diff --git a/clang/test/Headers/meta.cpp b/clang/test/Headers/meta.cpp
index d15cac35d1e7ca..05f8ba0ddab252 100644
--- a/clang/test/Headers/meta.cpp
+++ b/clang/test/Headers/meta.cpp
@@ -1,9 +1,11 @@
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,std
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,std
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
#include <meta>
+#include <stdint.h>
+#include <stddef.h>
#ifdef USE_BUILTIN
# define meta_is_type __builtin_meta_is_type
@@ -16,35 +18,76 @@ static_assert(__is_same(std::meta::info, decltype(^^int)));
struct S {};
namespace A{};
+using IntAlias = int;
+using ConstIntAlias = const int;
+template <typename T> using Identity = T;
+
consteval void test_pass() {
- static_assert(meta_is_type(^^int));
- static_assert(meta_is_type(^^unsigned));
- static_assert(meta_is_type(^^long));
- static_assert(meta_is_type(^^long long));
- static_assert(meta_is_type(^^short));
+ static_assert(meta_is_type(^^std::meta::info));
+ static_assert(meta_is_type(^^void));
+ static_assert(meta_is_type(^^bool));
static_assert(meta_is_type(^^char));
static_assert(meta_is_type(^^signed char));
static_assert(meta_is_type(^^unsigned char));
- static_assert(meta_is_type(^^wchar_t));
+ static_assert(meta_is_type(^^short));
+ static_assert(meta_is_type(^^unsigned short));
+ static_assert(meta_is_type(^^int));
+ static_assert(meta_is_type(^^unsigned int));
+ static_assert(meta_is_type(^^double));
+ static_assert(meta_is_type(^^float));
+ static_assert(meta_is_type(^^long));
+ static_assert(meta_is_type(^^long long));
+ static_assert(meta_is_type(^^unsigned long));
+ static_assert(meta_is_type(^^unsigned long long));
+
static_assert(meta_is_type(^^char8_t));
static_assert(meta_is_type(^^char16_t));
static_assert(meta_is_type(^^char32_t));
- static_assert(meta_is_type(^^bool));
- static_assert(meta_is_type(^^float));
- static_assert(meta_is_type(^^double));
- static_assert(meta_is_type(^^long double));
- static_assert(meta_is_type(^^void));
+ static_assert(meta_is_type(^^wchar_t));
+ static_assert(meta_is_type(^^int8_t));
+ static_assert(meta_is_type(^^int16_t));
+ static_assert(meta_is_type(^^int32_t));
+ static_assert(meta_is_type(^^int64_t));
+ static_assert(meta_is_type(^^uint8_t));
+ static_assert(meta_is_type(^^uint16_t));
+ static_assert(meta_is_type(^^uint32_t));
+ static_assert(meta_is_type(^^uint64_t));
+ static_assert(meta_is_type(^^intmax_t));
+ static_assert(meta_is_type(^^uintmax_t));
+ static_assert(meta_is_type(^^intptr_t));
+ static_assert(meta_is_type(^^uintptr_t));
+ static_assert(meta_is_type(^^size_t));
+#ifdef __SIZEOF_INT128__
+ static_assert(meta_is_type(^^__int128_t));
+ static_assert(meta_is_type(^^__uint128_t));
+#endif
+
+ static_assert(meta_is_type(^^const int));
+ static_assert(meta_is_type(^^volatile int));
+ static_assert(meta_is_type(^^const volatile int));
+ static_assert(meta_is_type(^^int const));
+ static_assert(meta_is_type(^^const unsigned long long));
+ static_assert(meta_is_type(^^volatile double));
+ static_assert(meta_is_type(^^const bool));
+ static_assert(meta_is_type(^^const std::meta::info));
+
+ static_assert(meta_is_type(^^IntAlias));
+ static_assert(meta_is_type(^^const IntAlias));
+ static_assert(meta_is_type(^^ConstIntAlias));
+ static_assert(meta_is_type(^^volatile ConstIntAlias));
+ static_assert(meta_is_type(^^const int32_t));
+ static_assert(meta_is_type(^^Identity<int>));
+ static_assert(meta_is_type(^^Identity<const float>));
+
static_assert(meta_is_type(^^decltype(nullptr)));
+ static_assert(meta_is_type(^^decltype(42)));
+ static_assert(meta_is_type(^^decltype(sizeof(int))));
+ static_assert(meta_is_type(^^decltype(^^int)));
constexpr std::meta::info null{};
static_assert(!meta_is_type(null));
}
-using IntAlias = int;
-static_assert(meta_is_type(^^const int));
-static_assert(meta_is_type(^^volatile int));
-static_assert(meta_is_type(^^IntAlias));
-static_assert(meta_is_type(^^std::meta::info));
constexpr std::meta::info r = ^^int;
static_assert(meta_is_type(r));
>From 763f81db2a40a731d4e9c67eb3592aa154e182c4 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 15:39:18 +0000
Subject: [PATCH 08/16] guard test under macro instead of arch option
---
clang/test/Headers/meta.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/test/Headers/meta.cpp b/clang/test/Headers/meta.cpp
index 05f8ba0ddab252..30557cf58dce52 100644
--- a/clang/test/Headers/meta.cpp
+++ b/clang/test/Headers/meta.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fsyntax-only -verify=expected,std
-// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,std
-// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
-// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
+// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
#include <meta>
#include <stdint.h>
>From f3e97627ea0e4801f922c73a6fd29ec197bb9458 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 18:24:21 +0000
Subject: [PATCH 09/16] refactor one function for all metafunc builtins
---
clang/include/clang/Basic/Builtins.h | 5 ++++
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 19 ++++++++++---
clang/lib/AST/ExprConstant.cpp | 36 ++++++++++++++++++------
3 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/clang/include/clang/Basic/Builtins.h b/clang/include/clang/Basic/Builtins.h
index 7f56f4306c82ac..f6e279ad829c80 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -468,6 +468,11 @@ class Context {
return strchr(getAttributesString(ID), 'G') != nullptr;
}
+ /// Returns true if this is a reflection metafunction builtin.
+ bool isReflectionMetafunctionBuiltin(unsigned ID) const {
+ return getInfo(ID).Langs & REFLECTION_LANG;
+ }
+
private:
std::pair<const InfosShard &, const Info &>
getShardAndInfo(unsigned ID) const;
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index f431b91b2c9a88..2dbdcbdc9e8b15 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2489,13 +2489,24 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
return false;
}
-static bool interp__builtin_meta_is_type(InterpState &S, CodePtr OpPC,
+static bool interp__reflection_builtin_meta_is_type(InterpState &S, CodePtr OpPC,
const CallExpr *) {
const Reflect &R = S.Stk.pop<Reflect>();
S.Stk.push<Boolean>(Boolean::from(R.getKind() == ReflectionKind::Type));
return true;
}
+static bool interp__reflection_metafunction_builtin(InterpState &S, CodePtr OpPC,
+ const CallExpr *Call,
+ uint32_t BuiltinID) {
+ switch (BuiltinID) {
+ case Builtin::BI__builtin_meta_is_type:
+ return interp__reflection_builtin_meta_is_type(S, OpPC, Call);
+ default:
+ llvm_unreachable("unknown metafunction builtin");
+ }
+}
+
static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
const CallExpr *Call) {
@@ -4692,6 +4703,9 @@ static bool interp_builtin_ia32_cvt_vector_to_int(InterpState &S, CodePtr OpPC,
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
uint32_t BuiltinID) {
+ if (S.getASTContext().BuiltinInfo.isReflectionMetafunctionBuiltin(BuiltinID))
+ return interp__reflection_metafunction_builtin(S, OpPC, Call, BuiltinID);
+
const InterpFrame *Frame = S.Current;
switch (BuiltinID) {
case Builtin::BI__builtin_is_constant_evaluated:
@@ -5456,9 +5470,6 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
case Builtin::BI__builtin_is_within_lifetime:
return interp__builtin_is_within_lifetime(S, OpPC, Call);
- case Builtin::BI__builtin_meta_is_type:
- return interp__builtin_meta_is_type(S, OpPC, Call);
-
case Builtin::BI__builtin_elementwise_add_sat:
return interp__builtin_elementwise_int_binop(
S, OpPC, Call, [](const APSInt &LHS, const APSInt &RHS) {
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 234dd038ff5572..c2a8dc3a4de33e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11391,6 +11391,27 @@ static bool EvaluateReflection(const Expr *E, APValue &Result, EvalInfo &Info) {
return ReflectionEvaluator(Info, Result).Visit(E);
}
+static bool EvaluateReflectionBuiltinMetaIsType(EvalInfo &Info, const CallExpr *E,
+ APValue &Result) {
+ APValue Reflection;
+ if (!EvaluateReflection(E->getArg(0), Reflection, Info))
+ return false;
+ Result = APValue(Info.Ctx.MakeIntValue(
+ Reflection.getReflectionOperandKind() == ReflectionKind::Type,
+ E->getType()));
+ return true;
+}
+
+static bool EvaluateReflectionMetafunctionBuiltin(EvalInfo &Info, const CallExpr *E,
+ unsigned BuiltinOp, APValue &Result) {
+ switch (BuiltinOp) {
+ case Builtin::BI__builtin_meta_is_type:
+ return EvaluateReflectionBuiltinMetaIsType(Info, E, Result);
+ default:
+ llvm_unreachable("unknown metafunction builtin");
+ }
+}
+
//===----------------------------------------------------------------------===//
// Member Pointer Evaluation
//===----------------------------------------------------------------------===//
@@ -17095,6 +17116,13 @@ static bool getBuiltinAlignArguments(const CallExpr *E, EvalInfo &Info,
bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
unsigned BuiltinOp) {
+ if (Info.Ctx.BuiltinInfo.isReflectionMetafunctionBuiltin(BuiltinOp)) {
+ APValue Result;
+ if (!EvaluateReflectionMetafunctionBuiltin(Info, E, BuiltinOp, Result))
+ return false;
+ return Success(Result, E);
+ }
+
auto EvalTestOp = [&](llvm::function_ref<bool(const APInt &, const APInt &)>
Fn) {
APValue SourceLHS, SourceRHS;
@@ -17423,14 +17451,6 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
return Success(*result, E);
return false;
- case Builtin::BI__builtin_meta_is_type: {
- APValue Reflection;
- if (!EvaluateReflection(E->getArg(0), Reflection, Info))
- return false;
- return Success(
- Reflection.getReflectionOperandKind() == ReflectionKind::Type, E);
- }
-
case Builtin::BI__builtin_ctz:
case Builtin::BI__builtin_ctzl:
case Builtin::BI__builtin_ctzll:
>From c480a094a15a972de3be48fde7e421d44d679164 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 18:34:01 +0000
Subject: [PATCH 10/16] function description
---
clang/lib/Headers/meta | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/Headers/meta b/clang/lib/Headers/meta
index 3491a0331be326..dd851b80aa5b5f 100644
--- a/clang/lib/Headers/meta
+++ b/clang/lib/Headers/meta
@@ -24,6 +24,7 @@ namespace meta {
using info = decltype(^^int);
+/// \return \c true if \p __r represents an entity whose underlying entity is a type; \c false otherwise.
consteval bool is_type(info __r) {
return __builtin_meta_is_type(__r);
}
>From d4f66d89848b060ae40275c6ea810d2f45817025 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 18:43:58 +0000
Subject: [PATCH 11/16] clang format
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 12 +++++++-----
clang/lib/AST/ExprConstant.cpp | 11 +++++++----
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 2dbdcbdc9e8b15..3474e9bca79c98 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2489,16 +2489,18 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
return false;
}
-static bool interp__reflection_builtin_meta_is_type(InterpState &S, CodePtr OpPC,
- const CallExpr *) {
+static bool interp__reflection_builtin_meta_is_type(InterpState &S,
+ CodePtr OpPC,
+ const CallExpr *) {
const Reflect &R = S.Stk.pop<Reflect>();
S.Stk.push<Boolean>(Boolean::from(R.getKind() == ReflectionKind::Type));
return true;
}
-static bool interp__reflection_metafunction_builtin(InterpState &S, CodePtr OpPC,
- const CallExpr *Call,
- uint32_t BuiltinID) {
+static bool interp__reflection_metafunction_builtin(InterpState &S,
+ CodePtr OpPC,
+ const CallExpr *Call,
+ uint32_t BuiltinID) {
switch (BuiltinID) {
case Builtin::BI__builtin_meta_is_type:
return interp__reflection_builtin_meta_is_type(S, OpPC, Call);
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index c2a8dc3a4de33e..85d13f7e440c72 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11391,8 +11391,9 @@ static bool EvaluateReflection(const Expr *E, APValue &Result, EvalInfo &Info) {
return ReflectionEvaluator(Info, Result).Visit(E);
}
-static bool EvaluateReflectionBuiltinMetaIsType(EvalInfo &Info, const CallExpr *E,
- APValue &Result) {
+static bool EvaluateReflectionBuiltinMetaIsType(EvalInfo &Info,
+ const CallExpr *E,
+ APValue &Result) {
APValue Reflection;
if (!EvaluateReflection(E->getArg(0), Reflection, Info))
return false;
@@ -11402,8 +11403,10 @@ static bool EvaluateReflectionBuiltinMetaIsType(EvalInfo &Info, const CallExpr *
return true;
}
-static bool EvaluateReflectionMetafunctionBuiltin(EvalInfo &Info, const CallExpr *E,
- unsigned BuiltinOp, APValue &Result) {
+static bool EvaluateReflectionMetafunctionBuiltin(EvalInfo &Info,
+ const CallExpr *E,
+ unsigned BuiltinOp,
+ APValue &Result) {
switch (BuiltinOp) {
case Builtin::BI__builtin_meta_is_type:
return EvaluateReflectionBuiltinMetaIsType(Info, E, Result);
>From 08b6d11fda0fcf3ba82843b0ab7fe3cb31296ec0 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nhat7203 at gmail.com>
Date: Wed, 28 Oct 2026 15:31:43 -0400
Subject: [PATCH 12/16] Update clang/lib/Headers/meta
Co-authored-by: Ambrose Leeb <aeternalmail at gmail.com>
---
clang/lib/Headers/meta | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Headers/meta b/clang/lib/Headers/meta
index dd851b80aa5b5f..2018642497000a 100644
--- a/clang/lib/Headers/meta
+++ b/clang/lib/Headers/meta
@@ -11,11 +11,11 @@
#define __CLANG_META
#if !defined(__clang__)
-#error "this meta header was vendored by clang and only works when compiling with clang"
+#error "this <meta> header is part of Clang and can only be used when compiling with Clang"
#elif !defined(__cplusplus)
-#error "meta header is only available in C++ mode"
+#error "<meta> is only available in C++ mode"
#elif !defined(__CLANG_CXX_REFLECTION__)
-#error "meta header is only available when -freflection is enabled"
+#error "<meta> is only available when -freflection is enabled"
#else
>From d63e917b8d572be13af87545355298db8c1acfe5 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 21:37:59 +0000
Subject: [PATCH 13/16] move the impl inside the main function in the old
evaluator
---
clang/lib/AST/ExprConstant.cpp | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 85d13f7e440c72..4377f0af967c0c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11391,25 +11391,20 @@ static bool EvaluateReflection(const Expr *E, APValue &Result, EvalInfo &Info) {
return ReflectionEvaluator(Info, Result).Visit(E);
}
-static bool EvaluateReflectionBuiltinMetaIsType(EvalInfo &Info,
- const CallExpr *E,
- APValue &Result) {
- APValue Reflection;
- if (!EvaluateReflection(E->getArg(0), Reflection, Info))
- return false;
- Result = APValue(Info.Ctx.MakeIntValue(
- Reflection.getReflectionOperandKind() == ReflectionKind::Type,
- E->getType()));
- return true;
-}
-
static bool EvaluateReflectionMetafunctionBuiltin(EvalInfo &Info,
const CallExpr *E,
unsigned BuiltinOp,
APValue &Result) {
switch (BuiltinOp) {
- case Builtin::BI__builtin_meta_is_type:
- return EvaluateReflectionBuiltinMetaIsType(Info, E, Result);
+ case Builtin::BI__builtin_meta_is_type: {
+ APValue Reflection;
+ if (!EvaluateReflection(E->getArg(0), Reflection, Info))
+ return false;
+ Result = APValue(Info.Ctx.MakeIntValue(
+ Reflection.getReflectionOperandKind() == ReflectionKind::Type,
+ E->getType()));
+ return true;
+ }
default:
llvm_unreachable("unknown metafunction builtin");
}
>From f2deb1722c135ce84de1a9094c8cf0a95607bc31 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 22:28:04 +0000
Subject: [PATCH 14/16] refactor new evaluator
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 40 +++++++++++-------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 3474e9bca79c98..c164d11b7f4a84 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2489,26 +2489,6 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
return false;
}
-static bool interp__reflection_builtin_meta_is_type(InterpState &S,
- CodePtr OpPC,
- const CallExpr *) {
- const Reflect &R = S.Stk.pop<Reflect>();
- S.Stk.push<Boolean>(Boolean::from(R.getKind() == ReflectionKind::Type));
- return true;
-}
-
-static bool interp__reflection_metafunction_builtin(InterpState &S,
- CodePtr OpPC,
- const CallExpr *Call,
- uint32_t BuiltinID) {
- switch (BuiltinID) {
- case Builtin::BI__builtin_meta_is_type:
- return interp__reflection_builtin_meta_is_type(S, OpPC, Call);
- default:
- llvm_unreachable("unknown metafunction builtin");
- }
-}
-
static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
const CallExpr *Call) {
@@ -4703,10 +4683,28 @@ static bool interp_builtin_ia32_cvt_vector_to_int(InterpState &S, CodePtr OpPC,
return true;
}
+static bool interp__builtin_meta_is_type(InterpState &S, CodePtr OpPC,
+ const CallExpr *) {
+ const Reflect &R = S.Stk.pop<Reflect>();
+ S.Stk.push<Boolean>(Boolean::from(R.getKind() == ReflectionKind::Type));
+ return true;
+}
+
+static bool InterpretReflectionBuiltin(InterpState &S, CodePtr OpPC,
+ const CallExpr *Call,
+ uint32_t BuiltinID) {
+ switch (BuiltinID) {
+ case Builtin::BI__builtin_meta_is_type:
+ return interp__builtin_meta_is_type(S, OpPC, Call);
+ default:
+ llvm_unreachable("unknown metafunction builtin");
+ }
+}
+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
uint32_t BuiltinID) {
if (S.getASTContext().BuiltinInfo.isReflectionMetafunctionBuiltin(BuiltinID))
- return interp__reflection_metafunction_builtin(S, OpPC, Call, BuiltinID);
+ return InterpretReflectionBuiltin(S, OpPC, Call, BuiltinID);
const InterpFrame *Frame = S.Current;
switch (BuiltinID) {
>From 9b3ddc493fd3b871d6a33185bd848fd244779f9d Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nnguyen326 at bloomberg.net>
Date: Wed, 28 Oct 2026 22:29:31 +0000
Subject: [PATCH 15/16] target x86_64-unknown-linux
---
clang/test/Headers/meta.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/test/Headers/meta.cpp b/clang/test/Headers/meta.cpp
index 30557cf58dce52..05f8ba0ddab252 100644
--- a/clang/test/Headers/meta.cpp
+++ b/clang/test/Headers/meta.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,std
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,std
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
-// RUN: %clang_cc1 %s -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,std
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -std=c++26 -freflection -fexperimental-new-constant-interpreter -fsyntax-only -verify=expected,builtin -DUSE_BUILTIN
#include <meta>
#include <stdint.h>
>From 086a348aebd6aa009ecdf16dcbe2a5a1e5b0e912 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nhat7203 at gmail.com>
Date: Thu, 29 Oct 2026 15:02:11 -0400
Subject: [PATCH 16/16] Update clang/test/Headers/meta.cpp
Co-authored-by: Ambrose Leeb <aeternalmail at gmail.com>
---
clang/test/Headers/meta.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang/test/Headers/meta.cpp b/clang/test/Headers/meta.cpp
index 05f8ba0ddab252..699721319fa226 100644
--- a/clang/test/Headers/meta.cpp
+++ b/clang/test/Headers/meta.cpp
@@ -57,10 +57,8 @@ consteval void test_pass() {
static_assert(meta_is_type(^^intptr_t));
static_assert(meta_is_type(^^uintptr_t));
static_assert(meta_is_type(^^size_t));
-#ifdef __SIZEOF_INT128__
static_assert(meta_is_type(^^__int128_t));
static_assert(meta_is_type(^^__uint128_t));
-#endif
static_assert(meta_is_type(^^const int));
static_assert(meta_is_type(^^volatile int));
More information about the cfe-commits
mailing list