r183616 - Revert "[Sema] Make FunctionType's TSI use unadjusted argument types"
Reid Kleckner
reid at kleckner.net
Sat Jun 8 11:19:52 PDT 2013
Author: rnk
Date: Sat Jun 8 13:19:52 2013
New Revision: 183616
URL: http://llvm.org/viewvc/llvm-project?rev=183616&view=rev
Log:
Revert "[Sema] Make FunctionType's TSI use unadjusted argument types"
This reverts commit r183614.
It broke test/Sema/block-printf-attribute-1.c on non-Windows platforms,
and the fix is not trivial.
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Index/print-type.c
cfe/trunk/test/Index/print-type.cpp
cfe/trunk/test/Sema/function-redecl.c
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Jun 8 13:19:52 2013
@@ -1465,7 +1465,7 @@ public:
///
/// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None.
QualType getLifetimeQualifiedType(QualType type,
- Qualifiers::ObjCLifetime lifetime) const {
+ Qualifiers::ObjCLifetime lifetime) {
assert(type.getObjCLifetime() == Qualifiers::OCL_None);
assert(lifetime != Qualifiers::OCL_None);
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Jun 8 13:19:52 2013
@@ -4142,21 +4142,6 @@ const ArrayType *ASTContext::getAsArrayT
}
QualType ASTContext::getAdjustedParameterType(QualType T) const {
- // In ARC, infer a lifetime qualifier for appropriate parameter types.
- if (getLangOpts().ObjCAutoRefCount &&
- T.getObjCLifetime() == Qualifiers::OCL_None &&
- T->isObjCLifetimeType()) {
- // Special cases for arrays:
- // - if it's const, use __unsafe_unretained
- // - otherwise, it's an error
- Qualifiers::ObjCLifetime lifetime;
- if (T->isArrayType())
- lifetime = Qualifiers::OCL_ExplicitNone;
- else
- lifetime = T->getObjCARCImplicitLifetime();
- T = getLifetimeQualifiedType(T, lifetime);
- }
-
// C99 6.7.5.3p7:
// A declaration of a parameter as "array of type" shall be
// adjusted to "qualified pointer to type", where the type
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sat Jun 8 13:19:52 2013
@@ -1781,10 +1781,8 @@ bool TypeOfExprType::isSugared() const {
}
QualType TypeOfExprType::desugar() const {
- if (isSugared()) {
- Expr *E = getUnderlyingExpr();
- return E->getType();
- }
+ if (isSugared())
+ return getUnderlyingExpr()->getType();
return QualType(this, 0);
}
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Jun 8 13:19:52 2013
@@ -5897,40 +5897,23 @@ Sema::ActOnFunctionDeclarator(Scope *S,
<< DeclSpec::getSpecifierName(TSCS);
// Do not allow returning a objc interface by-value.
- bool NeedsAdjustment = false;
- const FunctionType *FT = R->castAs<FunctionType>();
- QualType ResultTy = FT->getResultType();
- if (ResultTy->isObjCObjectType()) {
+ if (R->getAs<FunctionType>()->getResultType()->isObjCObjectType()) {
Diag(D.getIdentifierLoc(),
- diag::err_object_cannot_be_passed_returned_by_value) << 0 << ResultTy
- << FixItHint::CreateInsertion(D.getIdentifierLoc(), "*");
- ResultTy = Context.getObjCObjectPointerType(ResultTy);
- NeedsAdjustment = true;
- }
-
- // Adjust parameter types from the type as written.
- SmallVector<QualType, 16> AdjustedParms;
- const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT);
- if (FPT) {
- for (FunctionProtoType::arg_type_iterator I = FPT->arg_type_begin(),
- E = FPT->arg_type_end(); I != E; ++I) {
- AdjustedParms.push_back(Context.getAdjustedParameterType(*I));
- if (AdjustedParms.back() != *I)
- NeedsAdjustment = true;
- }
- }
-
- // Skip the type recreation if it isn't needed, for performance and to avoid
- // prematurely desugaring things like typedefs and __typeofs.
- if (NeedsAdjustment) {
- if (FPT) {
+ diag::err_object_cannot_be_passed_returned_by_value) << 0
+ << R->getAs<FunctionType>()->getResultType()
+ << FixItHint::CreateInsertion(D.getIdentifierLoc(), "*");
+
+ QualType T = R->getAs<FunctionType>()->getResultType();
+ T = Context.getObjCObjectPointerType(T);
+ if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(R)) {
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
- R = Context.getFunctionType(ResultTy, AdjustedParms, EPI);
- } else {
- assert(isa<FunctionNoProtoType>(FT));
- FunctionType::ExtInfo EI = FT->getExtInfo();
- R = Context.getFunctionNoProtoType(ResultTy, EI);
+ R = Context.getFunctionType(T,
+ ArrayRef<QualType>(FPT->arg_type_begin(),
+ FPT->getNumArgs()),
+ EPI);
}
+ else if (isa<FunctionNoProtoType>(R))
+ R = Context.getFunctionNoProtoType(T);
}
bool isFriend = false;
@@ -8515,15 +8498,27 @@ ParmVarDecl *Sema::CheckParameter(DeclCo
SourceLocation NameLoc, IdentifierInfo *Name,
QualType T, TypeSourceInfo *TSInfo,
VarDecl::StorageClass StorageClass) {
- // Diagnose non-const parameter arrays of ARC types.
+ // In ARC, infer a lifetime qualifier for appropriate parameter types.
if (getLangOpts().ObjCAutoRefCount &&
T.getObjCLifetime() == Qualifiers::OCL_None &&
- T->isObjCLifetimeType() &&
- T->isArrayType() &&
- !T.isConstQualified()) {
- DelayedDiagnostics.add(
- sema::DelayedDiagnostic::makeForbiddenType(
+ T->isObjCLifetimeType()) {
+
+ Qualifiers::ObjCLifetime lifetime;
+
+ // Special cases for arrays:
+ // - if it's const, use __unsafe_unretained
+ // - otherwise, it's an error
+ if (T->isArrayType()) {
+ if (!T.isConstQualified()) {
+ DelayedDiagnostics.add(
+ sema::DelayedDiagnostic::makeForbiddenType(
NameLoc, diag::err_arc_array_param_no_ownership, T, false));
+ }
+ lifetime = Qualifiers::OCL_ExplicitNone;
+ } else {
+ lifetime = T->getObjCARCImplicitLifetime();
+ }
+ T = Context.getLifetimeQualifiedType(T, lifetime);
}
ParmVarDecl *New = ParmVarDecl::Create(Context, DC, StartLoc, NameLoc, Name,
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Jun 8 13:19:52 2013
@@ -1674,7 +1674,7 @@ QualType Sema::BuildFunctionType(QualTyp
bool Invalid = false;
for (unsigned Idx = 0, Cnt = ParamTypes.size(); Idx < Cnt; ++Idx) {
// FIXME: Loc is too inprecise here, should use proper locations for args.
- QualType ParamType = ParamTypes[Idx];
+ QualType ParamType = Context.getAdjustedParameterType(ParamTypes[Idx]);
if (ParamType->isVoidType()) {
Diag(Loc, diag::err_param_with_void_type);
Invalid = true;
@@ -2798,11 +2798,13 @@ static TypeSourceInfo *GetFullTypeForDec
for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
ParmVarDecl *Param = cast<ParmVarDecl>(FTI.ArgInfo[i].Param);
- // Get the type as written. It will be adjusted later in
- // ActOnFunctionDeclarator().
- QualType ArgTy = Param->getTypeSourceInfo()->getType();
+ QualType ArgTy = Param->getType();
assert(!ArgTy.isNull() && "Couldn't parse type?");
+ // Adjust the parameter type.
+ assert((ArgTy == Context.getAdjustedParameterType(ArgTy)) &&
+ "Unadjusted type?");
+
// Look for 'void'. void is allowed only as a single argument to a
// function with no other parameters (C99 6.7.5.3p10). We record
// int(void) as a FunctionProtoType with an empty argument list.
Modified: cfe/trunk/test/Index/print-type.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.c?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-type.c (original)
+++ cfe/trunk/test/Index/print-type.c Sat Jun 8 13:19:52 2013
@@ -11,7 +11,7 @@ int __attribute__((vector_size(16))) x;
typedef int __attribute__((vector_size(16))) int4_t;
// RUN: c-index-test -test-print-type %s | FileCheck %s
-// CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int [5], void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0]
+// CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0]
// CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1]
// CHECK: ParmDecl=x:3:22 (Definition) [type=char *] [typekind=Pointer] [isPOD=1]
// CHECK: ParmDecl=z:3:33 (Definition) [type=FooType] [typekind=Typedef] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
Modified: cfe/trunk/test/Index/print-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.cpp?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-type.cpp (original)
+++ cfe/trunk/test/Index/print-type.cpp Sat Jun 8 13:19:52 2013
@@ -62,5 +62,5 @@ T tbar(int[5]);
// CHECK: TypedefDecl=ArrayType:20:15 (Definition) [type=ArrayType] [typekind=Typedef] [canonicaltype=int [5]] [canonicaltypekind=ConstantArray] [isPOD=1]
// CHECK: FunctionTemplate=tbar:27:3 [type=T (int)] [typekind=FunctionProto] [canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] [resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
// CHECK: TemplateTypeParameter=T:26:20 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0]
-// CHECK: FunctionTemplate=tbar:30:3 [type=T (int [5])] [typekind=FunctionProto] [canonicaltype=type-parameter-0-0 (int *)] [canonicaltypekind=FunctionProto] [resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
+// CHECK: FunctionTemplate=tbar:30:3 [type=T (int *)] [typekind=FunctionProto] [canonicaltype=type-parameter-0-0 (int *)] [canonicaltypekind=FunctionProto] [resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
// CHECK: ParmDecl=:30:11 (Definition) [type=int [5]] [typekind=ConstantArray] [isPOD=1]
Modified: cfe/trunk/test/Sema/function-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function-redecl.c?rev=183616&r1=183615&r2=183616&view=diff
==============================================================================
--- cfe/trunk/test/Sema/function-redecl.c (original)
+++ cfe/trunk/test/Sema/function-redecl.c Sat Jun 8 13:19:52 2013
@@ -115,11 +115,6 @@ void i0 (unsigned short a0);
extern __typeof (i0) i1;
extern __typeof (i1) i1;
-// Try __typeof with a parameter that needs adjustment.
-void j0 (int a0[1], ...);
-extern __typeof (j0) j1;
-extern __typeof (j1) j1;
-
typedef int a();
typedef int a2(int*);
a x;
More information about the cfe-commits
mailing list