[clang] ef107af - [Sema] avoid merge error type

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Sat May 20 02:18:56 PDT 2023


Author: Congcong Cai
Date: 2023-05-20T11:18:42+02:00
New Revision: ef107afd48a920e74167874a55e2afb6decb52c7

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

LOG: [Sema] avoid merge error type

fixed: https://github.com/llvm/llvm-project/issues/62447
C don't support `DependentSizedArrayType`, use `ConstantArrayType` with nullptr as `SizeExpr`

Reviewed By: erichkeane, hokein

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

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaDecl.cpp
    clang/test/Sema/merge-decls.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3e2b08e9693f..26ffe7f822e3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,6 +392,8 @@ Bug Fixes in This Version
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 <https://github.com/llvm/llvm-project/issues/62296>`_)
+- Fix crash when redefine variant with invalid type as another invalid type.
+  (`#62447 <https://github.com/llvm/llvm-project/issues/62447>`_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
   (`#60082` <https://github.com/llvm/llvm-project/issues/60082>`_)
 - Fix the assertion hit when generating code for global variable initializer of

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index eff5f38960f7..adebfe85be45 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4396,7 +4396,7 @@ static void diagnoseVarDeclTypeMismatch(Sema &S, VarDecl *New, VarDecl* Old) {
 /// is attached.
 void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
                              bool MergeTypeWithOld) {
-  if (New->isInvalidDecl() || Old->isInvalidDecl())
+  if (New->isInvalidDecl() || Old->isInvalidDecl() || New->getType()->containsErrors() || Old->getType()->containsErrors())
     return;
 
   QualType MergedT;

diff  --git a/clang/test/Sema/merge-decls.c b/clang/test/Sema/merge-decls.c
index 5af8546106ba..53944d57095e 100644
--- a/clang/test/Sema/merge-decls.c
+++ b/clang/test/Sema/merge-decls.c
@@ -91,3 +91,7 @@ void test7_g() {
   int x[5];
   test7_f(&x); // expected-warning {{incompatible pointer types passing 'int (*)[5]' to parameter of type 'int (*)[10]}}
 }
+
+char d;
+char test8_gh62447[d.undef == 8]; // expected-error {{member reference base type 'char' is not a structure or union}}
+char test8_gh62447[d.undef == 4]; // expected-error {{member reference base type 'char' is not a structure or union}}


        


More information about the cfe-commits mailing list