diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-04-02 05:18:44 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-04-02 05:18:44 +0000 |
| commit | a21ad8058a8189bfde375f68a6d04f37df0e8460 (patch) | |
| tree | bafa8ad703cd80d71e1d92fde67aeb0d19c0f81d /clang/lib/Sema | |
| parent | 2c71d5151353887c74af9ecbf4aa83b66114252f (diff) | |
| download | bcm5719-llvm-a21ad8058a8189bfde375f68a6d04f37df0e8460.tar.gz bcm5719-llvm-a21ad8058a8189bfde375f68a6d04f37df0e8460.zip | |
Fix several bugs in array -> pointer decomposition.
First, we got several CVR propagation cases wrong, which Eli pointed
out in PR2039.
Second, we didn't propagate address space qualifiers correctly, leading
to incorrect lowering of code in CodeGen/address-space.c.
Third, we didn't uniformly propagate the specifier in the array to the
pointer ("int[restrict 4]" -> "int *restrict").
This adds an ASTContext::getArrayDecayedType member that handles the
non-trivial logic for this seemingly simple operation.
llvm-svn: 49078
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 14 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 15 |
3 files changed, 11 insertions, 23 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 2d0251cc144..e247e2a52c5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1014,10 +1014,9 @@ Sema::ActOnParamDeclarator(struct DeclaratorChunk::ParamInfo &PI, // we need to consider storing both types (in ParmVarDecl)... // QualType parmDeclType = QualType::getFromOpaquePtr(PI.TypeInfo); - if (const ArrayType *AT = parmDeclType->getAsArrayType()) { + if (parmDeclType->isArrayType()) { // int x[restrict 4] -> int *restrict - parmDeclType = Context.getPointerType(AT->getElementType()); - parmDeclType = parmDeclType.getQualifiedType(AT->getIndexTypeQualifier()); + parmDeclType = Context.getArrayDecayedType(parmDeclType); } else if (parmDeclType->isFunctionType()) parmDeclType = Context.getPointerType(parmDeclType); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index f57ad2df9c7..1cd23522e8f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -932,18 +932,8 @@ void Sema::DefaultFunctionArrayConversion(Expr *&E) { } if (Ty->isFunctionType()) ImpCastExprToType(E, Context.getPointerType(Ty)); - else if (const ArrayType *ArrayTy = Ty->getAsArrayType()) { - // Make sure we don't lose qualifiers when dealing with typedefs. Example: - // typedef int arr[10]; - // void test2() { - // const arr b; - // b[4] = 1; - // } - QualType ELT = ArrayTy->getElementType(); - // FIXME: Handle ASQualType - ELT = ELT.getQualifiedType(Ty.getCVRQualifiers()|ELT.getCVRQualifiers()); - ImpCastExprToType(E, Context.getPointerType(ELT)); - } + else if (Ty->isArrayType()) + ImpCastExprToType(E, Context.getArrayDecayedType(Ty)); } /// UsualUnaryConversions - Performs various conversions that are common to most diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index ad9d138f91b..5874477de1a 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -317,18 +317,17 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { // type in ParmVarDecl (which makes the code generator unhappy). // // FIXME: We still apparently need the conversion in - // Sema::ParseParamDeclarator(). This doesn't make any sense, since + // Sema::ActOnParamDeclarator(). This doesn't make any sense, since // it should be driving off the type being created here. // // FIXME: If a source translation tool needs to see the original type, // then we need to consider storing both types somewhere... // - if (const ArrayType *AT = ArgTy->getAsArrayType()) { - // int x[restrict 4] -> int *restrict - ArgTy = Context.getPointerType(AT->getElementType()); - ArgTy = ArgTy.getQualifiedType(AT->getIndexTypeQualifier()); + if (ArgTy->isArrayType()) { + ArgTy = Context.getArrayDecayedType(ArgTy); } else if (ArgTy->isFunctionType()) ArgTy = Context.getPointerType(ArgTy); + // 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 FunctionTypeProto with an empty argument list. @@ -391,9 +390,9 @@ QualType Sema::ObjCGetTypeForMethodDefinition(DeclTy *D) { assert(!ArgTy.isNull() && "Couldn't parse type?"); // Perform the default function/array conversion (C99 6.7.5.3p[7,8]). // This matches the conversion that is done in - // Sema::ParseParamDeclarator(). - if (const ArrayType *AT = ArgTy->getAsArrayType()) - ArgTy = Context.getPointerType(AT->getElementType()); + // Sema::ActOnParamDeclarator(). + if (ArgTy->isArrayType()) + ArgTy = Context.getArrayDecayedType(ArgTy); else if (ArgTy->isFunctionType()) ArgTy = Context.getPointerType(ArgTy); ArgTys.push_back(ArgTy); |

