Skip to content

Commit 5e8626c

Browse files
committed
[clang][Interp] Handle ObjCBoolLiteralExprs
Emit them just like the others, but these are integer typed.
1 parent c5f68a7 commit 5e8626c

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,15 @@ bool ByteCodeExprGen<Emitter>::VisitChooseExpr(const ChooseExpr *E) {
19851985
return this->delegate(E->getChosenSubExpr());
19861986
}
19871987

1988+
template <class Emitter>
1989+
bool ByteCodeExprGen<Emitter>::VisitObjCBoolLiteralExpr(
1990+
const ObjCBoolLiteralExpr *E) {
1991+
if (DiscardResult)
1992+
return true;
1993+
1994+
return this->emitConst(E->getValue(), E);
1995+
}
1996+
19881997
template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
19891998
if (E->containsErrors())
19901999
return false;

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
110110
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
111111
bool VisitGenericSelectionExpr(const GenericSelectionExpr *E);
112112
bool VisitChooseExpr(const ChooseExpr *E);
113+
bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E);
113114

114115
protected:
115116
bool visitExpr(const Expr *E) override;

clang/test/AST/Interp/c.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ typedef __INTPTR_TYPE__ intptr_t;
77
typedef __PTRDIFF_TYPE__ ptrdiff_t;
88

99
_Static_assert(1, "");
10+
11+
_Static_assert(__objc_yes, "");
12+
_Static_assert(!__objc_no, "");
13+
1014
_Static_assert(0 != 1, "");
1115
_Static_assert(1.0 == 1.0, ""); // pedantic-ref-warning {{not an integer constant expression}} \
1216
// pedantic-expected-warning {{not an integer constant expression}}

clang/test/AST/Interp/literals.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ static_assert(number != 10, ""); // expected-error{{failed}} \
2727
// expected-note{{evaluates to}} \
2828
// ref-note{{evaluates to}}
2929

30+
static_assert(__objc_yes, "");
31+
static_assert(!__objc_no, "");
32+
3033
constexpr bool b = number;
3134
static_assert(b, "");
3235
constexpr int one = true;

clang/test/Sema/objc-bool-constant-conversion.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 %s -verify -fsyntax-only
2+
// RUN: %clang_cc1 %s -verify -fsyntax-only -fexperimental-new-constant-interpreter
23

34
typedef signed char BOOL;
45
#define YES __objc_yes

0 commit comments

Comments
 (0)