Skip to content

Commit

Permalink
Fix enum type literal assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Oct 7, 2024
1 parent 2878005 commit a4f2ccb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Differentiator/ConstantFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ namespace clad {
// SourceLocation noLoc;
Expr* Result = 0;
QT = QT.getCanonicalType();
if (QT->isPointerType()) {
if (QT->isEnumeralType()) {
llvm::APInt APVal(C.getIntWidth(QT), val,
QT->isSignedIntegerOrEnumerationType());
Result = clad::synthesizeLiteral(
dyn_cast<EnumType>(QT)->getDecl()->getIntegerType(), C, APVal);
Expr* cast = ImplicitCastExpr::Create(
C, QT, clang::CastKind::CK_IntegralCast, Result, nullptr, VK_PRValue,
FPOptionsOverride());
Result = cast;
} else if (QT->isPointerType()) {
Result = clad::synthesizeLiteral(QT, C);
} else if (QT->isBooleanType()) {
Result = clad::synthesizeLiteral(QT, C, (bool)val);
Expand Down

0 comments on commit a4f2ccb

Please sign in to comment.