[clang] 554febd - [Clang] Fix some assertions not looking through type sugar (#92299)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 17 07:42:05 PDT 2024


Author: Mital Ashok
Date: 2024-07-17T16:42:02+02:00
New Revision: 554febd3aad8d7cea7b8f8f6124d691031fb618c

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

LOG: [Clang] Fix some assertions not looking through type sugar (#92299)

Fixes #92284

Co-authored-by: cor3ntin <corentinjabot at gmail.com>

Added: 
    

Modified: 
    clang/lib/AST/ExprConstant.cpp
    clang/lib/Sema/SemaInit.cpp
    clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0aeac9d03eed3..5af712dd7257b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11478,7 +11478,7 @@ bool ArrayExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E,
 
 bool ArrayExprEvaluator::VisitCXXParenListInitExpr(
     const CXXParenListInitExpr *E) {
-  assert(dyn_cast<ConstantArrayType>(E->getType()) &&
+  assert(E->getType()->isConstantArrayType() &&
          "Expression result is not a constant array type");
 
   return VisitCXXParenListOrInitListExpr(E, E->getInitExprs(),

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d97a5c8988840..17435afab03f4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5621,7 +5621,7 @@ static void TryOrBuildParenListInitialization(
           << SE->getSourceRange();
       return;
     } else {
-      assert(isa<IncompleteArrayType>(Entity.getType()));
+      assert(Entity.getType()->isIncompleteArrayType());
       ArrayLength = Args.size();
     }
     EntityIndexToProcess = ArrayLength;

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp
index efc1e955d4ed8..cc2a9d88dd4a6 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -314,8 +314,8 @@ namespace GH63903 {
                     // expected-error {{constexpr variable 's' must be initialized by a constant expression}}
 }
 
-
 namespace gh62863 {
+
 int (&&arr)[] = static_cast<int[]>(42);
 // beforecxx20-warning at -1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
 int (&&arr1)[1] = static_cast<int[]>(42);
@@ -333,4 +333,23 @@ int (&&arr6)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' co
 // beforecxx20-warning at -1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
 int (&&arr7)[3] = (int[3])(42);
 // beforecxx20-warning at -1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
+
+}
+
+namespace GH92284 {
+
+using T = int[1]; T x(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'T' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}}
+using Ta = int[2]; Ta a(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'Ta' (aka 'int[2]') from a parenthesized list of values is a C++20 extension}}
+using Tb = int[2]; Tb b(42,43);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'Tb' (aka 'int[2]') from a parenthesized list of values is a C++20 extension}}
+using Tc = int[]; Tc c(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+using Td = int[]; Td d(42,43);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
+template<typename T, int Sz> using ThroughAlias = T[Sz];
+ThroughAlias<int, 1> e(42);
+// beforecxx20-warning at -1 {{aggregate initialization of type 'ThroughAlias<int, 1>' (aka 'int[1]') from a parenthesized list of values is a C++20 extension}} 
+
 }


        


More information about the cfe-commits mailing list