[clang-tools-extra] r178167 - cpp11-migrate segfaults transforming map<string, int>::iterator

Vane, Edwin edwin.vane at intel.com
Thu Mar 28 09:55:24 PDT 2013


What do you mean by "look through"? This patch is getting the sub-expression out of a ExprWithCleanups.

-----Original Message-----
From: cfe-commits-bounces at cs.uiuc.edu [mailto:cfe-commits-bounces at cs.uiuc.edu] On Behalf Of Jordan Rose
Sent: Thursday, March 28, 2013 12:51 PM
To: Bernal, Ariel J
Cc: cfe-commits at cs.uiuc.edu
Subject: Re: [clang-tools-extra] r178167 - cpp11-migrate segfaults transforming map<string, int>::iterator

Isn't the correct solution to look through ExprWithCleanups, since that won't change the type of the returned value anyway?


On Mar 27, 2013, at 11:49 , Ariel J. Bernal <ariel.j.bernal at intel.com> wrote:

> Author: ajbernal
> Date: Wed Mar 27 13:49:31 2013
> New Revision: 178167
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=178167&view=rev
> Log:
> cpp11-migrate segfaults transforming map<string,int>::iterator
> 
> cpp11-migrate segfaults when -use-auto tries to resolve initializing 
> expression resulting in an expression with cleanups.
> 
> - Skip expressions with cleanups from the initializer
> - Added test case
> 
> Fixes PR15550
> 
> 
> Modified:
>    clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp
>    clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
>    clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp
> 
> Modified: 
> clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migr
> ate/UseAuto/UseAutoActions.cpp?rev=178167&r1=178166&r2=178167&view=dif
> f 
> ======================================================================
> ========
> --- clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp 
> (original)
> +++ clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.cpp 
> +++ Wed Mar 27 13:49:31 2013
> @@ -28,7 +28,14 @@ void UseAutoFixer::run(const MatchFinder
>   if (!SM.isFromMainFile(D->getLocStart()))
>     return;
> 
> -  const CXXConstructExpr *Construct = 
> cast<CXXConstructExpr>(D->getInit());
> +  const Expr *ExprInit = D->getInit();
> +
> +  // Skip expressions with cleanups from the initializer expression.
> +  if (const ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(ExprInit))
> +    ExprInit = E->getSubExpr();
> +
> +  const CXXConstructExpr *Construct = 
> + cast<CXXConstructExpr>(ExprInit);
> +
>   assert(Construct->getNumArgs() == 1u &&
>          "Expected constructor with single argument");
> 
> 
> Modified: 
> clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_con
> tainer.h
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11
> -migrate/UseAuto/Inputs/test_std_container.h?rev=178167&r1=178166&r2=1
> 78167&view=diff 
> ======================================================================
> ========
> --- 
> clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std_con
> tainer.h (original)
> +++ clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/Inputs/test_std
> +++ _container.h Wed Mar 27 13:49:31 2013
> @@ -107,6 +107,9 @@ public:
> 
>   const_reverse_iterator rbegin() const { return const_reverse_iterator(); }
>   const_reverse_iterator rend() const { return 
> const_reverse_iterator(); }
> +
> +  template <typename K>
> +  iterator find(const K &Key) { return iterator(); }
> };
> 
> #if USE_INLINE_NAMESPACE
> 
> Modified: 
> clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11
> -migrate/UseAuto/iterator.cpp?rev=178167&r1=178166&r2=178167&view=diff
> ======================================================================
> ========
> --- clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp 
> (original)
> +++ clang-tools-extra/trunk/test/cpp11-migrate/UseAuto/iterator.cpp 
> +++ Wed Mar 27 13:49:31 2013
> @@ -148,5 +148,13 @@ int main(int argc, char **argv) {
>     // CHECK: auto && I2 = Vec.begin();
>   }
> 
> +  // Passing a string as an argument to introduce a temporary object  
> + // that will create an expression with cleanups. Bugzilla: 15550  {
> +    std::unordered_map<int> MapFind;
> +    std::unordered_map<int>::iterator I = MapFind.find("foo");
> +    // CHECK: auto I = MapFind.find("foo");  }
> +
>   return 0;
> }
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

_______________________________________________
cfe-commits mailing list
cfe-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list