Skip to content

Commit bf679f4

Browse files
authored
Enable use of GNU C extension - const statement expression as array size. (#411)
This patch partially reverts the commit: llvm/llvm-project@6781fee For backward compatibility, we still need to support the expressions like: ``` const int size = ({ false; }) ? 0 : 1; float array[size]; ``` https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
1 parent de262c9 commit bf679f4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 62267fec4a0d74472bc64695597f2477cc8c11df Mon Sep 17 00:00:00 2001
2+
From: FirstName LastName <[email protected]>
3+
Date: Wed, 5 Apr 2023 17:02:38 +0200
4+
Subject: [PATCH] Enable use of GNU C extension - const statement expression as array size
5+
6+
This patch partially reverts the commit:
7+
llvm/llvm-project@6781fee
8+
9+
For backward compatibility, we still need to support the
10+
expressions like:
11+
```
12+
const int size = ({ false; }) ? 0 : 1;
13+
float array[size];
14+
```
15+
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
16+
17+
---
18+
clang/lib/Sema/SemaType.cpp | 3 ++-
19+
1 file changed, 2 insertions(+), 1 deletion(-)
20+
21+
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
22+
index ab47e9f03..8cb26be44 100644
23+
--- a/clang/lib/Sema/SemaType.cpp
24+
+++ b/clang/lib/Sema/SemaType.cpp
25+
@@ -2330,7 +2330,8 @@ static ExprResult checkArraySize(Sema &S, Expr *&ArraySize,
26+
} Diagnoser(VLADiag, VLAIsError);
27+
28+
ExprResult R =
29+
- S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser);
30+
+ S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,
31+
+ S.LangOpts.OpenCL ? Sema::AllowFold : Sema::NoFold);
32+
if (Diagnoser.IsVLA)
33+
return ExprResult();
34+
return R;
35+
--
36+
2.34.1
37+

0 commit comments

Comments
 (0)