r221404 - This patch fixes a crash after rebuilding call AST of

David Blaikie dblaikie at gmail.com
Tue Nov 11 16:03:27 PST 2014


On Wed, Nov 5, 2014 at 1:50 PM, Fariborz Jahanian <fjahanian at apple.com>
wrote:

> Author: fjahanian
> Date: Wed Nov  5 15:50:22 2014
> New Revision: 221404
>
> URL: http://llvm.org/viewvc/llvm-project?rev=221404&view=rev
> Log:
> This patch fixes a crash after rebuilding call AST of
> an __unknown_anytype(...). In this case, we rebuild the
> vararg function type specially to convert the call expression
> to  something that IRGen can handle. However, FunctionDecl
> as rebuilt in RebuildUnknownAnyExpr::resolveDecl is bogus and
> results in crash when accessing its params later on. This
> patch fixes the crash by rebuilding the FunctionDecl to match
> its new resolved type. rdar://15297105.
> John McCall, please review post-commit.
>
> Modified:
>     cfe/trunk/lib/Sema/SemaExpr.cpp
>     cfe/trunk/test/CodeGenCXX/unknown-anytype.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=221404&r1=221403&r2=221404&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Nov  5 15:50:22 2014
> @@ -13343,6 +13343,39 @@ ExprResult RebuildUnknownAnyExpr::resolv
>          << VD << E->getSourceRange();
>        return ExprError();
>      }
> +    if (const FunctionProtoType *FT = Type->getAs<FunctionProtoType>()) {
> +      // We must match the FunctionDecl's type to the hack introduced in
> +      // RebuildUnknownAnyExpr::VisitCallExpr to vararg functions of
> unknown
> +      // type. See the lengthy commentary in that routine.
> +      QualType FDT = FD->getType();
> +      const FunctionType *FnType = FDT->castAs<FunctionType>();
> +      const FunctionProtoType *Proto =
> dyn_cast_or_null<FunctionProtoType>(FnType);
> +      DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
> +      if (DRE && Proto && Proto->getParamTypes().empty() &&
> Proto->isVariadic()) {
> +        SourceLocation Loc = FD->getLocation();
> +        FunctionDecl *NewFD = FunctionDecl::Create(FD->getASTContext(),
> +                                      FD->getDeclContext(),
> +                                      Loc, Loc,
> FD->getNameInfo().getName(),
> +                                      DestType, FD->getTypeSourceInfo(),
> +                                      SC_None, false/*isInlineSpecified*/,
> +                                      FD->hasPrototype(),
> +                                      false/*isConstexprSpecified*/);
> +
> +        if (FD->getQualifier())
> +          NewFD->setQualifierInfo(FD->getQualifierLoc());
> +
> +        SmallVector<ParmVarDecl*, 16> Params;
> +        for (const auto &AI : FT->param_types()) {
> +          ParmVarDecl *Param =
> +            S.BuildParmVarDeclForTypedef(FD, Loc, AI);
> +          Param->setScopeInfo(0, Params.size());
> +          Params.push_back(Param);
> +        }
> +        NewFD->setParams(Params);
> +        DRE->setDecl(NewFD);
> +        VD = DRE->getDecl();
> +      }
> +    }
>
>      if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
>        if (MD->isInstance()) {
>
> Modified: cfe/trunk/test/CodeGenCXX/unknown-anytype.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/unknown-anytype.cpp?rev=221404&r1=221403&r2=221404&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/unknown-anytype.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/unknown-anytype.cpp Wed Nov  5 15:50:22 2014
> @@ -115,3 +115,9 @@ extern "C" __unknown_anytype test10_any(
>  void test10() {
>    (void) test10_any(), (void) test10_any();
>  }
> +
> +extern "C" __unknown_anytype malloc(...);
> +void test11() {
> +  void *s = (void*)malloc(12);
> +  void *d = (void*)malloc(435);
> +}
>

Is there some output that should be tested here - a test that is simply
"this does not crash" is kind of uninteresting & usually telling of some
missing test coverage (if the program was crashing before and doesn't crash
after, presumably there's some specific behavior that's desired beyond
"anything other than crashing").


>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141111/4ce53e41/attachment.html>


More information about the cfe-commits mailing list