Skip to content

[clang][bytecode] Allow This pointers in CPCE mode #137761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ inline bool InitGlobalTempComp(InterpState &S, CodePtr OpPC,

template <PrimType Name, class T = typename PrimConv<Name>::T>
bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I) {
if (S.checkingPotentialConstantExpression())
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
return false;
const Pointer &This = S.Current->getThis();
if (!CheckThis(S, OpPC, This))
Expand All @@ -1533,7 +1533,7 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F,
uint32_t FieldOffset) {
assert(F->isBitField());
if (S.checkingPotentialConstantExpression())
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
return false;
const Pointer &This = S.Current->getThis();
if (!CheckThis(S, OpPC, This))
Expand Down Expand Up @@ -1600,7 +1600,7 @@ bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off);
bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off);

inline bool GetPtrThisField(InterpState &S, CodePtr OpPC, uint32_t Off) {
if (S.checkingPotentialConstantExpression())
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
return false;
const Pointer &This = S.Current->getThis();
if (!CheckThis(S, OpPC, This))
Expand Down
4 changes: 2 additions & 2 deletions clang/test/AST/ByteCode/builtin-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ static_assert(test_address_of_incomplete_array_type() == 1234, ""); // both-erro
constexpr NonTrivial(const NonTrivial &) : n(1) {}
int n;
};
constexpr bool test_nontrivial_memcpy() { // ref-error {{never produces a constant}}
constexpr bool test_nontrivial_memcpy() { // both-error {{never produces a constant}}
NonTrivial arr[3] = {};
__builtin_memcpy(arr, arr + 1, sizeof(NonTrivial)); // both-note {{non-trivially-copyable}} \
// ref-note {{non-trivially-copyable}}
// both-note {{non-trivially-copyable}}
return true;
}
static_assert(test_nontrivial_memcpy()); // both-error {{constant}} \
Expand Down
5 changes: 3 additions & 2 deletions clang/test/AST/ByteCode/unions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ namespace DefaultInit {

constexpr U1 u1; /// OK.

constexpr int foo() {
constexpr int foo() { // expected-error {{never produces a constant expression}}
U1 u;
return u.a; // both-note {{read of member 'a' of union with active member 'b'}}
return u.a; // both-note {{read of member 'a' of union with active member 'b'}} \
// expected-note {{read of member 'a' of union with active member 'b'}}
}
static_assert(foo() == 42); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
Expand Down
Loading