r228959 - Sema: Semantically check _Atomic-qualified pointers
David Majnemer
david.majnemer at gmail.com
Thu Feb 12 13:07:34 PST 2015
Author: majnemer
Date: Thu Feb 12 15:07:34 2015
New Revision: 228959
URL: http://llvm.org/viewvc/llvm-project?rev=228959&view=rev
Log:
Sema: Semantically check _Atomic-qualified pointers
This fixes PR22568.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/pointer-addition.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=228959&r1=228958&r2=228959&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 12 15:07:34 2015
@@ -7334,9 +7334,12 @@ static void diagnoseArithmeticOnFunction
/// \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 checkArithmeticIncompletePoi
/// \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();
+
+ if (!ResType->isAnyPointerType()) return true;
- QualType PointeeTy = Operand->getType()->getPointeeType();
+ QualType PointeeTy = ResType->getPointeeType();
if (PointeeTy->isVoidType()) {
diagnoseArithmeticOnVoidPointer(S, Loc, Operand);
return !S.getLangOpts().CPlusPlus;
Modified: cfe/trunk/test/Sema/pointer-addition.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pointer-addition.c?rev=228959&r1=228958&r2=228959&view=diff
==============================================================================
--- cfe/trunk/test/Sema/pointer-addition.c (original)
+++ cfe/trunk/test/Sema/pointer-addition.c Thu Feb 12 15:07:34 2015
@@ -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}}
}
More information about the cfe-commits
mailing list