Author: Demetrios Chiuratto Agourakis Date: 2026-10-23T15:58:04Z New Revision: b9a494531c471f8a9726c8b0c48494766d5a2764
URL: https://github.com/llvm/llvm-project/commit/b9a494531c471f8a9726c8b0c48494766d5a2764 DIFF: https://github.com/llvm/llvm-project/commit/b9a494531c471f8a9726c8b0c48494766d5a2764.diff LOG: [clang] Stop claiming __builtin_assume_separate_storage is constexpr (#225515) `__builtin_assume_separate_storage` was marked `Constexpr`, but constant evaluation never handles it (only CodeGen does). That produces the odd constexpr behavior in #225335. This drops the `Constexpr` attribute. Actually implementing it in the evaluator can be a follow-up; not advertising support is the smaller correct fix. Test: `clang/test/SemaCXX/builtin-assume-separate-storage.cpp` Fixes #225335 Assisted-by: Claude --------- Co-authored-by: Demetrios Chiuratto Agourakis <[email protected]> Added: clang/test/SemaCXX/builtin-assume-separate-storage.cpp Modified: clang/docs/ReleaseNotes.md clang/include/clang/Basic/Builtins.td Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 75d46d9f012b3..adcdd911beb09 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -809,6 +809,7 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and #### Bug Fixes to Compiler Builtins +- Dropped invalid ``constexpr`` specifier from ``__builtin_assume_separate_storage``, which is not supported in constexpr evaluation. (#GH225335) - Fixed a crash when classifying a call to a builtin with dependent arguments, such as when the call is used as an `auto` non-type template argument. - Fixed an assertion failure when diagnosing a constant evaluation failure diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 905c5d29d86e1..60feac55f9968 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4861,7 +4861,7 @@ def Assume : Builtin { def AssumeSeparateStorage : Builtin { let Spellings = ["__builtin_assume_separate_storage"]; - let Attributes = [NoThrow, Constexpr]; + let Attributes = [NoThrow]; let Prototype = "void(void const volatile*, void const volatile*)"; } diff --git a/clang/test/SemaCXX/builtin-assume-separate-storage.cpp b/clang/test/SemaCXX/builtin-assume-separate-storage.cpp new file mode 100644 index 0000000000000..b11e91382a038 --- /dev/null +++ b/clang/test/SemaCXX/builtin-assume-separate-storage.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=ref,both %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,both -fexperimental-new-constant-interpreter %s + +// __builtin_assume_separate_storage is not constant-evaluable (#225335). + +constexpr int separated(int *a, int *b) { // both-error {{constexpr function never produces a constant expression}} + __builtin_assume_separate_storage(a, b); // both-note 2 {{subexpression not valid in a constant expression}} + return 0; +} + +constexpr int a = 1, b = 2; +static_assert(separated(const_cast<int *>(&a), const_cast<int *>(&b)) == 0); // both-error {{static assertion expression is not an integral constant expression}} \ + // both-note {{in call to 'separated(&a, &b)'}} + +// Original reproducer from #225335 +static_assert([] { // both-error {{static assertion expression is not an integral constant expression}} \ + // both-note {{in call to '[] {}.operator()()'}} + int i, j; + __builtin_assume_separate_storage(&i, &j); // both-note {{subexpression not valid in a constant expression}} + return true; +}()); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
