[clang] [clang][Sema] Fix crash on atomic builtins with incomplete type args (PR #96374)

Mital Ashok via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 22 02:52:48 PDT 2024


MitalAshok wrote:

Could you knock out a related bug at the same time:

```c++
template<typename>
struct X {
  char arr[1];
};

extern X<void>* p, *q;
//X<void> inst;

void f() {
  __atomic_exchange(p, p, q, __ATOMIC_RELAXED);
}
```

With the line commented out, currently this crashes, but in Clang 18 and with your patch, it fails as `X<void>` hasn't been instantiated yet and `isTriviallyCopyableType` is false for incomplete types:

```
test:10:3: error: address argument to atomic operation must be a pointer to a trivially-copyable type ('X<void> *' invalid)
   10 |   __atomic_exchange(p, p, q, __ATOMIC_RELAXED);
      |   ^                 ~
```

`->isIncompleteType()` is true for uninstantiated templates too, so just a `RequireCompleteType` should stop the crash and instantiate templates as needed.

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


More information about the cfe-commits mailing list