[clang] e0fa2f1 - `__noop` not marked as constexpr #102064 (#105983)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 30 00:52:29 PDT 2024


Author: ofAlpaca
Date: 2024-08-30T09:52:24+02:00
New Revision: e0fa2f1c2957d9783d21460febf103cecac9e19a

URL: https://github.com/llvm/llvm-project/commit/e0fa2f1c2957d9783d21460febf103cecac9e19a
DIFF: https://github.com/llvm/llvm-project/commit/e0fa2f1c2957d9783d21460febf103cecac9e19a.diff

LOG: `__noop` not marked as constexpr #102064 (#105983)

Fixes #102064

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/Basic/Builtins.td
    clang/lib/AST/ExprConstant.cpp
    clang/test/SemaCXX/builtins.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d3aebdb0b06477..d0ac3b65820b05 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -285,6 +285,13 @@ Bug Fixes in This Version
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+- Fix crash when atomic builtins are called with pointer to zero-size struct (#GH90330)
+
+- Clang now allows pointee types of atomic builtin arguments to be complete template types
+  that was not instantiated elsewhere.
+
+- ``__noop`` can now be used in a constant expression. (#GH102064)
+
 Bug Fixes to Attribute Support
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

diff  --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index ac33672a32b336..8668b25661dec8 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -2518,7 +2518,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 d46f57521a97d3..e8a4d1d3c74102 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12719,6 +12719,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/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index 080b4476c7eec1..c6fbb8b514d671 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -175,3 +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
+
+#ifdef _MSC_VER
+constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
+#endif


        


More information about the cfe-commits mailing list