Skip to content

Commit

Permalink
[clang][Interp] Classify correct type for compound shifts
Browse files Browse the repository at this point in the history
RT must be the type of the RHS, otherwise this later fails when
we set the RHS value to the temporary variable.
  • Loading branch information
tbaederr committed Feb 18, 2024
1 parent 2d0137d commit ba27c39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/Interp/shifts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
};

0 comments on commit ba27c39

Please sign in to comment.