Author: Timm Bäder Date: 2024-02-05T18:21:30+01:00 New Revision: 5e8626c920a8cffff4e286cd8521528cc80c0a3e
URL: https://github.com/llvm/llvm-project/commit/5e8626c920a8cffff4e286cd8521528cc80c0a3e DIFF: https://github.com/llvm/llvm-project/commit/5e8626c920a8cffff4e286cd8521528cc80c0a3e.diff LOG: [clang][Interp] Handle ObjCBoolLiteralExprs Emit them just like the others, but these are integer typed. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/ByteCodeExprGen.h clang/test/AST/Interp/c.c clang/test/AST/Interp/literals.cpp clang/test/Sema/objc-bool-constant-conversion.m Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 24fa3d16896e8..10e32d9b7bcf3 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 4ed5d31e343a6..2c9cca5082b12 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -110,6 +110,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>, 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 53ce62fa1452e..9ab271a82aeef 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__ ptr diff _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 c88e7c1214807..0031e577580aa 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 00619ac8000b3..a47b8b6e867cd 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits