r251335 - MismatchingNewDeleteDetector uses incorrect field, and finds no initializer

Ismail Pazarbasi via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 12:45:28 PDT 2015


Hi,

this patch addresses a crash-on-valid on 3.7. Could you please merge
this to 3.7 branch?

Ismail

On Mon, Oct 26, 2015 at 8:20 PM, Ismail Pazarbasi via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: ismailp
> Date: Mon Oct 26 14:20:24 2015
> New Revision: 251335
>
> URL: http://llvm.org/viewvc/llvm-project?rev=251335&view=rev
> Log:
> MismatchingNewDeleteDetector uses incorrect field, and finds no initializer
>
> Summary:
> In `MismatchingNewDeleteDetector::analyzeInClassInitializer`, if
> `Field`'s initializer expression is null, lookup the field in
> implicit instantiation, and use found field's the initializer.
>
> Reviewers: rsmith, rtrieu
>
> Subscribers: cfe-commits
>
> Differential Revision: http://reviews.llvm.org/D9898
>
> Modified:
>     cfe/trunk/lib/Sema/SemaExprCXX.cpp
>     cfe/trunk/test/SemaCXX/delete.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=251335&r1=251334&r2=251335&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Oct 26 14:20:24 2015
> @@ -2500,8 +2500,10 @@ bool MismatchingNewDeleteDetector::hasMa
>  MismatchingNewDeleteDetector::MismatchResult
>  MismatchingNewDeleteDetector::analyzeInClassInitializer() {
>    assert(Field != nullptr && "This should be called only for members");
> -  if (const CXXNewExpr *NE =
> -          getNewExprFromInitListOrExpr(Field->getInClassInitializer())) {
> +  const Expr *InitExpr = Field->getInClassInitializer();
> +  if (!InitExpr)
> +    return EndOfTU ? NoMismatch : AnalyzeLater;
> +  if (const CXXNewExpr *NE = getNewExprFromInitListOrExpr(InitExpr)) {
>      if (NE->isArray() != IsArrayForm) {
>        NewExprs.push_back(NE);
>        return MemberInitMismatches;
>
> Modified: cfe/trunk/test/SemaCXX/delete.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/delete.cpp?rev=251335&r1=251334&r2=251335&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/delete.cpp (original)
> +++ cfe/trunk/test/SemaCXX/delete.cpp Mon Oct 26 14:20:24 2015
> @@ -120,6 +120,22 @@ void f() {
>    DELETE(d);          // expected-warning {{'delete' applied to a pointer that was allocated with 'new[]'; did you mean 'delete[]'?}}
>  }
>  }
> +
> +namespace MissingInitializer {
> +template<typename T>
> +struct Base {
> +  struct S {
> +    const T *p1 = nullptr;
> +    const T *p2 = new T[3];
> +  };
> +};
> +
> +void null_init(Base<double>::S s) {
> +  delete s.p1;
> +  delete s.p2;
> +}
> +}
> +
>  #ifndef WITH_PCH
>  pch_test::X::X()
>    : a(new int[1])  // expected-note{{allocated with 'new[]' here}}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list