Re: [cfe-users] Need a GCC-free LLVM/Clang on Linux.

2020-02-19 Thread Richard Smith via cfe-users
On Thu, 23 Jan 2020 at 07:24, Christopher H Green via cfe-users <
cfe-users@lists.llvm.org> wrote:

> Hi,
>
> I've spent the last several days trying to build a fast, full-featured
> relocatable distribution of LLVM/Clang 9.0.1 on Linux RHEL7, which has an
> older native GCC (4.8.5)—I can't require the RH toolset. I have access to a
> modern version of GCC in order to make the stage-1 build, but I need the
> final product not only to be relocatable, but also to be free of any
> dependence on that GCC or its libraries. In other words, I want to be able
> to distribute an LLVM/CLang which defaults to compiling using libc++,
> libcxxabi, compiler-rt, libunwind, and ldd, and which itself depends
> neither on libstdc++ or  libgcc_s. I'd also like to be able to to provide
> LTO, but whether the compiler is itself the beneficiary of LTO is optional.
> As a final wish, I'd like the distribution as installed to serve as an SDK
> against which to build other components such as separately packaged lldb
> and f18. Oh, and I want a pony.
>
> Here's what I have so far (CMake cache files attached for stages 1 and 2).
> Invoked  in a separate build directory with:
>
> env CC=gcc-9 CXX=g++-9 \
> 'CXXFLAGS=-Wno-cast-function-type -Wno-deprecated-copy 
> -Wno-init-list-lifetime -Wno-pessimizing-move -Wno-redundant-move 
> -Wno-uninitialized -Wno-unused-function -Wno-unused-variable' \
> cmake -GNinja -C FNAL.cmake -DCMAKE_INSTALL_PREFIX= \
> -DBOOTSTRAP_LLVM_CXX_STD=c++17 
> ninja
> ninja install
>
> (The CXXFLAGS are just to keep the noise down during the stage-1 build).
>
> I appear (finally) to have a mostly functioning build *in situ*, but the
> installed compiler depends upon libstdc++ to be able to run, and I should
> have put --rtlib=compiler-rt in LINKER_FLAGS rather than CXX_FLAGS.
> Additionally, I haven't been able to come up with a good set of targets for
> LLVM_DISTRIBUTION_COMPONENTS, but when I do I think I need to exclude
> static libraries if I'm doing LTO, no?
>
> I suspect I need a three stage build—well, two stage 2s, at least—but any
> advice would be appreciated as I'm wandering around in the dark at this
> point.
>
I have a two-stage setup that builds a GCC-free Clang except for libgcc_s
(I've not looked at what's pulling that in yet, but I expect that's
resolvable).

My stage1 cmake setup has: -DCLANG_DEFAULT_CXX_STDLIB=libc++
-DCLANG_DEFAULT_RTLIB=compiler-rt
My stage2 cmake setup additionally has: -DLIBCXXABI_USE_LLVM_UNWINDER=ON
-DLIBCXXABI_USE_COMPILER_RT=ON -DLIBCXX_USE_COMPILER_RT=ON
(and points CMAKE_C_COMPILER and CMAKE_CXX_COMPILER at the stage1 clang).

There might be some other things you need, I'm not sure. But it should be
doable in two stages.

> Many thanks for any help,
>
> Chris.
>
>
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] How to check whether a type is_copy_assignable?

2020-02-19 Thread Richard Smith via cfe-users
On Thu, 6 Feb 2020 at 12:13, Weston Carvalho via cfe-users <
cfe-users@lists.llvm.org> wrote:

> HI,
>
> I'm trying to write a tool that uses the AST to look at all the class
> declarations in our codebase and get some metrics on our use of special
> member functions. (How many classes are copyable, how many have
> ctors without the corresponding assignment operator, etc.) I'm running into
> some problems with implicitly declared special members. For example:
>
> class UserDefCopy {
>  public:
>   UserDefCopy(const UserDefCopy&) {}
>   UserDefCopy& operator=(const UserDefCopy&) { return *this; }
> };
> class ContainsUserDefCopy {
>  private:
>   UserDefCopy x_;
> };
>
> UserDefCopy has a CXXConstructorDecl for its copy constructor and a
> CXXMethodDecl for the copy-assign operator, so I can use the methods on the
> decls to get the info I need (isDeleted, isExplicitlyDefaulted, getAccess,
> etc.) However, ContainsUserDefCopy's copy-assign operator is implicit, so
> there's no decl for it. Since there's no decl, I can't differentiate
> between a class with an implicitly defaulted copy-assign and one with an
> implicitly deleted copy-assign. ContainsUserDefCopy does have a
> declaration for its copy constructor, but AFAICT from looking at
> clang::Sema::AddImplicitlyDeclaredMembersToClass
> ,
> that's because special members with the needs_overload_resolution tag are
> eagerly generated while others are deferred. I don't understand why the
> ctor has the tag while the assign operator doesn't, though.
>
> The questions I have are:
>
>1. What makes a method needs_overload_resolution? The docs in
>CXXRecordDecl just say that it "[determines] whether we need to
>eagerly declare a defaulted [member] for this class."
>
> Once the class is completely defined, the definition data accessors on
CXXRecordDecl (eg, hasTrivialCopyConstructor) are required to return
accurate information about the class. The "needs overload resolution" flag
is set by CXXRecordDecl if it couldn't work those properties out by itself
and needs Sema to help. For example, if it's not trivially obvious what
constructor would be used to copy a subobject of a class (see
CXXRecordDecl::hasSimpleCopyConstructor), CXXRecordDecl sets the "need
overload resolution" flag so that Sema can properly work out whether that
class's copy constructor is trivial.

This flag is just an implementation detail, and doesn't have any
interesting meaning outside of the implementation of CXXRecordDecl and Sema.

>
>1. Is there a different way I should query the AST so that I see any
>decls that were deferred during the Sema step? Or some other way to get
>this information? Trying to use an implicitly deleted copy assignment
>operator is a compiler error, so that information is obviously available
>*somewhere*.
>
> It depends on what question you want the answer to. I'd guess (based on
the subject of your email) that you want the same answer that
is_copy_assignable would give, which means you want to know whether a
certain assignment expression would be valid (and note that the assignment
expression might be implemented by something other than a copy-assignment
operator in general, C++ being what it is). Probably the easiest way to
query that would be to call Sema::BuildTypeTrait and call
TypeTraitExpr::getValue() on the result.

You should be aware that making this query may have side-effects (in
particular, it may trigger template instantiations and result in errors
outside of the immediate context). But that's fundamental to the question
you're asking, I'm afraid.
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users