[clang] [Clang] allow restrict qualifier for array types with pointer types as element types (PR #120896)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 28 12:32:52 PST 2025
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/120896
>From 295df258043ef5a87ae603eedd308b863bad7b59 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Sun, 22 Dec 2024 15:14:30 +0200
Subject: [PATCH] [Clang] allow restrict qualifier for array types with pointer
types as element types
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Sema/SemaType.cpp | 4 +++-
clang/test/Sema/types.c | 10 +++++-----
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..52daea9b8eb2b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -332,6 +332,7 @@ C Language Changes
------------------
- Extend clang's ``<limits.h>`` to define ``LONG_LONG_*`` macros for Android's bionic.
+- Clang now allows ``restrict`` qualifier for array types with pointer elements (#GH92847).
C2y Feature Support
^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 83464c50b4b238..e84daeee679a57 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1595,12 +1595,14 @@ QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
QualType ProblemTy;
if (T->isAnyPointerType() || T->isReferenceType() ||
- T->isMemberPointerType()) {
+ T->isMemberPointerType() || T->isArrayType()) {
QualType EltTy;
if (T->isObjCObjectPointerType())
EltTy = T;
else if (const MemberPointerType *PTy = T->getAs<MemberPointerType>())
EltTy = PTy->getPointeeType();
+ else if (T->isArrayType())
+ EltTy = Context.getBaseElementType(T);
else
EltTy = T->getPointeeType();
diff --git a/clang/test/Sema/types.c b/clang/test/Sema/types.c
index e0a6ba4f0691b9..4c90634b7ce284 100644
--- a/clang/test/Sema/types.c
+++ b/clang/test/Sema/types.c
@@ -9,20 +9,20 @@ typedef int (*T)[2];
restrict T x;
typedef int *S[2];
-restrict S y; // expected-error {{restrict requires a pointer or reference ('S' (aka 'int *[2]') is invalid)}}
-
-
+restrict S y;
// int128_t is available.
int a(void) {
__int128_t s;
__uint128_t t;
-}
+} // expected-warning {{non-void function does not return a value}}
+
// but not a keyword
int b(void) {
int __int128_t;
int __uint128_t;
-}
+} // expected-warning {{non-void function does not return a value}}
+
// __int128 is a keyword
int c(void) {
__int128 i;
More information about the cfe-commits
mailing list