[clang] [clang][ObjC][CodeComplete] Fix crash on C-Style cast with parenthesi… (PR #180343)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 7 02:43:07 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (edisongz)
<details>
<summary>Changes</summary>
…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.
---
Full diff: https://github.com/llvm/llvm-project/pull/180343.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+1-1)
- (added) clang/test/CodeCompletion/objc-cast-parenthesized-expr.m (+12)
``````````diff
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
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/180343
More information about the cfe-commits
mailing list