-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][bytecode] Fix compound assign operators for IntAP(S) #169303
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
Member
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesWe didn't take Full diff: https://github.com/llvm/llvm-project/pull/169303.diff 3 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 958373ed94fe3..dd0b8e790d444 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2827,10 +2827,10 @@ bool Compiler<Emitter>::VisitCompoundAssignOperator(
return false;
if (!this->emitLoad(*LT, E))
return false;
- if (LT != LHSComputationT) {
- if (!this->emitCast(*LT, *LHSComputationT, E))
- return false;
- }
+ if (LT != LHSComputationT &&
+ !this->emitIntegralCast(*LT, *LHSComputationT, E->getComputationLHSType(),
+ E))
+ return false;
// Get the RHS value on the stack.
if (!this->emitGetLocal(*RT, TempOffset, E))
@@ -2883,10 +2883,9 @@ bool Compiler<Emitter>::VisitCompoundAssignOperator(
}
// And now cast from LHSComputationT to ResultT.
- if (ResultT != LHSComputationT) {
- if (!this->emitCast(*LHSComputationT, *ResultT, E))
- return false;
- }
+ if (ResultT != LHSComputationT &&
+ !this->emitIntegralCast(*LHSComputationT, *ResultT, E->getType(), E))
+ return false;
// And store the result in LHS.
if (DiscardResult) {
@@ -7243,6 +7242,19 @@ bool Compiler<Emitter>::emitPrimCast(PrimType FromT, PrimType ToT,
return false;
}
+template <class Emitter>
+bool Compiler<Emitter>::emitIntegralCast(PrimType FromT, PrimType ToT,
+ QualType ToQT, const Expr *E) {
+ assert(FromT != ToT);
+
+ if (ToT == PT_IntAP)
+ return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
+ if (ToT == PT_IntAPS)
+ return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);
+
+ return this->emitCast(FromT, ToT, E);
+}
+
/// Emits __real(SubExpr)
template <class Emitter>
bool Compiler<Emitter>::emitComplexReal(const Expr *SubExpr) {
diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h
index 6a9fe1e954530..54d39bbc25952 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -393,6 +393,8 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
}
bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
+ bool emitIntegralCast(PrimType FromT, PrimType ToT, QualType ToQT,
+ const Expr *E);
PrimType classifyComplexElementType(QualType T) const {
assert(T->isAnyComplexType());
diff --git a/clang/test/AST/ByteCode/intap.cpp b/clang/test/AST/ByteCode/intap.cpp
index 05ab319bf16df..efb60cb0abffe 100644
--- a/clang/test/AST/ByteCode/intap.cpp
+++ b/clang/test/AST/ByteCode/intap.cpp
@@ -305,6 +305,46 @@ namespace UnderlyingInt128 {
static_assert(foo() == 0, ""); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
}
+
+namespace CompoundAssignOperators {
+ constexpr unsigned __int128 foo() {
+ long b = 10;
+
+ b += (__int128)1;
+ b -= (__int128)1;
+ b *= (__int128)1;
+ b /= (__int128)1;
+
+ b += (unsigned __int128)1;
+ b -= (unsigned __int128)1;
+ b *= (unsigned __int128)1;
+ b /= (unsigned __int128)1;
+
+ __int128 i = 10;
+ i += (__int128)1;
+ i -= (__int128)1;
+ i *= (__int128)1;
+ i /= (__int128)1;
+ i += (unsigned __int128)1;
+ i -= (unsigned __int128)1;
+ i *= (unsigned __int128)1;
+ i /= (unsigned __int128)1;
+
+ unsigned __int128 i2 = 10;
+ i2 += (__int128)1;
+ i2 -= (__int128)1;
+ i2 *= (__int128)1;
+ i2 /= (__int128)1;
+ i2 += (unsigned __int128)1;
+ i2 -= (unsigned __int128)1;
+ i2 *= (unsigned __int128)1;
+ i2 /= (unsigned __int128)1;
+
+ return (int)b;
+ }
+ static_assert(foo() == 10);
+}
+
#endif
#endif
|
aadeshps-mcw
pushed a commit
to aadeshps-mcw/llvm-project
that referenced
this pull request
Nov 26, 2025
…9303) We didn't take `IntAP`/`IntAPS` into account when casting to and from the computation LHS type. This broke the `std/ranges/range.factories/range.iota.view/end.pass.cpp` test.
Priyanshu3820
pushed a commit
to Priyanshu3820/llvm-project
that referenced
this pull request
Nov 26, 2025
…9303) We didn't take `IntAP`/`IntAPS` into account when casting to and from the computation LHS type. This broke the `std/ranges/range.factories/range.iota.view/end.pass.cpp` test.
augusto2112
pushed a commit
to augusto2112/llvm-project
that referenced
this pull request
Dec 3, 2025
…9303) We didn't take `IntAP`/`IntAPS` into account when casting to and from the computation LHS type. This broke the `std/ranges/range.factories/range.iota.view/end.pass.cpp` test.
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.
We didn't take
IntAP/IntAPSinto account when casting to and from the computation LHS type. This broke thestd/ranges/range.factories/range.iota.view/end.pass.cpptest.