diff options
author | Timm Bäder <tbaeder@redhat.com> | 2024-02-05 18:19:45 +0100 |
---|---|---|
committer | Timm Bäder <tbaeder@redhat.com> | 2024-02-05 18:21:30 +0100 |
commit | 5e8626c920a8cffff4e286cd8521528cc80c0a3e (patch) | |
tree | d33c18c5c4195f9d0b2b9de8691cd58f5f493e4f | |
parent | c5f68a711c62aa1748c03215d95ad9b8c7dff9dd (diff) | |
download | llvm-5e8626c920a8cffff4e286cd8521528cc80c0a3e.zip llvm-5e8626c920a8cffff4e286cd8521528cc80c0a3e.tar.gz llvm-5e8626c920a8cffff4e286cd8521528cc80c0a3e.tar.bz2 |
[clang][Interp] Handle ObjCBoolLiteralExprs
Emit them just like the others, but these are integer typed.
-rw-r--r-- | clang/lib/AST/Interp/ByteCodeExprGen.cpp | 9 | ||||
-rw-r--r-- | clang/lib/AST/Interp/ByteCodeExprGen.h | 1 | ||||
-rw-r--r-- | clang/test/AST/Interp/c.c | 4 | ||||
-rw-r--r-- | clang/test/AST/Interp/literals.cpp | 3 | ||||
-rw-r--r-- | clang/test/Sema/objc-bool-constant-conversion.m | 1 |
5 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 24fa3d1..10e32d9 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1985,6 +1985,15 @@ bool ByteCodeExprGen<Emitter>::VisitChooseExpr(const ChooseExpr *E) { return this->delegate(E->getChosenSubExpr()); } +template <class Emitter> +bool ByteCodeExprGen<Emitter>::VisitObjCBoolLiteralExpr( + const ObjCBoolLiteralExpr *E) { + if (DiscardResult) + return true; + + return this->emitConst(E->getValue(), E); +} + template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) { if (E->containsErrors()) return false; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 4ed5d31..2c9cca5 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -110,6 +110,7 @@ public: bool VisitSizeOfPackExpr(const SizeOfPackExpr *E); bool VisitGenericSelectionExpr(const GenericSelectionExpr *E); bool VisitChooseExpr(const ChooseExpr *E); + bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c index 53ce62f..9ab271a 100644 --- a/clang/test/AST/Interp/c.c +++ b/clang/test/AST/Interp/c.c @@ -7,6 +7,10 @@ typedef __INTPTR_TYPE__ intptr_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; _Static_assert(1, ""); + +_Static_assert(__objc_yes, ""); +_Static_assert(!__objc_no, ""); + _Static_assert(0 != 1, ""); _Static_assert(1.0 == 1.0, ""); // pedantic-ref-warning {{not an integer constant expression}} \ // pedantic-expected-warning {{not an integer constant expression}} diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index c88e7c1..0031e57 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -27,6 +27,9 @@ static_assert(number != 10, ""); // expected-error{{failed}} \ // expected-note{{evaluates to}} \ // ref-note{{evaluates to}} +static_assert(__objc_yes, ""); +static_assert(!__objc_no, ""); + constexpr bool b = number; static_assert(b, ""); constexpr int one = true; diff --git a/clang/test/Sema/objc-bool-constant-conversion.m b/clang/test/Sema/objc-bool-constant-conversion.m index 00619ac8..a47b8b6 100644 --- a/clang/test/Sema/objc-bool-constant-conversion.m +++ b/clang/test/Sema/objc-bool-constant-conversion.m @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only +// RUN: %clang_cc1 %s -verify -fsyntax-only -fexperimental-new-constant-interpreter typedef signed char BOOL; #define YES __objc_yes |