Skip to content

Port "Enable use of GNU C extension - const statement expression as array size" #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions patches/clang/0005-Enable-use-of-GNU-C-extension.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 62267fec4a0d74472bc64695597f2477cc8c11df Mon Sep 17 00:00:00 2001
From: FirstName LastName <[email protected]>
Date: Wed, 5 Apr 2023 17:02:38 +0200
Subject: [PATCH] Enable use of GNU C extension - const statement expression as array size

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

---
clang/lib/Sema/SemaType.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index ab47e9f03..8cb26be44 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2330,7 +2330,8 @@ static ExprResult checkArraySize(Sema &S, Expr *&ArraySize,
} Diagnoser(VLADiag, VLAIsError);

ExprResult R =
- S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser);
+ S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,
+ S.LangOpts.OpenCL ? Sema::AllowFold : Sema::NoFold);
if (Diagnoser.IsVLA)
return ExprResult();
return R;
--
2.34.1