[clang] d4e9352 - [clang][AST] Propagate the value-dependent bit for VAArgExpr.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri May 19 14:43:55 PDT 2023


Author: Haojian Wu
Date: 2023-05-19T23:43:46+02:00
New Revision: d4e935240f0223cdf2270dde587960d3d3868c6f

URL: https://github.com/llvm/llvm-project/commit/d4e935240f0223cdf2270dde587960d3d3868c6f
DIFF: https://github.com/llvm/llvm-project/commit/d4e935240f0223cdf2270dde587960d3d3868c6f.diff

LOG: [clang][AST] Propagate the value-dependent bit for VAArgExpr.

Fixes https://github.com/llvm/llvm-project/issues/62711

We never set the value-dependent bit for the VAArgExpr before this
patch, this was fine becase the dependent-type TypoExpr was always
resolved before checking the operands (see https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExpr.cpp#L21173-L21180)

Now we have enabled the dependence by default for C, the typo expr is
not early resolved before checking rather than delayed (share the same
codepath with C++).

The fix is to propagate the value-dependent bit for VAArgExpr where it contains
a TypoExpr, so that the AST node can be handled properly.

Differential Revision: https://reviews.llvm.org/D150955

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/AST/ComputeDependence.cpp
    clang/test/AST/ast-dump-recovery.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3035e23f0b45c..3e2b08e9693fe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -413,6 +413,9 @@ Bug Fixes in This Version
 - Fix a crash when an enum constant has a dependent-type recovery expression for
   C.
   (`#62446 <https://github.com/llvm/llvm-project/issues/62446>`_).
+- Propagate the value-dependent bit for VAArgExpr. Fixes a crash where a
+  __builtin_va_arg call has invalid arguments.
+  (`#62711 <https://github.com/llvm/llvm-project/issues/62711>`_).
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index 5a301c10aca6d..4b6bc2d994ca8 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -227,7 +227,7 @@ ExprDependence clang::computeDependence(VAArgExpr *E) {
   auto D = toExprDependenceAsWritten(
                E->getWrittenTypeInfo()->getType()->getDependence()) |
            (E->getSubExpr()->getDependence() & ~ExprDependence::Type);
-  return D & ~ExprDependence::Value;
+  return D;
 }
 
 ExprDependence clang::computeDependence(NoInitExpr *E) {

diff  --git a/clang/test/AST/ast-dump-recovery.c b/clang/test/AST/ast-dump-recovery.c
index 75441c1c9de0a..33f0f2ad3c996 100644
--- a/clang/test/AST/ast-dump-recovery.c
+++ b/clang/test/AST/ast-dump-recovery.c
@@ -109,3 +109,11 @@ void test4() {
     b,
   };
 }
+
+// Verify no crash
+void test5_GH62711() {
+  // CHECK:      VAArgExpr {{.*}} 'int' contains-errors
+  // CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '<dependent type>' contains-errors
+  // CHECK-NEXT: |   `-RecoveryExpr {{.*}} '<dependent type>' contains-errors
+  if (__builtin_va_arg(undef, int) << 1);
+}


        


More information about the cfe-commits mailing list