[PATCH] Support/Unix: use lambda function to fix building errors with clang

Mauro Rossi via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 25 04:22:04 PDT 2018


Hi Pavel,

Il giorno mar 17 lug 2018 alle ore 08:36 Mauro Rossi
<issor.oruam at gmail.com> ha scritto:
>
> Hi Pavel,
>
> Il giorno lun 16 lug 2018 alle ore 19:14 Pavel Labath <labath at google.com> ha scritto:
>>
>> I think all/most systems have open(2) defined as a variadic (...)
>> function, so that can't be the only reason why this is failing for
>> you. There must be something more which is specific to your platform.
>> Nevertheless, the workaround is not bad, so there's no harm in
>>
>> changing this. Some people would even prefer the lambda based syntax.
>
>
> We are using basically the same Build System/compilers of AOSP,
> it seam that just using clang can produce the error because of behavior different from gcc.
> In some comments in the web behaviors of gcc and clang were described as different.
>
> If you are also using clang, are you using the clang version with AOSP (8.1.0_r33 at the time of reporting)
> I propose to check in order to identify root cause, then evaluate how to proceed.
>
> Mauro

The building error is happening using default AOSP 8.1.0_r41 clang tool chain

If you don't see drawbacks, would it be possible to queue the patch
that solves the building problem
as candidate for llvm 7.0rc3?
This would prevent building issues for AOSP current and future Android releases

After your feedback, I am adding Hans Wennborg to evaluate if the
patch is an acceptable candidate for llvm 7.0rc3
Mauro

>
>
>>
>> On Sun, 8 Jul 2018 at 21:28, Mauro Rossi <issor.oruam at gmail.com> wrote:
>> >
>> > From: Chih-Wei Huang <cwhuang at linux.org.tw>
>> >
>> > The ::open() function has unlimited arguments. Seems the compiler can't
>> > infer the template argument from it:
>> >
>> > external/llvm70/lib/Support/Unix/Path.inc:770:19: error: no matching function for call to 'RetryAfterSignal'
>> >   if ((ResultFD = sys::RetryAfterSignal(-1, ::open, P.begin(), OpenFlags, Mode)) <
>> >                   ^~~~~~~~~~~~~~~~~~~~~
>> > external/llvm70/lib/Support/../../include/llvm/Support/Errno.h:34:13: note: candidate template ignored: couldn't infer template argument 'Fun'
>> > inline auto RetryAfterSignal(const FailT &Fail, const Fun &F,
>> >             ^
>> > 1 error generated.
>> >
>> > To avoid that, use a lambda function to wrap the ::open() function.
>> > ---
>> >  lib/Support/Unix/Path.inc    | 4 ++--
>> >  lib/Support/Unix/Process.inc | 2 +-
>> >  2 files changed, 3 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc
>> > index b8fea5bda4f..44a8b981c48 100644
>> > --- a/lib/Support/Unix/Path.inc
>> > +++ b/lib/Support/Unix/Path.inc
>> > @@ -766,8 +766,8 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
>> >
>> >    SmallString<128> Storage;
>> >    StringRef P = Name.toNullTerminatedStringRef(Storage);
>> > -  if ((ResultFD = sys::RetryAfterSignal(-1, ::open, P.begin(), OpenFlags, Mode)) <
>> > -      0)
>> > +  auto openfun([&] { return ::open(P.begin(), OpenFlags, Mode); });
>> > +  if ((ResultFD = sys::RetryAfterSignal(-1, openfun)) < 0)
>> >      return std::error_code(errno, std::generic_category());
>> >  #ifndef O_CLOEXEC
>> >    if (!(Flags & OF_ChildInherit)) {
>> > diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc
>> > index fa515d44f3f..1111cd2fe2c 100644
>> > --- a/lib/Support/Unix/Process.inc
>> > +++ b/lib/Support/Unix/Process.inc
>> > @@ -211,7 +211,7 @@ std::error_code Process::FixupStandardFileDescriptors() {
>> >      assert(errno == EBADF && "expected errno to have EBADF at this point!");
>> >
>> >      if (NullFD < 0) {
>> > -      if ((NullFD = RetryAfterSignal(-1, ::open, "/dev/null", O_RDWR)) < 0)
>> > +      if ((NullFD = RetryAfterSignal(-1, [] { return ::open("/dev/null", O_RDWR); })) < 0)
>> >          return std::error_code(errno, std::generic_category());
>> >      }
>> >
>> > --
>> > 2.17.1
>> >


More information about the llvm-commits mailing list