summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Horvath <xazax@google.com>2020-01-02 11:57:42 -0800
committerGabor Horvath <xazax@google.com>2020-01-07 08:32:40 -0800
commit247a6032549efb03c14b79c035a47c660b75263e (patch)
treea6fd0257a39ce2a470fb2e56a17617fa40d06fb0
parenta3832f33d9323a5080321ca52321efd9c5741b63 (diff)
downloadbcm5719-llvm-247a6032549efb03c14b79c035a47c660b75263e.tar.gz
bcm5719-llvm-247a6032549efb03c14b79c035a47c660b75263e.zip
[LifetimeAnalysis] Do not forbid void deref type in gsl::Pointer/gsl::Owner annotations
It turns out it is useful to be able to define the deref type as void. In case we have a type erased owner, we want to express that the pointee can be basically any type. It should not be unnatural to have a void deref type as we already familiar with "pointers to void". Differential Revision: https://reviews.llvm.org/D72097
-rw-r--r--clang/include/clang/Basic/AttrDocs.td4
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp8
-rw-r--r--clang/test/SemaCXX/attr-gsl-owner-pointer.cpp6
4 files changed, 10 insertions, 10 deletions
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 9b4afa8f128..515476df3fd 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4590,7 +4590,7 @@ object of type ``T``:
The argument ``T`` is optional and is ignored.
This attribute may be used by analysis tools and has no effect on code
-generation.
+generation. A ``void`` argument means that the class can own any type.
See Pointer_ for an example.
}];
@@ -4616,7 +4616,7 @@ like pointers to an object of type ``T``:
The argument ``T`` is optional and is ignored.
This attribute may be used by analysis tools and has no effect on code
-generation.
+generation. A ``void`` argument means that the pointer can point to any type.
Example:
When constructing an instance of a class annotated like this (a Pointer) from
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a8f49fef9f1..dd9649bcb5c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2631,7 +2631,7 @@ def err_nsobject_attribute : Error<
def err_attributes_are_not_compatible : Error<
"%0 and %1 attributes are not compatible">;
def err_attribute_invalid_argument : Error<
- "%select{'void'|a reference type|an array type|a non-vector or "
+ "%select{a reference type|an array type|a non-vector or "
"non-vectorizable scalar type}0 is an invalid argument to attribute %1">;
def err_attribute_wrong_number_arguments : Error<
"%0 attribute %plural{0:takes no arguments|1:takes one argument|"
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 50951ad6022..02aebbea4a8 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2913,7 +2913,7 @@ static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {
if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() &&
(ParmType->isBooleanType() ||
!ParmType->isIntegralType(S.getASTContext()))) {
- S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 3 << AL;
+ S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
return;
}
@@ -4454,12 +4454,10 @@ static void handleLifetimeCategoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
ParmType = S.GetTypeFromParser(AL.getTypeArg(), &DerefTypeLoc);
unsigned SelectIdx = ~0U;
- if (ParmType->isVoidType())
+ if (ParmType->isReferenceType())
SelectIdx = 0;
- else if (ParmType->isReferenceType())
- SelectIdx = 1;
else if (ParmType->isArrayType())
- SelectIdx = 2;
+ SelectIdx = 1;
if (SelectIdx != ~0U) {
S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument)
diff --git a/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp b/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
index 5b438822ba2..6c1bfe405e8 100644
--- a/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
+++ b/clang/test/SemaCXX/attr-gsl-owner-pointer.cpp
@@ -31,9 +31,11 @@ class [[gsl::Owner(int)]] [[gsl::Pointer(int)]] BothOwnerPointer{};
// CHECK: OwnerAttr {{.*}} int
class [[gsl::Owner(void)]] OwnerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Owner'}}
+// CHECK: CXXRecordDecl {{.*}} OwnerVoidDerefType
+// CHECK: OwnerAttr {{.*}} void
class [[gsl::Pointer(void)]] PointerVoidDerefType{};
-// expected-error@-1 {{'void' is an invalid argument to attribute 'Pointer'}}
+// CHECK: CXXRecordDecl {{.*}} PointerVoidDerefType
+// CHECK: PointerAttr {{.*}} void
class [[gsl::Pointer(int)]] AddConflictLater{};
// CHECK: CXXRecordDecl {{.*}} AddConflictLater
OpenPOWER on IntegriCloud