Author: clamb Date: Wed Aug 1 13:19:14 2007 New Revision: 40679 URL: http://llvm.org/viewvc/llvm-project?rev=40679&view=rev Log: Bring across restrict handling from llvm-gcc-4.0. This should fix PR1582 on both llvm-gcc projects.
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp llvm-gcc-4.2/trunk/gcc/llvm-internal.h llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=40679&r1=40678&r2=40679&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Wed Aug 1 13:19:14 2007 @@ -1004,7 +1004,7 @@ if (FnEntry == 0) { unsigned CC; const FunctionType *Ty = - TheTypeConverter->ConvertFunctionType(TREE_TYPE(decl), NULL, CC); + TheTypeConverter->ConvertFunctionType(TREE_TYPE(decl), decl, NULL, CC); FnEntry = new Function(Ty, Function::ExternalLinkage, Name, TheModule); FnEntry->setCallingConv(CC); Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=40679&r1=40678&r2=40679&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Aug 1 13:19:14 2007 @@ -530,6 +530,7 @@ } else { // Otherwise, just get the type from the function itself. FTy = TheTypeConverter->ConvertFunctionType(TREE_TYPE(FnDecl), + FnDecl, static_chain, CallingConv); } @@ -2597,6 +2598,7 @@ unsigned CallingConv; const Type *Ty = TheTypeConverter->ConvertFunctionType(function_type, + fndecl, static_chain, CallingConv); Callee = CastToType(Instruction::BitCast, Callee, PointerType::get(Ty)); Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=40679&r1=40678&r2=40679&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Wed Aug 1 13:19:14 2007 @@ -147,6 +147,7 @@ /// tree to an LLVM type. This does the same thing that ConvertType does, but /// it also returns the function's LLVM calling convention. const FunctionType *ConvertFunctionType(tree_node *type, + tree_node *decl, tree_node *static_chain, unsigned &CallingConv); Modified: llvm-gcc-4.2/trunk/gcc/llvm-types.cpp URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-types.cpp?rev=40679&r1=40678&r2=40679&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Wed Aug 1 13:19:14 2007 @@ -804,9 +804,13 @@ case FUNCTION_TYPE: { if (const Type *Ty = GET_TYPE_LLVM(type)) return Ty; - + + // No declaration to pass through, passing NULL. unsigned CallingConv; - return TypeDB.setType(type, ConvertFunctionType(type, NULL, CallingConv)); + return TypeDB.setType(type, ConvertFunctionType(type, + NULL, + NULL, + CallingConv)); } case ARRAY_TYPE: { if (const Type *Ty = GET_TYPE_LLVM(type)) @@ -948,6 +952,7 @@ } const FunctionType *TypeConverter::ConvertFunctionType(tree type, + tree decl, tree static_chain, unsigned &CallingConv) { const Type *RetTy = 0; @@ -998,6 +1003,8 @@ LLVM_TARGET_INIT_REGPARM(local_regparam, type); #endif // LLVM_TARGET_ENABLE_REGPARM + // Check if we have a corresponding decl to inspect. + tree DeclArgs = (decl) ? DECL_ARGUMENTS(decl) : NULL; // Loop over all of the arguments, adding them as we go. tree Args = TYPE_ARG_TYPES(type); for (; Args && TREE_VALUE(Args) != void_type_node; Args = TREE_CHAIN(Args)){ @@ -1032,10 +1039,15 @@ Attributes |= ParamAttr::SExt; } - // Compute noalias attributes. - if (TREE_CODE(ArgTy) == POINTER_TYPE || TREE_CODE(ArgTy) == REFERENCE_TYPE) - if (TYPE_RESTRICT(ArgTy)) + // Compute noalias attributes. If we have a decl for the function + // inspect it for restrict qualifiers, otherwise try the argument + // types. + tree RestrictArgTy = (DeclArgs) ? TREE_TYPE(DeclArgs) : ArgTy; + if (TREE_CODE(RestrictArgTy) == POINTER_TYPE || + TREE_CODE(RestrictArgTy) == REFERENCE_TYPE) { + if (TYPE_RESTRICT(RestrictArgTy)) Attributes |= ParamAttr::NoAlias; + } #ifdef LLVM_TARGET_ENABLE_REGPARM // Allow the target to mark this as inreg. @@ -1047,6 +1059,9 @@ if (Attributes != ParamAttr::None) Attrs.push_back(ParamAttrsWithIndex::get(ArgTypes.size(), Attributes)); + + if (DeclArgs) + DeclArgs = TREE_CHAIN(DeclArgs); } // If the argument list ends with a void type node, it isn't vararg. _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits