Skip to content

Commit

Permalink
__noop not marked as constexpr #102064 (#105983)
Browse files Browse the repository at this point in the history
Fixes #102064
  • Loading branch information
ofAlpaca authored Aug 30, 2024
1 parent d6ad551 commit e0fa2f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Builtins.td
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)";
}

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
4 changes: 4 additions & 0 deletions clang/test/SemaCXX/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e0fa2f1

Please sign in to comment.