https://github.com/edisongz created https://github.com/llvm/llvm-project/pull/180343
…zed operand in ObjC++ In ObjC++ mode, code-completion after a C-style cast like `(int*)(0x200)` crashed because the inner parenthesized expression was parsed as a `ParenListExpr` (null type) due to `AllowTypes` propagation. Add a null-type guard in CodeCompletePostfixExpression. >From 24e569b3856a2c227603dc01d3a67ae6b3f4490c Mon Sep 17 00:00:00 2001 From: Yijie Jiang <[email protected]> Date: Sat, 7 Feb 2026 18:34:46 +0800 Subject: [PATCH] [clang][ObjC][CodeComplete] Fix crash on C-Style cast with parenthesized operand in ObjC++ In ObjC++ mode, code-completion after a C-style cast like `(int*)(0x200)` crashed because the inner parenthesized expression was parsed as a `ParenListExpr` (null type) due to `AllowTypes` propagation. Add a null-type guard in CodeCompletePostfixExpression. --- clang/lib/Sema/SemaCodeComplete.cpp | 2 +- .../CodeCompletion/objc-cast-parenthesized-expr.m | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeCompletion/objc-cast-parenthesized-expr.m diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index aa93507ab5c30..0d8ed56a1ede3 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -5152,7 +5152,7 @@ void SemaCodeCompletion::CodeCompletePostfixExpression(Scope *S, ExprResult E, QualType PreferredType) { if (E.isInvalid()) CodeCompleteExpression(S, PreferredType); - else if (getLangOpts().ObjC) + else if (getLangOpts().ObjC && !E.get()->getType().isNull()) CodeCompleteObjCInstanceMessage(S, E.get(), {}, false); } diff --git a/clang/test/CodeCompletion/objc-cast-parenthesized-expr.m b/clang/test/CodeCompletion/objc-cast-parenthesized-expr.m new file mode 100644 index 0000000000000..171d62cf971f5 --- /dev/null +++ b/clang/test/CodeCompletion/objc-cast-parenthesized-expr.m @@ -0,0 +1,12 @@ +// Note: the run lines follow their respective tests, since line/column +// matter in this test. + +void func() { + int *foo = (int *)(0x200); + int *bar = (int *)((0x200)); +} + +// Make sure this doesn't crash +// RUN: %clang_cc1 -fsyntax-only -xobjective-c++-header -code-completion-at=%s:%(line-5):28 %s +// RUN: %clang_cc1 -fsyntax-only -xobjective-c++-header -code-completion-at=%s:%(line-5):30 %s + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
