[PATCH] D155707: [clang][Interp] Handle CXXNoexceptExprs
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 26 03:24:28 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG378fcbf20ff8: [clang][Interp] Handle CXXNoexceptExprs (authored by tbaeder).
Changed prior to commit:
https://reviews.llvm.org/D155707?vs=543266&id=544283#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155707/new/
https://reviews.llvm.org/D155707
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp
clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===================================================================
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression -fexperimental-new-constant-interpreter
void f(); // expected-note {{possible target for call}}
void f(int); // expected-note {{possible target for call}}
Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -910,3 +910,25 @@
static_assert(heh(2) == 'h', "");
#endif
}
+
+namespace NE {
+ constexpr int foo() noexcept {
+ return 1;
+ }
+ static_assert(noexcept(foo()), "");
+ constexpr int foo2() {
+ return 1;
+ }
+ static_assert(!noexcept(foo2()), "");
+
+#if __cplusplus > 201402L
+ constexpr int a() {
+ int b = 0;
+ (void)noexcept(++b); // expected-warning {{expression with side effects has no effect in an unevaluated context}} \
+ // ref-warning {{expression with side effects has no effect in an unevaluated context}}
+
+ return b;
+ }
+ static_assert(a() == 0, "");
+#endif
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@
bool VisitPredefinedExpr(const PredefinedExpr *E);
bool VisitCXXThrowExpr(const CXXThrowExpr *E);
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
+ bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
protected:
bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1006,6 +1006,15 @@
return this->emitInvalidCast(CastKind::Reinterpret, E);
}
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
+ assert(E->getType()->isBooleanType());
+
+ if (DiscardResult)
+ return true;
+ return this->emitConstBool(E->getValue(), E);
+}
+
template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
if (E->containsErrors())
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155707.544283.patch
Type: text/x-patch
Size: 2628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230726/175751ab/attachment-0001.bin>
More information about the cfe-commits
mailing list