Author: edisongz Date: 2026-02-15T15:30:03-08:00 New Revision: 8988fb751669a7e47deb4aa3f3f5fd03ccc95831
URL: https://github.com/llvm/llvm-project/commit/8988fb751669a7e47deb4aa3f3f5fd03ccc95831 DIFF: https://github.com/llvm/llvm-project/commit/8988fb751669a7e47deb4aa3f3f5fd03ccc95831.diff LOG: [clang][ObjC][CodeComplete] Fix crash on C-Style cast with parenthesized operand in ObjC++ (#180343) 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. Fixes https://github.com/llvm/llvm-project/issues/180125 Added: clang/test/CodeCompletion/objc-cast-parenthesized-expr.m Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaCodeComplete.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c648e8b0ec6fa..c9bedb87c6a79 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -391,6 +391,9 @@ libclang Code Completion --------------- +- Fixed a crash in code completion when using a C-Style cast with a parenthesized + operand in Objective-C++ mode. (#GH180125) + Static Analyzer --------------- diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index aa93507ab5c30..4a3559955ade3 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -8442,6 +8442,11 @@ void SemaCodeCompletion::CodeCompleteObjCInstanceMessage( // If necessary, apply function/array conversion to the receiver. // C99 6.7.5.3p[7,8]. if (RecExpr) { + // If the receiver expression has no type (e.g., a parenthesized C-style + // cast that hasn't been resolved), bail out to avoid dereferencing a null + // type. + if (RecExpr->getType().isNull()) + return; ExprResult Conv = SemaRef.DefaultFunctionArrayLvalueConversion(RecExpr); if (Conv.isInvalid()) // conversion failed. bail. return; 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
