-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThe 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. Full diff: https://github.com/llvm/llvm-project/pull/137761.diff 3 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 6cd995279029a..e7ab4f1771891 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -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))
@@ -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))
@@ -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))
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index a4c8ec4856ecc..814e6d3fad8ee 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -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}} \
diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp
index 3911a2b2f7dde..36f4b72335af3 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -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}}
|
gizmondo
pushed a commit
to gizmondo/llvm-project
that referenced
this pull request
Apr 29, 2025
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.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
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.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
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.
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
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.
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
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.
Ankur-0429
pushed a commit
to Ankur-0429/llvm-project
that referenced
this pull request
May 9, 2025
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:bytecode
Issues for the clang bytecode constexpr interpreter
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.