[clang] [libclang] Fix evaluation of parenthesized string initializers (PR #243317)

Ivan Ugliansky via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 20:29:52 PST 2026


================
@@ -4748,7 +4748,7 @@ static const ExprEvalResult *evaluateExpr(Expr *expr, CXCursor C) {
 
   if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) {
     const auto *I = cast<ImplicitCastExpr>(expr);
-    auto *subExpr = I->getSubExprAsWritten();
+    auto *subExpr = I->getSubExprAsWritten()->IgnoreParens();
----------------
ugliansky wrote:

Hello! Thank you for your comment!

I think recursing on `getSubExprAsWritten()` would change the behavior for non-string initializers. For `int *p = 0;`, `clang_Cursor_Evaluate` currently returns `nullptr` for the declaration. With the recursive call, it would evaluate the `IntegerLiteral` under `NullToPointer` and return `CXEval_Int` with value `0`. That would   report an integer result for an initializer whose type is `int *` (which I believe is incorrect?).

Please tell me if I misunderstood something. 

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


More information about the cfe-commits mailing list