[PATCH] D152561: [AST] Always set dependent-type for the CallExpr for error-recovery in C.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 11 22:23:33 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG752b97129789: [AST] Always set dependent-type for the CallExpr for error-recovery in C. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152561/new/

https://reviews.llvm.org/D152561

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.c


Index: clang/test/AST/ast-dump-recovery.c
===================================================================
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -93,7 +93,7 @@
   (*__builtin_classify_type)(1);
 
   extern void ext();
-  // CHECK:     CallExpr {{.*}} 'void' contains-errors
+  // CHECK:     CallExpr {{.*}} '<dependent type>' contains-errors
   // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext'
   // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
   ext(undef_var);
@@ -117,3 +117,12 @@
   // CHECK-NEXT: |   `-RecoveryExpr {{.*}} '<dependent type>' contains-errors
   if (__builtin_va_arg(undef, int) << 1);
 }
+
+void test6_GH50244() {
+  double array[16];
+  // CHECK:      UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' contains-errors sizeof
+  // CHECK-NEXT: `-CallExpr {{.*}} '<dependent type>' contains-errors
+  // CHECK-NEXT:   |-DeclRefExpr {{.*}} 'int ()'
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} '<dependent type>'
+  sizeof array / sizeof foo(undef);
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -7225,13 +7225,8 @@
             llvm::any_of(ArgExprs,
                          [](clang::Expr *E) { return E->containsErrors(); })) &&
            "should only occur in error-recovery path.");
-    QualType ReturnType =
-        llvm::isa_and_nonnull<FunctionDecl>(NDecl)
-            ? cast<FunctionDecl>(NDecl)->getCallResultType()
-            : Context.DependentTy;
-    return CallExpr::Create(Context, Fn, ArgExprs, ReturnType,
-                            Expr::getValueKindForType(ReturnType), RParenLoc,
-                            CurFPFeatureOverrides());
+    return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
+                            VK_PRValue, RParenLoc, CurFPFeatureOverrides());
   }
   return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
                                ExecConfig, IsExecConfig);
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,9 @@
   (`See patch <https://reviews.llvm.org/D152303>`_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 <https://github.com/llvm/llvm-project/issues/50534>`_).
+- CallExpr built for C error-recovery now is always type-dependent. Fixes a
+  crash when we encounter a unresolved TypoExpr during diagnostic emission.
+  (`#50244 <https://github.com/llvm/llvm-project/issues/50244>_`).
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152561.530383.patch
Type: text/x-patch
Size: 2723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230612/bb2e7281/attachment-0001.bin>


More information about the cfe-commits mailing list