[clang] [CIR] Allow implicit truncation in CharacterLiteral codegen (PR #197269)

via cfe-commits cfe-commits at lists.llvm.org
Thu May 14 12:56:20 PDT 2026


================
@@ -246,8 +246,14 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
 
   mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {
     mlir::Type ty = cgf.convertType(e->getType());
-    auto init = cir::IntAttr::get(ty, e->getValue());
-    return cir::ConstantOp::create(builder, cgf.getLoc(e->getExprLoc()), init);
+    // Character literals are always stored in an unsigned (even for signed
+    // char), so allow implicit truncation here.  Mirrors classic CodeGen
----------------
adams381 wrote:

Dropped the "Mirrors classic CodeGen" lines.  Kept the two preceding lines explaining why `isSigned=false, implicitTrunc=true` is needed.

https://github.com/llvm/llvm-project/pull/197269


More information about the cfe-commits mailing list