[clang] 27fe526 - [Clang] Fix crash on improper use of `__array_extent` (#94173)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 3 06:28:18 PDT 2024


Author: Oleksandr T
Date: 2024-06-03T15:28:14+02:00
New Revision: 27fe52622618a7cac3bf3444349a0c40c9e8328f

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

LOG: [Clang] Fix crash on improper use of `__array_extent` (#94173)

Check whether parsing of the argument failed before attempting
to build the expression. 

Fixes #80474.

Added: 
    clang/test/SemaCXX/incomplete-array-extent.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Parse/ParseExprCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c700d23257bf..32515fbac64f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -823,6 +823,7 @@ Bug Fixes to C++ Support
   
diff erering by their constraints when only one of these function was variadic.
 - Fix a crash when a variable is captured by a block nested inside a lambda. (Fixes #GH93625).
 - Fixed a type constraint substitution issue involving a generic lambda expression. (#GH93821)
+- Fix a crash caused by improper use of ``__array_extent``. (#GH80474)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 1558e3dcb8974..6f21a4f9bd826 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -4011,6 +4011,9 @@ ExprResult Parser::ParseArrayTypeTrait() {
     ExprResult DimExpr = ParseExpression();
     T.consumeClose();
 
+    if (DimExpr.isInvalid())
+      return ExprError();
+
     return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
                                        T.getCloseLocation());
   }

diff  --git a/clang/test/SemaCXX/incomplete-array-extent.cpp b/clang/test/SemaCXX/incomplete-array-extent.cpp
new file mode 100644
index 0000000000000..8134af6b9251b
--- /dev/null
+++ b/clang/test/SemaCXX/incomplete-array-extent.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -verify -std=c++14 %s
+
+auto f() {
+  return __array_extent(int, ); // expected-error {{expected expression}}
+}


        


More information about the cfe-commits mailing list