From 1c9b121fb38d1a74be206a3ee0109f649b615f11 Mon Sep 17 00:00:00 2001 From: kchristin Date: Tue, 8 Oct 2024 13:13:43 +0300 Subject: [PATCH] Fix synth literal function for enums --- lib/Differentiator/ConstantFolder.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Differentiator/ConstantFolder.cpp b/lib/Differentiator/ConstantFolder.cpp index 6439c6eaa..8e7780ad7 100644 --- a/lib/Differentiator/ConstantFolder.cpp +++ b/lib/Differentiator/ConstantFolder.cpp @@ -7,6 +7,7 @@ //----------------------------------------------------------------------------// #include "ConstantFolder.h" +#include "clad/Differentiator/Compatibility.h" #include "clang/AST/ASTContext.h" @@ -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(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);