File tree 6 files changed +48
-8
lines changed
6 files changed +48
-8
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,14 @@ Major New Features
54
54
There is an analogous ``zero_call_used_regs `` attribute to allow for finer
55
55
control of this feature.
56
56
57
+ Bug Fixes
58
+ ------------------
59
+ - ``CXXNewExpr::getArraySize() `` previously returned a ``llvm::Optional ``
60
+ wrapping a ``nullptr `` when the ``CXXNewExpr `` did not have an array
61
+ size expression. This was fixed and ``::getArraySize() `` will now always
62
+ either return ``None `` or a ``llvm::Optional `` wrapping a valid ``Expr* ``.
63
+ This fixes `Issue #53742<https://github.com/llvm/llvm-project/issues/53742> `_.
64
+
57
65
Improvements to Clang's diagnostics
58
66
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59
67
@@ -83,7 +91,8 @@ Attribute Changes in Clang
83
91
- Added support for parameter pack expansion in `clang::annotate `.
84
92
85
93
- The ``overloadable `` attribute can now be written in all of the syntactic
86
- locations a declaration attribute may appear. Fixes PR53805.
94
+ locations a declaration attribute may appear.
95
+ This fixes `Issue #53805<https://github.com/llvm/llvm-project/issues/53805> `_.
87
96
88
97
Windows Support
89
98
---------------
Original file line number Diff line number Diff line change @@ -2261,15 +2261,32 @@ class CXXNewExpr final
2261
2261
2262
2262
bool isArray () const { return CXXNewExprBits.IsArray ; }
2263
2263
2264
+ // / This might return None even if isArray() returns true,
2265
+ // / since there might not be an array size expression.
2266
+ // / If the result is not-None, it will never wrap a nullptr.
2264
2267
Optional<Expr *> getArraySize () {
2265
2268
if (!isArray ())
2266
2269
return None;
2267
- return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset ()]);
2270
+
2271
+ if (auto *Result =
2272
+ cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset ()]))
2273
+ return Result;
2274
+
2275
+ return None;
2268
2276
}
2277
+
2278
+ // / This might return None even if isArray() returns true,
2279
+ // / since there might not be an array size expression.
2280
+ // / If the result is not-None, it will never wrap a nullptr.
2269
2281
Optional<const Expr *> getArraySize () const {
2270
2282
if (!isArray ())
2271
2283
return None;
2272
- return cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset ()]);
2284
+
2285
+ if (auto *Result =
2286
+ cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset ()]))
2287
+ return Result;
2288
+
2289
+ return None;
2273
2290
}
2274
2291
2275
2292
unsigned getNumPlacementArgs () const {
Original file line number Diff line number Diff line change @@ -9427,7 +9427,7 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
9427
9427
bool ValueInit = false;
9428
9428
9429
9429
QualType AllocType = E->getAllocatedType();
9430
- if (Optional<const Expr*> ArraySize = E->getArraySize()) {
9430
+ if (Optional<const Expr *> ArraySize = E->getArraySize()) {
9431
9431
const Expr *Stripped = *ArraySize;
9432
9432
for (; auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
9433
9433
Stripped = ICE->getSubExpr())
Original file line number Diff line number Diff line change @@ -2132,10 +2132,10 @@ void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
2132
2132
if (E->isParenTypeId ())
2133
2133
OS << " (" ;
2134
2134
std::string TypeS;
2135
- if (Optional<Expr *> Size = E->getArraySize ()) {
2135
+ if (E->isArray ()) {
2136
2136
llvm::raw_string_ostream s (TypeS);
2137
2137
s << ' [' ;
2138
- if (* Size )
2138
+ if (Optional<Expr *> Size = E-> getArraySize () )
2139
2139
(*Size )->printPretty (s, Helper, Policy);
2140
2140
s << ' ]' ;
2141
2141
}
Original file line number Diff line number Diff line change @@ -11912,9 +11912,9 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
11912
11912
11913
11913
// Transform the size of the array we're allocating (if any).
11914
11914
Optional<Expr *> ArraySize;
11915
- if (Optional<Expr *> OldArraySize = E->getArraySize ()) {
11915
+ if (E->isArray ()) {
11916
11916
ExprResult NewArraySize;
11917
- if (* OldArraySize) {
11917
+ if (Optional<Expr *> OldArraySize = E->getArraySize() ) {
11918
11918
NewArraySize = getDerived().TransformExpr(*OldArraySize);
11919
11919
if (NewArraySize.isInvalid())
11920
11920
return ExprError();
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -fsyntax-only %s -verify
2
+
3
+ struct Data {
4
+ char *a;
5
+ char *b;
6
+ bool *c;
7
+ };
8
+
9
+ int main () {
10
+ Data in;
11
+ in.a = new char [](); // expected-error {{cannot determine allocated array size from initializer}}
12
+ in.c = new bool [100 ]();
13
+ in.b = new char [100 ]();
14
+ }
You can’t perform that action at this time.
0 commit comments