[clang] [clang][AST] Stop creating `ConstantExpr` nodes without a result (PR #229761)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 8 05:50:17 PDT 2026


================
@@ -1848,18 +1848,13 @@ void CodeGenFunction::EmitCaseStmt(const CaseStmt &S,
     Builder.getInt(S.getLHS()->EvaluateKnownConstInt(getContext()));
 
   // Emit debuginfo for the case value if it is an enum value.
-  const ConstantExpr *CE;
-  if (auto ICE = dyn_cast<ImplicitCastExpr>(S.getLHS()))
-    CE = dyn_cast<ConstantExpr>(ICE->getSubExpr());
-  else
-    CE = dyn_cast<ConstantExpr>(S.getLHS());
-  if (CE) {
-    if (auto DE = dyn_cast<DeclRefExpr>(CE->getSubExpr()))
-      if (CGDebugInfo *Dbg = getDebugInfo())
-        if (CGM.getCodeGenOpts().hasReducedDebugInfo())
-          Dbg->EmitGlobalVariable(DE->getDecl(),
-              APValue(llvm::APSInt(CaseVal->getValue())));
-  }
+  const auto *CE = dyn_cast<ConstantExpr>(S.getLHS()->IgnoreImpCasts());
----------------
AaronBallman wrote:

This isn't quite equivalent, but I'm not certain whether that's a bug fix or not.

We used to only check if the LHS is an `ImplicitCastExpr` and if so, get the subexpression.

Now we're checking if the LHS is an `ImplicitCastExpr` or a `FullExpr` and if so, get the subexpression.

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


More information about the cfe-commits mailing list