https://github.com/dougsonos updated 
https://github.com/llvm/llvm-project/pull/121525

>From 805b182e1a9ebe5e344943748dce6c86594495eb Mon Sep 17 00:00:00 2001
From: Doug Wyatt <dwy...@apple.com>
Date: Thu, 2 Jan 2025 14:28:48 -0800
Subject: [PATCH 1/4] [Clang] FunctionEffects: Correctly navigate through array
 types in FunctionEffectsRef::get().

---
 clang/include/clang/AST/Type.h                  | 17 +++++++++++++----
 .../test/Sema/attr-nonblocking-constraints.cpp  | 10 ++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..782c32f41852e2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8836,13 +8836,22 @@ void FixedPointValueToString(SmallVectorImpl<char> 
&Str, llvm::APSInt Val,
                              unsigned Scale);
 
 inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
+  const Type *TypePtr = QT.getTypePtr();
   while (true) {
-    QualType Pointee = QT->getPointeeType();
-    if (Pointee.isNull())
+    // Note that getPointeeType() seems to successfully navigate some 
constructs
+    // for which isAnyPointerType() returns false (e.g.
+    // pointer-to-member-function).
+    QualType Pointee = TypePtr->getPointeeType();
+    if (Pointee.isNull()) {
+      if (TypePtr->isArrayType()) {
+        TypePtr = TypePtr->getBaseElementTypeUnsafe();
+        continue;
+      }
       break;
-    QT = Pointee;
+    }
+    TypePtr = Pointee.getTypePtr();
   }
-  if (const auto *FPT = QT->getAs<FunctionProtoType>())
+  if (const auto *FPT = TypePtr->getAs<FunctionProtoType>())
     return FPT->getFunctionEffects();
   return {};
 }
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index bbc909f627f4c3..8304a38f9af500 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -246,6 +246,16 @@ void PTMFTester::convert() [[clang::nonblocking]]
        (this->*mConvertFunc)();
 }
 
+// Allow implicit conversion from array to pointer.
+void nb14(unsigned idx) [[clang::nonblocking]]
+{
+       using FP = void (*)() [[clang::nonblocking]];
+       auto nb = +[]() [[clang::nonblocking]] {};
+
+       FP array[4] = { nb, nb, nb, nb };
+       FP f = array[idx]; // This should not generate a warning.
+}
+
 // Block variables
 void nb17(void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
        blk();

>From 9dc1d8627d5f9ab4bfc6106161347d1d15063baf Mon Sep 17 00:00:00 2001
From: Doug Wyatt <dwy...@apple.com>
Date: Thu, 2 Jan 2025 16:55:11 -0800
Subject: [PATCH 2/4] Test an array hidden behind a typealias.

---
 clang/test/Sema/attr-nonblocking-constraints.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index 8304a38f9af500..f7b5abbfa34e91 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -250,10 +250,11 @@ void PTMFTester::convert() [[clang::nonblocking]]
 void nb14(unsigned idx) [[clang::nonblocking]]
 {
        using FP = void (*)() [[clang::nonblocking]];
+       using FPArray = FP[2];
        auto nb = +[]() [[clang::nonblocking]] {};
 
-       FP array[4] = { nb, nb, nb, nb };
-       FP f = array[idx]; // This should not generate a warning.
+       FPArray src{ nb, nullptr };
+       FP f = src[idx]; // This should not generate a warning.
 }
 
 // Block variables

>From f16a0128dded93c3e283f285f7ac1c50b4f2ce0e Mon Sep 17 00:00:00 2001
From: Doug Wyatt <d...@sonosphere.com>
Date: Thu, 16 Jan 2025 11:06:25 -0800
Subject: [PATCH 3/4] Update clang/include/clang/AST/Type.h

Co-authored-by: Sirraide <aeternalm...@gmail.com>
---
 clang/include/clang/AST/Type.h | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 782c32f41852e2..e1e960e6706b37 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8838,15 +8838,11 @@ void FixedPointValueToString(SmallVectorImpl<char> 
&Str, llvm::APSInt Val,
 inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
   const Type *TypePtr = QT.getTypePtr();
   while (true) {
-    // Note that getPointeeType() seems to successfully navigate some 
constructs
-    // for which isAnyPointerType() returns false (e.g.
-    // pointer-to-member-function).
-    QualType Pointee = TypePtr->getPointeeType();
-    if (Pointee.isNull()) {
-      if (TypePtr->isArrayType()) {
-        TypePtr = TypePtr->getBaseElementTypeUnsafe();
-        continue;
-      }
+    if (QualType Pointee = TypePtr->getPointeeType())
+      TypePtr = Pointee.getTypePtr();
+    else if (TypePtr->isArrayType())
+      TypePtr = TypePtr->getBaseElementTypeUnsafe();
+    else
       break;
     }
     TypePtr = Pointee.getTypePtr();

>From 15a960cedd5e822d08028778b31cd127c82182ae Mon Sep 17 00:00:00 2001
From: Doug Wyatt <dwy...@apple.com>
Date: Thu, 16 Jan 2025 14:55:12 -0800
Subject: [PATCH 4/4] Fix cleanup in Type.h. Add tests for multi-dimensional
 and variable-length arrays.

---
 clang/include/clang/AST/Type.h                   | 4 +---
 clang/test/Sema/attr-nonblocking-constraints.cpp | 9 +++++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index e1e960e6706b37..4eaf8705fd2572 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8838,14 +8838,12 @@ void FixedPointValueToString(SmallVectorImpl<char> 
&Str, llvm::APSInt Val,
 inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
   const Type *TypePtr = QT.getTypePtr();
   while (true) {
-    if (QualType Pointee = TypePtr->getPointeeType())
+    if (QualType Pointee = TypePtr->getPointeeType(); !Pointee.isNull())
       TypePtr = Pointee.getTypePtr();
     else if (TypePtr->isArrayType())
       TypePtr = TypePtr->getBaseElementTypeUnsafe();
     else
       break;
-    }
-    TypePtr = Pointee.getTypePtr();
   }
   if (const auto *FPT = TypePtr->getAs<FunctionProtoType>())
     return FPT->getFunctionEffects();
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index f7b5abbfa34e91..a302f631f5fd88 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -255,6 +255,15 @@ void nb14(unsigned idx) [[clang::nonblocking]]
 
        FPArray src{ nb, nullptr };
        FP f = src[idx]; // This should not generate a warning.
+
+       FP twoDim[2][2] = {};
+       FP g = twoDim[1][1];
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wvla-extension"
+       FP vla[idx];
+#pragma clang diagnostic pop
+       FP h = vla[0];
 }
 
 // Block variables

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to