[clang] [Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). (PR #121525)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 14 12:23:04 PST 2025


================
@@ -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;
----------------
Sirraide wrote:

```suggestion
    if (QualType Pointee = TypePtr->getPointeeType())
      TypePtr = Pointee.getTypePtr();
    else if (TypePtr->isArrayType())
      TypePtr = TypePtr->getBaseElementTypeUnsafe();
    else
      break;
```
Another option would be to write the entire loop body like this (github won’t let me make a suggestion across deleted lines...), but I don’t have strong opinions on this, so feel pick whichever one you prefer I’d say.

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


More information about the cfe-commits mailing list