-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] allow restrict qualifier for array types with pointer types as element types #120896
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
Conversation
@llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) ChangesFixes #92847 > Types other than pointer types whose referenced type is an object type and (possibly multi-dimensional) array types with such pointer types as element type shall not be restrict-qualified. Full diff: https://github.com/llvm/llvm-project/pull/120896.diff 3 Files Affected:
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;
|
@AaronBallman ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these changes are correct, but adding a few more folks interested in C to verify because existing compilers definitely disagree: https://godbolt.org/z/1Yb44WP9o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is pretty close, mostly just nits from me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Please wait a bit before landing in case @efriedma-quic has any additional comments.
…s element types (llvm#120896) Fixes llvm#92847 --- > Types other than pointer types whose referenced type is an object type and (possibly multi-dimensional) array types with such pointer types as element type shall not be restrict-qualified.
…s element types (llvm#120896) Fixes llvm#92847 --- > Types other than pointer types whose referenced type is an object type and (possibly multi-dimensional) array types with such pointer types as element type shall not be restrict-qualified.
Fixes #92847