diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 24fa3d16896e..10e32d9b7bcf 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1985,6 +1985,15 @@ bool ByteCodeExprGen::VisitChooseExpr(const ChooseExpr *E) { return this->delegate(E->getChosenSubExpr()); } +template +bool ByteCodeExprGen::VisitObjCBoolLiteralExpr( + const ObjCBoolLiteralExpr *E) { + if (DiscardResult) + return true; + + return this->emitConst(E->getValue(), E); +} + template bool ByteCodeExprGen::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 4ed5d31e343a..2c9cca5082b1 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 53ce62fa1452..9ab271a82aee 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 c88e7c121480..0031e577580a 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 00619ac8000b..a47b8b6e867c 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