https://github.com/ofAlpaca updated https://github.com/llvm/llvm-project/pull/105983
>From 7f13ff52821a6c2ba58236fe363fb9a3a378c33b Mon Sep 17 00:00:00 2001 From: ofAlpaca <frank70...@gmail.com> Date: Sun, 25 Aug 2024 17:02:11 +0800 Subject: [PATCH 1/5] Fix for GH102064 --- clang/include/clang/Basic/Builtins.td | 2 +- clang/lib/AST/ExprConstant.cpp | 4 ++++ clang/test/SemaCXX/GH102064.cpp | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/GH102064.cpp diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index f5b15cf90d1f83..b42f7ea1d9de68 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -2516,7 +2516,7 @@ def IsoVolatileStore : MSLangBuiltin, Int8_16_32_64Template { def Noop : MSLangBuiltin { let Spellings = ["__noop"]; - let Attributes = [NoThrow]; + let Attributes = [NoThrow, Constexpr]; let Prototype = "int(...)"; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 5af712dd7257b1..d505346bccd9b3 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -12586,6 +12586,10 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, return false; } + case Builtin::BI__noop: + // __noop always evaluates successfully + return true; + case Builtin::BI__builtin_is_constant_evaluated: { const auto *Callee = Info.CurrentCall->getCallee(); if (Info.InConstantContext && !Info.CheckingPotentialConstantExpression && diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp new file mode 100644 index 00000000000000..52213b66e9eccc --- /dev/null +++ b/clang/test/SemaCXX/GH102064.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -std=c++20 -fms-extensions %s +// expected-no-diagnostics +constexpr int x = []{ __noop; return 0; }(); \ No newline at end of file >From 676b1b352d7e3279c6e3681466605e88b81dfdde Mon Sep 17 00:00:00 2001 From: ofAlpaca <frank70...@gmail.com> Date: Sun, 25 Aug 2024 20:03:19 +0800 Subject: [PATCH 2/5] Add release note --- clang/docs/ReleaseNotes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 971df672b6ca1e..e60407061ccd3b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -861,6 +861,8 @@ Bug Fixes to Compiler Builtins - Clang now allows pointee types of atomic builtin arguments to be complete template types that was not instantiated elsewhere. +- Fix ``__noop`` not marked as constexpr. (#GH102064) + Bug Fixes to Attribute Support ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >From 9730d9c50033c44766b370ccc92de6575c1eca29 Mon Sep 17 00:00:00 2001 From: ofAlpaca <frank70...@gmail.com> Date: Sun, 25 Aug 2024 20:13:48 +0800 Subject: [PATCH 3/5] Update testcase for end of file newline --- clang/test/SemaCXX/GH102064.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp index 52213b66e9eccc..0ed930439e3d75 100644 --- a/clang/test/SemaCXX/GH102064.cpp +++ b/clang/test/SemaCXX/GH102064.cpp @@ -1,3 +1,3 @@ // RUN: %clang_cc1 -std=c++20 -fms-extensions %s // expected-no-diagnostics -constexpr int x = []{ __noop; return 0; }(); \ No newline at end of file +constexpr int x = []{ __noop; return 0; }(); >From 1a9a0740a1360443bf5f2ba42f7d263fdf06fdc7 Mon Sep 17 00:00:00 2001 From: ofAlpaca <frank70...@gmail.com> Date: Wed, 28 Aug 2024 00:48:44 +0800 Subject: [PATCH 4/5] Update ReleaseNotes.rst and testcase --- clang/docs/ReleaseNotes.rst | 2 +- clang/test/SemaCXX/GH102064.cpp | 3 --- clang/test/SemaCXX/builtins.cpp | 7 +++++++ 3 files changed, 8 insertions(+), 4 deletions(-) delete mode 100644 clang/test/SemaCXX/GH102064.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e60407061ccd3b..e458c1ba1550f8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -861,7 +861,7 @@ Bug Fixes to Compiler Builtins - Clang now allows pointee types of atomic builtin arguments to be complete template types that was not instantiated elsewhere. -- Fix ``__noop`` not marked as constexpr. (#GH102064) +- ``__noop`` can now be used in a constant expression. (#GH102064) Bug Fixes to Attribute Support ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp deleted file mode 100644 index 0ed930439e3d75..00000000000000 --- a/clang/test/SemaCXX/GH102064.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// RUN: %clang_cc1 -std=c++20 -fms-extensions %s -// expected-no-diagnostics -constexpr int x = []{ __noop; return 0; }(); diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp index 080b4476c7eec1..da4023fd467065 100644 --- a/clang/test/SemaCXX/builtins.cpp +++ b/clang/test/SemaCXX/builtins.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11 -fcxx-exceptions // RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++1z -fcxx-exceptions +// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20 -fms-extensions -DNOOP +#ifndef NOOP typedef const struct __CFString * CFStringRef; #define CFSTR __builtin___CFStringMakeConstantString @@ -175,3 +177,8 @@ template void test_builtin_complex(int, double); // expected-note {{instantiatio static void __builtin_cpu_init(); // expected-error {{static declaration of '__builtin_cpu_init' follows non-static declaration}} \ expected-note {{'__builtin_cpu_init' is a builtin with type 'void () noexcept'}} #endif +#endif // end of NOOP + +#if NOOP +constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics +#endif >From 88505d0d04154a8f8bccaea046047e94ac30aa1e Mon Sep 17 00:00:00 2001 From: ofAlpaca <frank70...@gmail.com> Date: Thu, 29 Aug 2024 11:22:16 +0800 Subject: [PATCH 5/5] Update builtins.cpp with _MSC_VER --- clang/test/SemaCXX/builtins.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp index da4023fd467065..c6fbb8b514d671 100644 --- a/clang/test/SemaCXX/builtins.cpp +++ b/clang/test/SemaCXX/builtins.cpp @@ -1,7 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11 -fcxx-exceptions // RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++1z -fcxx-exceptions -// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20 -fms-extensions -DNOOP -#ifndef NOOP typedef const struct __CFString * CFStringRef; #define CFSTR __builtin___CFStringMakeConstantString @@ -177,8 +175,7 @@ template void test_builtin_complex(int, double); // expected-note {{instantiatio static void __builtin_cpu_init(); // expected-error {{static declaration of '__builtin_cpu_init' follows non-static declaration}} \ expected-note {{'__builtin_cpu_init' is a builtin with type 'void () noexcept'}} #endif -#endif // end of NOOP -#if NOOP +#ifdef _MSC_VER constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits