[clang] [Clang] Add attribute for consteval builtins; Declare constexpr builtins as constexpr in C++ (PR #91894)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 13 02:08:37 PDT 2024


================
@@ -14,13 +14,18 @@ void __builtin_va_copy(double d);
 // expected-error at +2 {{cannot redeclare builtin function '__builtin_va_end'}}
 // expected-note at +1 {{'__builtin_va_end' is a builtin with type}}
 void __builtin_va_end(__builtin_va_list);
-// RUN: %clang_cc1 %s -fsyntax-only -verify 
-// RUN: %clang_cc1 %s -fsyntax-only -verify -x c
 
 void __va_start(__builtin_va_list*, ...);
 
+          void *__builtin_assume_aligned(const void *, size_t, ...);
 #ifdef __cplusplus
-void *__builtin_assume_aligned(const void *, size_t, ...) noexcept;
-#else
-void *__builtin_assume_aligned(const void *, size_t, ...);
+constexpr void *__builtin_assume_aligned(const void *, size_t, ...);
+          void *__builtin_assume_aligned(const void *, size_t, ...) noexcept;
+constexpr void *__builtin_assume_aligned(const void *, size_t, ...) noexcept;
+          void *__builtin_assume_aligned(const void *, size_t, ...) throw();
+constexpr void *__builtin_assume_aligned(const void *, size_t, ...) throw();
+
----------------
cor3ntin wrote:

What is the motivation to allow that?

I kind of understand letting users defining builtin (actually, I am not sure I do). but once the builtin is redefined once, I think should be some sort of consistency with the language rules.
Here if you were to replace `__builtin_assume_aligned` with `f`, it would be ill-formed, for god reason.

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


More information about the cfe-commits mailing list