Sema: Semantically check _Atomic-qualified pointers

This fixes PR22568.

llvm-svn: 228959
This commit is contained in:
David Majnemer 2015-02-12 21:07:34 +00:00
parent aa150ed780
commit cf7d164ec1
2 changed files with 16 additions and 7 deletions

View File

@ -7334,9 +7334,12 @@ static void diagnoseArithmeticOnFunctionPointer(Sema &S, SourceLocation Loc,
/// \returns True if pointer has incomplete type
static bool checkArithmeticIncompletePointerType(Sema &S, SourceLocation Loc,
Expr *Operand) {
assert(Operand->getType()->isAnyPointerType() &&
!Operand->getType()->isDependentType());
QualType PointeeTy = Operand->getType()->getPointeeType();
QualType ResType = Operand->getType();
if (const AtomicType *ResAtomicType = ResType->getAs<AtomicType>())
ResType = ResAtomicType->getValueType();
assert(ResType->isAnyPointerType() && !ResType->isDependentType());
QualType PointeeTy = ResType->getPointeeType();
return S.RequireCompleteType(Loc, PointeeTy,
diag::err_typecheck_arithmetic_incomplete_type,
PointeeTy, Operand->getSourceRange());
@ -7352,9 +7355,13 @@ static bool checkArithmeticIncompletePointerType(Sema &S, SourceLocation Loc,
/// \returns True when the operand is valid to use (even if as an extension).
static bool checkArithmeticOpPointerOperand(Sema &S, SourceLocation Loc,
Expr *Operand) {
if (!Operand->getType()->isAnyPointerType()) return true;
QualType ResType = Operand->getType();
if (const AtomicType *ResAtomicType = ResType->getAs<AtomicType>())
ResType = ResAtomicType->getValueType();
QualType PointeeTy = Operand->getType()->getPointeeType();
if (!ResType->isAnyPointerType()) return true;
QualType PointeeTy = ResType->getPointeeType();
if (PointeeTy->isVoidType()) {
diagnoseArithmeticOnVoidPointer(S, Loc, Operand);
return !S.getLangOpts().CPlusPlus;

View File

@ -1,6 +1,7 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic -std=c11
typedef struct S S; // expected-note 3 {{forward declaration of 'struct S'}}
typedef struct S S; // expected-note 4 {{forward declaration of 'struct S'}}
extern _Atomic(S*) e;
void a(S* b, void* c) {
void (*fp)(int) = 0;
b++; // expected-error {{arithmetic on a pointer to an incomplete type}}
@ -18,4 +19,5 @@ void a(S* b, void* c) {
d--; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
d -= 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
(void)(1 + d); // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
e++; // expected-error {{arithmetic on a pointer to an incomplete type}}
}