[clang] 3ce7d25 - [clang][RecoveryExpr] Don't perform alignment check if parameter type is dependent

Aleksandr Platonov via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 15 05:52:58 PDT 2022


Author: Aleksandr Platonov
Date: 2022-09-15T15:51:43+03:00
New Revision: 3ce7d256f2d7f64d57ccbfd7935d55eafc639314

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

LOG: [clang][RecoveryExpr] Don't perform alignment check if parameter type is dependent

This patch fixes a crash which appears because of getTypeAlignInChars() call with depentent type.

Reviewed By: hokein

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/SemaCXX/recovery-expr-type.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index bc9642d17d852..e419287014893 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5690,9 +5690,9 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
 
   // Find expected alignment, and the actual alignment of the passed object.
   // getTypeAlignInChars requires complete types
-  if (ArgTy.isNull() || ParamTy->isIncompleteType() ||
-      ArgTy->isIncompleteType() || ParamTy->isUndeducedType() ||
-      ArgTy->isUndeducedType())
+  if (ArgTy.isNull() || ParamTy->isDependentType() ||
+      ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
+      ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
     return;
 
   CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);

diff  --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp
index df6f4b69763c7..a5ba1ae2b8222 100644
--- a/clang/test/SemaCXX/recovery-expr-type.cpp
+++ b/clang/test/SemaCXX/recovery-expr-type.cpp
@@ -162,3 +162,12 @@ extern "C" void *memset(void *, int b, unsigned long) {
   b = __builtin_object_size(c, 0); // crash2
 }
 }
+
+namespace test15 {
+void f() {
+  struct {
+    void m(int (&)[undefined()]) {} // expected-error {{undeclared identifier}}
+  } S;
+  S.m(1); // no crash
+}
+}


        


More information about the cfe-commits mailing list