[llvm-branch-commits] [clang] 7513e66 - Address comments
Amy Huang via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 18 09:02:52 PST 2019
Author: Amy Huang
Date: 2019-12-18T09:01:31-08:00
New Revision: 7513e662d3c536c04b7bf44f68ce41cdc5eefc21
URL: https://github.com/llvm/llvm-project/commit/7513e662d3c536c04b7bf44f68ce41cdc5eefc21
DIFF: https://github.com/llvm/llvm-project/commit/7513e662d3c536c04b7bf44f68ce41cdc5eefc21.diff
LOG: Address comments
Added:
Modified:
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaOverload.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 4e1d4a44bd8c..92f81eb55ed7 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1155,6 +1155,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// attribute.
QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
+ /// Remove the existing address space on the type if it is a pointer size
+ /// address space and return the type with qualifiers intact.
+ QualType removePtrSizeAddrSpace(QualType T) const;
+
/// Return the uniqued reference to the type for a \c restrict
/// qualified type.
///
@@ -1209,6 +1213,15 @@ class ASTContext : public RefCountedBase<ASTContext> {
const FunctionProtoType::ExceptionSpecInfo &ESI,
bool AsWritten = false);
+ /// Get a function type and produce the equivalent function type where
+ /// pointer size address spaces in the return type and parameter tyeps are
+ /// replaced with the default address space.
+ QualType getFunctionTypeWithoutPtrSizes(QualType T);
+
+ /// Determine whether two function types are the same, ignoring pointer sizes
+ /// in the return type and parameter types.
+ bool hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U);
+
/// Return the uniqued reference to the type for a complex
/// number with the specified element type.
QualType getComplexType(QualType T) const;
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f7cd4945d022..942564756c93 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -479,9 +479,8 @@ class Qualifiers {
// for __constant can be used as __generic.
(A == LangAS::opencl_generic && B != LangAS::opencl_constant) ||
// Consider pointer size address spaces to be equivalent to default.
- ((isPtrSizeAddressSpace(A) && B == LangAS::Default) ||
- (isPtrSizeAddressSpace(B) && A == LangAS::Default) ||
- (isPtrSizeAddressSpace(A) && isPtrSizeAddressSpace(B)));
+ ((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
+ (isPtrSizeAddressSpace(B) || B == LangAS::Default));
}
/// Returns true if the address space in these qualifiers is equal to or
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 47d9e641b178..286807ec779f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2975,22 +2975,22 @@ def Win64 : IgnoredAttr {
def Ptr32 : TypeAttr {
let Spellings = [Keyword<"__ptr32">];
- let Documentation = [Undocumented];
+ let Documentation = [Ptr32Docs];
}
def Ptr64 : TypeAttr {
let Spellings = [Keyword<"__ptr64">];
- let Documentation = [Undocumented];
+ let Documentation = [Ptr64Docs];
}
def SPtr : TypeAttr {
let Spellings = [Keyword<"__sptr">];
- let Documentation = [Undocumented];
+ let Documentation = [SPtrDocs];
}
def UPtr : TypeAttr {
let Spellings = [Keyword<"__uptr">];
- let Documentation = [Undocumented];
+ let Documentation = [UPtrDocs];
}
def MSInheritance : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index c632e52b28d1..3fa6993a5fd0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3139,6 +3139,44 @@ Since it is not widely used and has been removed from OpenCL 2.1, it is ignored
by Clang.
}];
}
+
+def Ptr32Docs : Documentation {
+ let Category = DocCatType;
+ let Content = [{
+The ``__ptr32`` qualifier represents a native pointer on a 32-bit system. On a
+64-bit system, a pointer with ``__ptr32`` is extended to a 64-bit pointer. The
+``__sptr`` and ``__uptr`` qualifiers can be used to specify whether the pointer
+is sign extended or zero extended. This qualifier is enabled under
+``-fms-extensions``.
+ }];
+}
+
+def Ptr64Docs : Documentation {
+ let Category = DocCatType;
+ let Content = [{
+The ``__ptr64`` qualifier represents a native pointer on a 64-bit system. On a
+32-bit system, a ``__ptr64`` pointer is truncated to a 32-bit pointer. This
+qualifier is enabled under ``-fms-extensions``.
+ }];
+}
+
+def SPtrDocs : Documentation {
+ let Category = DocCatType;
+ let Content = [{
+The ``__sptr`` qualifier specifies that a 32-bit pointer should be sign
+extended when converted to a 64-bit pointer.
+ }];
+}
+
+def UPtrDocs : Documentation {
+ let Category = DocCatType;
+ let Content = [{
+The ``__uptr`` qualifier specifies that a 32-bit pointer should be zero
+extended when converted to a 64-bit pointer.
+ }];
+}
+
+
def NullabilityDocs : DocumentationCategory<"Nullability Attributes"> {
let Content = [{
Whether a particular pointer may be "null" is an important concern when working with pointers in the C family of languages. The various nullability attributes indicate whether a particular pointer can be null or not, which makes APIs more expressive and can help static analysis tools identify bugs involving null pointers. Clang supports several kinds of nullability attributes: the ``nonnull`` and ``returns_nonnull`` attributes indicate which function or method parameters and result types can never be null, while nullability type qualifiers indicate which pointer types can be null (``_Nullable``) or cannot be null (``_Nonnull``).
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 42b49be54df2..da279fa82158 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2835,6 +2835,16 @@ QualType ASTContext::getObjCGCQualType(QualType T,
return getExtQualType(TypeNode, Quals);
}
+QualType ASTContext::removePtrSizeAddrSpace(QualType T) const {
+ if (const PointerType *Ptr = T->getAs<PointerType>()) {
+ QualType Pointee = Ptr->getPointeeType();
+ if (isPtrSizeAddressSpace(Pointee.getAddressSpace())) {
+ return getPointerType(removeAddrSpaceQualType(Pointee));
+ }
+ }
+ return T;
+}
+
const FunctionType *ASTContext::adjustFunctionType(const FunctionType *T,
FunctionType::ExtInfo Info) {
if (T->getExtInfo() == Info)
@@ -2909,6 +2919,29 @@ bool ASTContext::hasSameFunctionTypeIgnoringExceptionSpec(QualType T,
getFunctionTypeWithExceptionSpec(U, EST_None)));
}
+QualType ASTContext::getFunctionTypeWithoutPtrSizes(QualType T) {
+ if (const auto *Proto = T->getAs<FunctionProtoType>()) {
+ QualType RetTy = removePtrSizeAddrSpace(Proto->getReturnType());
+ SmallVector<QualType, 16> Args(Proto->param_types());
+ for (unsigned i = 0, n = Args.size(); i != n; ++i)
+ Args[i] = removePtrSizeAddrSpace(Args[i]);
+ return getFunctionType(RetTy, Args, Proto->getExtProtoInfo());
+ }
+
+ if (const FunctionNoProtoType *Proto = T->getAs<FunctionNoProtoType>()) {
+ QualType RetTy = removePtrSizeAddrSpace(Proto->getReturnType());
+ return getFunctionNoProtoType(RetTy, Proto->getExtInfo());
+ }
+
+ return T;
+}
+
+bool ASTContext::hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U) {
+ return hasSameType(T, U) ||
+ hasSameType(getFunctionTypeWithoutPtrSizes(T),
+ getFunctionTypeWithoutPtrSizes(U));
+}
+
void ASTContext::adjustExceptionSpec(
FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI,
bool AsWritten) {
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 71822a7264c3..6b984955849a 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1872,14 +1872,9 @@ void MicrosoftCXXNameMangler::mangleAddressSpaceType(QualType T,
Extra.mangleSourceName("_ASCUshared");
break;
case LangAS::ptr32_sptr:
- Extra.mangleSourceName("_ASPtr32_sptr");
- break;
case LangAS::ptr32_uptr:
- Extra.mangleSourceName("_ASPtr32_uptr");
- break;
case LangAS::ptr64:
- Extra.mangleSourceName("_ASPtr64");
- break;
+ llvm_unreachable("don't mangle ptr address spaces with _AS");
}
}
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index a26daabd8f1a..0228d637d018 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1792,6 +1792,12 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
return "__constant__";
case LangAS::cuda_shared:
return "__shared__";
+ case LangAS::ptr32_sptr:
+ return "__sptr __ptr32";
+ case LangAS::ptr32_uptr:
+ return "__uptr __ptr32";
+ case LangAS::ptr64:
+ return "__ptr64";
default:
return std::to_string(toTargetAddressSpace(AS));
}
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b5c14a582c48..715e8757d43f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3153,64 +3153,6 @@ static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD,
FixSemaDC(VD->getDescribedVarTemplate());
}
-static QualType RemovePtrSizeAddrSpace(ASTContext &Ctx, QualType T) {
- if (const PointerType *Ptr = T->getAs<PointerType>()) {
- QualType Pointee = Ptr->getPointeeType();
- if (isPtrSizeAddressSpace(Pointee.getAddressSpace())) {
- return Ctx.getPointerType(Ctx.removeAddrSpaceQualType(Pointee));
- }
- }
- return T;
-}
-
-static bool HasSameFunctionTypeIgnoringPointerSizes(ASTContext &Ctx,
- QualType Old,
- QualType New) {
- if (Ctx.hasSameType(Old, New))
- return true;
-
- if (const FunctionProtoType *OldProto = Old->getAs<FunctionProtoType>()) {
- if (const FunctionProtoType *NewProto = New->getAs<FunctionProtoType>()) {
- SmallVector<QualType, 16> OArgs(OldProto->param_types());
- SmallVector<QualType, 16> NArgs(NewProto->param_types());
- if (OArgs.size() != NArgs.size())
- return false;
-
- QualType OldRTy = RemovePtrSizeAddrSpace(Ctx, OldProto->getReturnType());
- QualType NewRTy = RemovePtrSizeAddrSpace(Ctx, NewProto->getReturnType());
-
- for (unsigned i = 0, n = OArgs.size(); i != n; ++i) {
- QualType OArg = OArgs[i];
- QualType NArg = NArgs[i];
- if (Ctx.hasSameType(OArg, NArg))
- continue;
- OArgs[i] = RemovePtrSizeAddrSpace(Ctx, OArg);
- NArgs[i] = RemovePtrSizeAddrSpace(Ctx, NArg);
- }
-
- QualType OldType =
- Ctx.getFunctionType(OldRTy, OArgs, OldProto->getExtProtoInfo());
- QualType NewType =
- Ctx.getFunctionType(NewRTy, NArgs, NewProto->getExtProtoInfo());
-
- return Ctx.hasSameType(OldType, NewType);
- }
- }
-
- if (const FunctionNoProtoType *OldF = Old->getAs<FunctionNoProtoType>()) {
- if (const FunctionNoProtoType *NewF = New->getAs<FunctionNoProtoType>()) {
- QualType OldRetTy = RemovePtrSizeAddrSpace(Ctx, OldF->getReturnType());
- QualType NewRetTy = RemovePtrSizeAddrSpace(Ctx, NewF->getReturnType());
-
- return Ctx.hasSameType(
- Ctx.getFunctionNoProtoType(OldRetTy, OldF->getExtInfo()),
- Ctx.getFunctionNoProtoType(NewRetTy, NewF->getExtInfo()));
- }
- }
-
- return false;
-}
-
/// MergeFunctionDecl - We just parsed a function 'New' from
/// declarator D which has the same name and scope as a previous
/// declaration 'Old'. Figure out how to resolve this situation,
@@ -3716,7 +3658,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
// Check if the function types are compatible when pointer size address
// spaces are ignored.
- if (HasSameFunctionTypeIgnoringPointerSizes(Context, OldQType, NewQType))
+ if (Context.hasSameFunctionTypeIgnoringPtrSizes(OldQType, NewQType))
return false;
// GNU C permits a K&R definition to follow a prototype declaration
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0452da4535a2..22f1a087ca22 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2922,16 +2922,6 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
PDiag << ft_default;
}
-static QualType RemovePtrSizeAddrSpace(ASTContext &Ctx, QualType T) {
- if (const PointerType *Ptr = T->getAs<PointerType>()) {
- QualType Pointee = Ptr->getPointeeType();
- if (isPtrSizeAddressSpace(Pointee.getAddressSpace())) {
- return Ctx.getPointerType(Ctx.removeAddrSpaceQualType(Pointee));
- }
- }
- return T;
-}
-
/// FunctionParamTypesAreEqual - This routine checks two function proto types
/// for equality of their argument types. Caller has already checked that
/// they have same number of arguments. If the parameters are
diff erent,
@@ -2945,8 +2935,8 @@ bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
O && (O != E); ++O, ++N) {
// Ignore address spaces in pointee type. This is to disallow overloading
// on __ptr32/__ptr64 address spaces.
- QualType Old = RemovePtrSizeAddrSpace(Context, O->getUnqualifiedType());
- QualType New = RemovePtrSizeAddrSpace(Context, N->getUnqualifiedType());
+ QualType Old = Context.removePtrSizeAddrSpace(O->getUnqualifiedType());
+ QualType New = Context.removePtrSizeAddrSpace(N->getUnqualifiedType());
if (!Context.hasSameType(Old, New)) {
if (ArgPos)
More information about the llvm-branch-commits
mailing list