Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Mar 2015 17:38:48 -0700
From:      Mark Millard <markmi@dsl-only.net>
To:        freebsd-toolchain@freebsd.org, FreeBSD PowerPC ML <freebsd-ppc@freebsd.org>
Subject:   contrib/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h's IntrusiveRefCntPtr and its use violates C++ privacy rules
Message-ID:  <8CFA382E-85D3-4A02-A448-3284C827DC29@dsl-only.net>

next in thread | raw e-mail | index | archive | help
When trying to build the 11.0-CURRENT clang 3.5 on powerpc64 I ran into =
a violation of C++ accessibility rules (for private) that stopped the =
compile.

contrib/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h has...

  template <typename T>
  class IntrusiveRefCntPtr {
    T* Obj;

  public:
  ...
    template <class X>
    IntrusiveRefCntPtr(IntrusiveRefCntPtr<X>&& S) : Obj(S.get()) {
      S.Obj =3D 0;
    }
  ...
  }

To first illustrate a (partial) but-simpler-to-follow example use that =
would show the problem:

using Ta =3D ...;
using Tb =3D ...;

// Note that private members of IntrusiveRefCntPtr<Ta>
// are not (should not be) accessible to
// IntrusiveRefCntPtr<Tb> methods (and vice-versa).

IntrusiveRefCntPtr<Ta> a{}

IntrusiveRefCntPtr<Tb> b{a};

// We then would have a usage where an example of:

IntrusiveRefCntPtr<Tb>::IntrusiveRefCntPtr

is then trying to access an example of

IntrusiveRefCntPtr<Ta>'s Obj private member.

It would take a friend relationship to be established to allow the =
cross-type access to Obj.


The code in =
contrib/llvm/tools/clang/lib/Frontend/ChainedIncludesSource.cpp has such =
a use and so makes an instance of the violation of the language rules in =
the actual code.

The function clang::createChainedIncludesSourceIt uses classes...=20

class ChainedIncludesSource : public ExternalSemaSource
where...
class ExternalSemaSource : public ExternalASTSource
where...
class ExternalASTSource : public RefCountedBase<ExternalASTSource>
where...
template <class Derived> class RefCountedBase;

and it uses both of the following types...

IntrusiveRefCntPtr<ExternalSemaSource>
and...
IntrusiveRefCntPtr<ChainedIncludesSource>

In fact IntrusiveRefCntPtr<ChainedIncludesSource> is the =
return-expresison type for the following routine that has return type =
IntrusiveRefCntPtr<ExternalSemaSource>...

IntrusiveRefCntPtr<ExternalSemaSource> =
clang::createChainedIncludesSource(
    CompilerInstance &CI, IntrusiveRefCntPtr<ExternalSemaSource> =
&Reader) {
...
  IntrusiveRefCntPtr<ChainedIncludesSource> source(new =
ChainedIncludesSource());
...
  return source;
}




=3D=3D=3D
Mark Millard
markmi at dsl-only.net




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8CFA382E-85D3-4A02-A448-3284C827DC29>