Skip to content

Commit ba27c39

Browse files
committed
[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.
1 parent 2d0137d commit ba27c39

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundAssignOperator(
14681468
std::optional<PrimType> LHSComputationT =
14691469
classify(E->getComputationLHSType());
14701470
std::optional<PrimType> LT = classify(LHS->getType());
1471-
std::optional<PrimType> RT = classify(E->getComputationResultType());
1471+
std::optional<PrimType> RT = classify(RHS->getType());
14721472
std::optional<PrimType> ResultT = classify(E->getType());
14731473

14741474
if (!LT || !RT || !ResultT || !LHSComputationT)

clang/test/AST/Interp/shifts.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,12 @@ namespace shifts {
188188
// ref-cxx17-error {{not an integral constant expression}} \
189189
// ref-cxx17-note {{in call to 'foo(2)'}}
190190
};
191+
192+
namespace LongInt {
193+
constexpr int f() {
194+
int a = 1;
195+
a <<= (long)0;
196+
return 1;
197+
}
198+
static_assert(f() == 1, "");
199+
};

0 commit comments

Comments
 (0)