llvm-project/clang/test/SemaCXX/atomic-ops.cpp
Takuya Shimizu 6b737c4446
[clang][Sema] Fix crash on atomic builtins with incomplete type args (#96374)
This patch fixes the crash when pointers to incomplete type are passed
to atomic builtins such as `__atomic_load`.
`ASTContext::getTypeInfoInChars` assumes that the argument type is a
complete type, so I added a check to eliminate cases where incomplete
types gets passed to this function

Relevant PR: https://github.com/llvm/llvm-project/pull/91057
Fixes https://github.com/llvm/llvm-project/issues/96289
2024-06-30 14:09:10 +09:00

25 lines
719 B
C++

// RUN: %clang_cc1 %s -verify -fsyntax-only -triple=i686-linux-gnu -std=c++11
// We crashed when we couldn't properly convert the first arg of __atomic_* to
// an lvalue.
void PR28623() {
void helper(int); // expected-note{{target}}
void helper(char); // expected-note{{target}}
__atomic_store_n(helper, 0, 0); // expected-error{{reference to overloaded function could not be resolved}}
}
template<typename>
struct X {
char arr[1];
};
extern X<void>* p, *q;
// They should be accepted.
void f() {
__atomic_exchange(p, p, q, __ATOMIC_RELAXED);
__atomic_load(p, p, __ATOMIC_RELAXED);
__atomic_store(p, p, __ATOMIC_RELAXED);
__atomic_compare_exchange(p, p, q, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
}