[clang] c4becd5 - [clang][Interp] Support __null
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 17 01:29:04 PDT 2023
Author: Timm Bäder
Date: 2023-08-17T10:28:37+02:00
New Revision: c4becd50ad437b44a303e9a14780ce600dd95146
URL: https://github.com/llvm/llvm-project/commit/c4becd50ad437b44a303e9a14780ce600dd95146
DIFF: https://github.com/llvm/llvm-project/commit/c4becd50ad437b44a303e9a14780ce600dd95146.diff
LOG: [clang][Interp] Support __null
Differential Revision: https://reviews.llvm.org/D155552
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 1d528f642e10be..77d2b1131005d1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1952,6 +1952,17 @@ bool ByteCodeExprGen<Emitter>::VisitCXXNullPtrLiteralExpr(
return this->emitNullPtr(E);
}
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitGNUNullExpr(const GNUNullExpr *E) {
+ if (DiscardResult)
+ return true;
+
+ assert(E->getType()->isIntegerType());
+
+ PrimType T = classifyPrim(E->getType());
+ return this->emitZero(T, E);
+}
+
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
if (DiscardResult)
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 6e134680d1fc5b..d28e03d571b1c6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
+ bool VisitGNUNullExpr(const GNUNullExpr *E);
bool VisitCXXThisExpr(const CXXThisExpr *E);
bool VisitUnaryOperator(const UnaryOperator *E);
bool VisitDeclRefExpr(const DeclRefExpr *E);
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 2a31d11e72cce2..e78ae42eb6d431 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -12,9 +12,13 @@ typedef __INTPTR_TYPE__ intptr_t;
static_assert(true, "");
static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
static_assert(nullptr == nullptr, "");
+static_assert(__null == __null, "");
static_assert(1 == 1, "");
static_assert(1 == 3, ""); // expected-error{{failed}} ref-error{{failed}}
+constexpr void* v = nullptr;
+static_assert(__null == v, "");
+
constexpr int number = 10;
static_assert(number == 10, "");
static_assert(number != 10, ""); // expected-error{{failed}} \
@@ -923,6 +927,7 @@ namespace DiscardExprs {
(short)5;
(bool)1;
+ __null;
return 0;
}
More information about the cfe-commits
mailing list