diff options
author | Timm Bäder <tbaeder@redhat.com> | 2024-02-18 07:04:12 +0100 |
---|---|---|
committer | Timm Bäder <tbaeder@redhat.com> | 2024-02-18 16:31:40 +0100 |
commit | ba27c3963d785a023cc8963ec3b6f508fe31527e (patch) | |
tree | 5ea5d9a6d7211a098468b4ada81872984d5119d3 | |
parent | 2d0137dd64017c34101f8a763fd8958c20acd6bb (diff) |
[clang][Interp] Classify correct type for compound shifts
RT must be the type of the RHS, otherwise this later fails when
we set the RHS value to the temporary variable.
-rw-r--r-- | clang/lib/AST/Interp/ByteCodeExprGen.cpp | 2 | ||||
-rw-r--r-- | clang/test/AST/Interp/shifts.cpp | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 72789d9d3481..6ad75d4e034a 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1468,7 +1468,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundAssignOperator( std::optional<PrimType> LHSComputationT = classify(E->getComputationLHSType()); std::optional<PrimType> LT = classify(LHS->getType()); - std::optional<PrimType> RT = classify(E->getComputationResultType()); + std::optional<PrimType> RT = classify(RHS->getType()); std::optional<PrimType> ResultT = classify(E->getType()); if (!LT || !RT || !ResultT || !LHSComputationT) diff --git a/clang/test/AST/Interp/shifts.cpp b/clang/test/AST/Interp/shifts.cpp index cf71e7145c27..e5201b3f8bbe 100644 --- a/clang/test/AST/Interp/shifts.cpp +++ b/clang/test/AST/Interp/shifts.cpp @@ -188,3 +188,12 @@ namespace shifts { // ref-cxx17-error {{not an integral constant expression}} \ // ref-cxx17-note {{in call to 'foo(2)'}} }; + +namespace LongInt { + constexpr int f() { + int a = 1; + a <<= (long)0; + return 1; + } + static_assert(f() == 1, ""); +}; |