Skip to content

Commit 29df494

Browse files
tbaederrIanWood1
authored andcommitted
[clang][bytecode] Allow This pointers in CPCE mode (llvm#137761)
The outermost function doesn't have a This pointers, but inner calls can. This still doesn't match the diagnostic output of the current interpreter properly, but it's closer I think.
1 parent 2906551 commit 29df494

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ inline bool InitGlobalTempComp(InterpState &S, CodePtr OpPC,
15171517

15181518
template <PrimType Name, class T = typename PrimConv<Name>::T>
15191519
bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I) {
1520-
if (S.checkingPotentialConstantExpression())
1520+
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
15211521
return false;
15221522
const Pointer &This = S.Current->getThis();
15231523
if (!CheckThis(S, OpPC, This))
@@ -1535,7 +1535,7 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
15351535
bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F,
15361536
uint32_t FieldOffset) {
15371537
assert(F->isBitField());
1538-
if (S.checkingPotentialConstantExpression())
1538+
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
15391539
return false;
15401540
const Pointer &This = S.Current->getThis();
15411541
if (!CheckThis(S, OpPC, This))
@@ -1602,7 +1602,7 @@ bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off);
16021602
bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off);
16031603

16041604
inline bool GetPtrThisField(InterpState &S, CodePtr OpPC, uint32_t Off) {
1605-
if (S.checkingPotentialConstantExpression())
1605+
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
16061606
return false;
16071607
const Pointer &This = S.Current->getThis();
16081608
if (!CheckThis(S, OpPC, This))

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ static_assert(test_address_of_incomplete_array_type() == 1234, ""); // both-erro
4848
constexpr NonTrivial(const NonTrivial &) : n(1) {}
4949
int n;
5050
};
51-
constexpr bool test_nontrivial_memcpy() { // ref-error {{never produces a constant}}
51+
constexpr bool test_nontrivial_memcpy() { // both-error {{never produces a constant}}
5252
NonTrivial arr[3] = {};
5353
__builtin_memcpy(arr, arr + 1, sizeof(NonTrivial)); // both-note {{non-trivially-copyable}} \
54-
// ref-note {{non-trivially-copyable}}
54+
// both-note {{non-trivially-copyable}}
5555
return true;
5656
}
5757
static_assert(test_nontrivial_memcpy()); // both-error {{constant}} \

clang/test/AST/ByteCode/unions.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ namespace DefaultInit {
7676

7777
constexpr U1 u1; /// OK.
7878

79-
constexpr int foo() {
79+
constexpr int foo() { // expected-error {{never produces a constant expression}}
8080
U1 u;
81-
return u.a; // both-note {{read of member 'a' of union with active member 'b'}}
81+
return u.a; // both-note {{read of member 'a' of union with active member 'b'}} \
82+
// expected-note {{read of member 'a' of union with active member 'b'}}
8283
}
8384
static_assert(foo() == 42); // both-error {{not an integral constant expression}} \
8485
// both-note {{in call to}}

0 commit comments

Comments
 (0)