Skip to content

Commit

Permalink
Fix synth literal function for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Oct 8, 2024
1 parent 8ed2707 commit 1c9b121
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Differentiator/ConstantFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//----------------------------------------------------------------------------//

#include "ConstantFolder.h"
#include "clad/Differentiator/Compatibility.h"

#include "clang/AST/ASTContext.h"

Expand Down Expand Up @@ -141,7 +142,17 @@ 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,
CLAD_COMPAT_ExprValueKind_R_or_PR_Value
CLAD_COMPAT_CLANG12_CastExpr_DefaultFPO);
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 1c9b121

Please sign in to comment.