From: David Majnemer Date: Wed, 28 Jan 2015 05:48:06 +0000 (+0000) Subject: Sema: Ensure that __c11_atomic_fetch_add has a pointer to complete type X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18a541723125a193231dbb1b9fb2250c0577bf8d;p=clang Sema: Ensure that __c11_atomic_fetch_add has a pointer to complete type Pointer arithmetic is only makes sense if the pointee type is complete. This fixes PR22361. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227295 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index d1a27569da..cfa61119c8 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -1404,6 +1404,11 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult, << IsC11 << Ptr->getType() << Ptr->getSourceRange(); return ExprError(); } + if (IsC11 && ValType->isPointerType() && + RequireCompleteType(Ptr->getLocStart(), ValType->getPointeeType(), + diag::err_incomplete_type)) { + return ExprError(); + } } else if (IsN && !ValType->isIntegerType() && !ValType->isPointerType()) { // For __atomic_*_n operations, the value type must be a scalar integral or // pointer type which is 1, 2, 4, 8 or 16 bytes in length. diff --git a/test/Sema/atomic-ops.c b/test/Sema/atomic-ops.c index e21c3fd58e..71eaaa8b7a 100644 --- a/test/Sema/atomic-ops.c +++ b/test/Sema/atomic-ops.c @@ -49,7 +49,7 @@ char i8; short i16; int i32; int __attribute__((vector_size(8))) i64; -struct Incomplete *incomplete; +struct Incomplete *incomplete; // expected-note {{forward declaration of 'struct Incomplete'}} _Static_assert(__atomic_is_lock_free(1, &i8), ""); _Static_assert(__atomic_is_lock_free(1, &i64), ""); @@ -268,6 +268,10 @@ void memory_checks(_Atomic(int) *Ap, int *p, int val) { (void)__c11_atomic_fetch_add(Ap, 1, memory_order_acq_rel); (void)__c11_atomic_fetch_add(Ap, 1, memory_order_seq_cst); + (void)__c11_atomic_fetch_add( + (struct Incomplete * _Atomic *)0, // expected-error {{incomplete type 'struct Incomplete'}} + 1, memory_order_seq_cst); + (void)__c11_atomic_init(Ap, val); (void)__c11_atomic_init(Ap, val); (void)__c11_atomic_init(Ap, val);