[PATCH] D125349: [Sema] Fix crash for C11 atomic in gnu++ mode

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 9 08:24:18 PDT 2022


rjmccall added inline comments.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:8978
+          }
         }
       }
----------------
Can we do this in a way that's a little more general if we want to include other qualifiers in this combinatoric explosion in the future?  I think you just need to make a recursive helper function that takes a set of qualifiers to break down (treating the atomic flag as a "qualifier" for this purpose) and then calls a callback for all combinations of those qualifiers.  Like:

```
struct QualifiersAndAtomic {
  Qualifiers Quals;
  bool HasAtomic;
  QualifiersAndAtomic() : HasAtomic(false) {}
  QualifiersAndAtomic(Qualifiers quals, bool hasAtomic) : Quals(quals), HasAtomic(hasAtomic) {}

  QualifiersAndAtomic withVolatile() { return {Quals.withVolatile(), HasAtomic}; }
  QualifiersAndAtomic withAtomic() { return {Quals, true}; }
};

static void forAllQualifierCombinations(QualifiersAndAtomic available, QualifiersAndAtomic applied, llvm::function_ref<void(QualifiersAndAtomic)> callback) {
  // _Atomic
  if (available.HasAtomic) {
    available.HasAtomic = false;
    forAllQualifierCombinations(available, applied.withAtomic());
    forAllQualifierCombinations(available, applied);
    return;
  }

  // volatile
  if (available.Quals.hasVolatile()) {
    available.Quals.removeVolatile();
    assert(!applied.Quals.hasVolatile());
    forAllQualifierCombinations(available, applied.withVolatile());
    forAllQualifierCombinations(available, applied);
    return;
  }

  callback(applied);
}
```

The `QualifiersAndAtomic` structure is probably useful enough to go in `Type.h`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125349/new/

https://reviews.llvm.org/D125349



More information about the cfe-commits mailing list